Skip to content

Commit 3f8d110

Browse files
hootlexAkryum
authored andcommitted
test: Component data edit bugfix and tests (vuejs#729)
* tests for data edit * add test for parsing JSON input * add test for renaming object's property * fix bug when renaming object's property
1 parent fa185d8 commit 3f8d110

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { suite } from '../utils/suite'
2+
3+
suite('component data edit', () => {
4+
it('should edit data using the decrease button', () => {
5+
// select Instance
6+
cy.get('.instance:nth-child(1) .instance:nth-child(2)').eq(0).click()
7+
cy.get('.data-field').eq(7).find('.actions .vue-ui-button').eq(1).click({force: true}).click({force: true})
8+
cy.get('.data-field').eq(7).should('contain', '-1')
9+
10+
// expect DOM element to be updated
11+
cy.get('#target').iframe().then(({ get }) => {
12+
get('#target div').eq(0).contains('-1')
13+
})
14+
})
15+
16+
it('should edit data using the increase button', () => {
17+
cy.get('.instance:nth-child(1) .instance:nth-child(2)').eq(0).click()
18+
cy.get('.data-field').eq(7).find('.actions .vue-ui-button').eq(2).click({force: true})
19+
cy.get('.data-field').eq(7).should('contain', '0')
20+
21+
// expect DOM element to be updated
22+
cy.get('#target').iframe().then(({ get }) => {
23+
get('#target div').eq(0).contains('0')
24+
})
25+
})
26+
27+
it('should edit data using the edit input', () => {
28+
cy.get('.instance:nth-child(1) .instance:nth-child(2)').eq(0).click()
29+
cy.get('.data-field').eq(7).find('.actions .vue-ui-button').eq(0).click({force: true})
30+
31+
cy.get('.edit-input').type('12')
32+
cy.get('.edit-overlay > .actions > :nth-child(2) > .content > .vue-ui-icon').click()
33+
34+
cy.get('.data-field').eq(7).should('contain', '12')
35+
36+
// expect DOM element to be updated
37+
cy.get('#target').iframe().then(({ get }) => {
38+
get('#target div').eq(0).contains('12')
39+
})
40+
})
41+
42+
it('should add elements to array', () => {
43+
cy.get('.instance:nth-child(1) .instance:nth-child(2)').eq(0).click()
44+
cy.get('.data-field').eq(6).find('.actions .vue-ui-button').eq(1).click({force: true})
45+
46+
cy.get('.edit-input').type('55')
47+
cy.get('.edit-overlay > .actions > :nth-child(2) > .content > .vue-ui-icon').click()
48+
49+
cy.get('.data-field').eq(6).find('.children .data-field').should('have.length', '3')
50+
cy.get('.data-field').eq(6).find('.children .data-field').eq(2).should('contain', 55)
51+
52+
// expect DOM element to be updated
53+
cy.get('#target').iframe().then(({ get }) => {
54+
get('#target div').eq(4).contains('55')
55+
})
56+
})
57+
58+
it('should remove elements from array', () => {
59+
cy.get('.instance:nth-child(1) .instance:nth-child(2)').eq(0).click()
60+
cy.get('.data-field').eq(9).find('.actions .vue-ui-button').eq(3).click({force: true})
61+
62+
cy.get('.data-field').eq(6).find('.children .data-field').should('have.length', '2')
63+
})
64+
65+
it('should parse object through edit input', () => {
66+
cy.get('.instance:nth-child(1) .instance:nth-child(2)').eq(0).click()
67+
cy.get('.data-field').eq(7).find('.actions .vue-ui-button').eq(0).click({force: true})
68+
69+
cy.get('.edit-input').type('{{}"count":42}')
70+
cy.get('.edit-overlay > .actions > :nth-child(2) > .content > .vue-ui-icon').click()
71+
72+
cy.get('.data-field').eq(7).should('contain', 'Object')
73+
// expand object
74+
cy.get('.data-field').eq(7).click()
75+
cy.get('.data-field').eq(8).find('.key').should('contain', 'count')
76+
cy.get('.data-field').eq(8).find('.value').should('contain', 42)
77+
})
78+
79+
it('should rename object\'s property', () => {
80+
cy.get('.instance:nth-child(1) .instance:nth-child(2)').eq(0).click()
81+
cy.get('.data-field').eq(8).find('.actions .vue-ui-button').eq(0).click({force: true})
82+
cy.get('.edit-input.key-input').clear().type('name')
83+
cy.get('.edit-overlay > .actions > :nth-child(2) > .content > .vue-ui-icon').click()
84+
85+
cy.get('.data-field').eq(8).find('.key').should('contain', 'name')
86+
})
87+
})

src/devtools/mixins/data-field-edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default {
8989
},
9090

9191
duplicateKey () {
92-
return this.parentField.value.hasOwnProperty(this.editedKey)
92+
return this.parentField && this.parentField.value.hasOwnProperty(this.editedKey)
9393
},
9494

9595
keyValid () {

0 commit comments

Comments
 (0)