Skip to content

Commit eceeced

Browse files
authored
Allow user to edit a device type on an existing endpoint as a new endpoint config and not an overwrite on existing endpoint config (#1541)
- Currently when a user edits the device type on an endpoint configuration then the configuration is overwritten on top of the existing endpoint configuration. - However the above can lead to non-compliant device type as per the protocol specification if the users are not careful. - With this change a dialogue pops up when the user changes the device type to either edit on top of existing endpoint config or add as a new endpoint config. - Added cypress tests to cover the same - Add changes to to UI by removing v-close-up and add persist so that the UI pop ups don't vanish when clicking outside the popups - Github: ZAP#1125
1 parent dbef348 commit eceeced

File tree

3 files changed

+131
-16
lines changed

3 files changed

+131
-16
lines changed

cypress/e2e/endpoints/edit-endpoint.cy.js

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Cypress.on('uncaught:exception', (err, runnable) => {
66
})
77

88
describe('Testing Editing endpoints', () => {
9-
it('create a new endpoint', () => {
9+
beforeEach(() => {
10+
// Set up the base URL and create an endpoint before each test
1011
cy.fixture('baseurl').then((data) => {
1112
cy.visit(data.baseurl)
1213
})
@@ -15,26 +16,59 @@ describe('Testing Editing endpoints', () => {
1516
cy.addEndpoint(data.endpoint1)
1617
})
1718
})
18-
it('edit endpoint', { retries: { runMode: 2, openMode: 2 } }, () => {
19-
cy.get('[data-test="edit-endpoint"]').last().click()
2019

20+
it('create a new endpoint', () => {
21+
// Verify the endpoint was created successfully
2122
cy.fixture('data').then((data) => {
22-
cy.get('[data-test="select-endpoint-input"]')
23-
.click()
24-
.type(data.endpoint2.substring(0, 5), { force: true })
25-
cy.wait(500)
26-
cy.get('div').contains(data.endpoint2).click({ force: true })
23+
cy.get('aside').children().should('contain', data.endpoint1)
2724
})
28-
cy.get('[data-test="endpoint-title"]').click() // it makes sure that the previous input field has been unselected
29-
cy.get('button').contains('Save').click()
3025
})
3126
it(
32-
'Check if edit is successfull',
27+
'edit endpoint -> Overwrite',
3328
{ retries: { runMode: 2, openMode: 2 } },
3429
() => {
30+
cy.get('[data-test="edit-endpoint"]').last().click()
31+
32+
cy.fixture('data').then((data) => {
33+
cy.get('[data-test="select-endpoint-input"]')
34+
.click()
35+
.type(data.endpoint2.substring(0, 5), { force: true })
36+
cy.wait(500)
37+
cy.get('div').contains(data.endpoint2).click({ force: true })
38+
})
39+
cy.get('[data-test="endpoint-title"]').click() // it makes sure that the previous input field has been unselected
40+
cy.get('button').contains('Save').click()
41+
cy.wait(500)
42+
// Test overwrite option
43+
cy.get('button').contains('Overwrite').click()
44+
// Verify the endpoint was updated successfully
3545
cy.fixture('data').then((data) => {
3646
cy.get('aside').children().should('contain', data.endpoint2)
3747
})
3848
}
3949
)
50+
it(
51+
'edit endpoint -> delete and add',
52+
{ retries: { runMode: 2, openMode: 2 } },
53+
() => {
54+
cy.get('[data-test="edit-endpoint"]').last().click()
55+
56+
cy.fixture('data').then((data) => {
57+
cy.get('[data-test="select-endpoint-input"]')
58+
.click()
59+
.type(data.endpoint3.substring(0, 5), { force: true })
60+
cy.wait(500)
61+
cy.get('div').contains(data.endpoint3).click({ force: true })
62+
})
63+
cy.get('[data-test="endpoint-title"]').click() // it makes sure that the previous input field has been unselected
64+
cy.get('button').contains('Save').click()
65+
cy.wait(500)
66+
// Test delete and add option
67+
cy.get('button').contains('Delete and Add').click()
68+
// Verify the endpoint was updated successfully
69+
cy.fixture('data').then((data) => {
70+
cy.get('aside').children().should('contain', data.endpoint3)
71+
})
72+
}
73+
)
4074
})

src/components/ZclCreateModifyEndpoint.vue

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,43 @@ limitations under the License.
262262
/>
263263
</q-card-actions>
264264
</q-card>
265+
266+
<!-- Device Type Change Dialog -->
267+
<q-dialog v-model="showDeviceTypeChangeDialog" persistent>
268+
<q-card>
269+
<q-card-section>
270+
<div class="text-h6">Device Type Changed</div>
271+
<p>
272+
The device type configuration for this endpoint has changed. Would
273+
you like to apply the changes on top of the existing configuration,
274+
which may result in a noncompliant device type (Overwrite), or
275+
delete the existing endpoint and create a new one?
276+
</p>
277+
</q-card-section>
278+
<q-card-actions align="right">
279+
<q-btn
280+
flat
281+
label="Cancel"
282+
color="primary"
283+
@click="cancelDeviceTypeChange"
284+
/>
285+
<q-btn
286+
flat
287+
label="Overwrite"
288+
color="primary"
289+
@click="overwriteDeviceType"
290+
data-test="overwrite"
291+
/>
292+
<q-btn
293+
flat
294+
label="Delete and Add"
295+
color="primary"
296+
@click="deleteAndAddDeviceType"
297+
data-test="delete-and-add"
298+
/>
299+
</q-card-actions>
300+
</q-card>
301+
</q-dialog>
265302
</div>
266303
</template>
267304

@@ -341,7 +378,8 @@ export default {
341378
deviceTypeTmp: [], // Temp store for the selected device types
342379
primaryDeviceTypeTmp: null, // Temp store for the selected primary device type
343380
endpointIds: [],
344-
tmpSelectedOptions: []
381+
tmpSelectedOptions: [],
382+
showDeviceTypeChangeDialog: false // Controls the visibility of the dialog
345383
}
346384
},
347385
computed: {
@@ -588,15 +626,58 @@ export default {
588626
!this.$refs.version?.includes((v) => !(v >= 0))) &&
589627
profile
590628
) {
591-
this.$emit('saveOrCreateValidated')
592629
if (this.endpointReference) {
593-
this.editEpt(this.shownEndpoint, this.endpointReference)
594-
this.$emit('updateData')
630+
// Check if the device type has changed
631+
const currentDeviceType = this.deviceTypeTmp.map(
632+
(dt) => dt.deviceTypeRef
633+
)
634+
const previousDeviceType =
635+
this.endpointDeviceTypeRef[
636+
this.endpointType[this.endpointReference]
637+
]
638+
639+
if (currentDeviceType.toString() !== previousDeviceType.toString()) {
640+
// Show the dialog
641+
this.showDeviceTypeChangeDialog = true
642+
} else {
643+
// No change in device type, proceed with editing
644+
this.editEpt(this.shownEndpoint, this.endpointReference)
645+
this.$emit('updateData')
646+
this.$emit('saveOrCreateValidated')
647+
}
595648
} else {
649+
// Create new endpoint
596650
this.newEpt()
597651
}
598652
}
599653
},
654+
cancelDeviceTypeChange() {
655+
this.showDeviceTypeChangeDialog = false
656+
},
657+
overwriteDeviceType() {
658+
this.showDeviceTypeChangeDialog = false
659+
this.editEpt(this.shownEndpoint, this.endpointReference)
660+
this.$emit('updateData')
661+
this.$emit('saveOrCreateValidated') // Toggle the edit endpoint UI
662+
},
663+
deleteAndAddDeviceType() {
664+
this.showDeviceTypeChangeDialog = false
665+
this.deleteEpt(this.endpointReference)
666+
this.newEpt()
667+
},
668+
deleteEpt(endpointReference) {
669+
// Logic to delete the existing endpoint
670+
this.$store
671+
.dispatch('zap/deleteEndpoint', endpointReference)
672+
.then(() => {
673+
console.log(`Endpoint ${endpointReference} deleted successfully.`)
674+
})
675+
.catch((err) => {
676+
console.error(
677+
`Error deleting endpoint ${endpointReference}: ${err.message}`
678+
)
679+
})
680+
},
600681
reqValue(value) {
601682
return !_.isEmpty(value) || '* Required'
602683
},

src/components/ZclEndpointCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ limitations under the License.
4545
dense
4646
icon="o_edit"
4747
size="sm"
48-
v-close-popup
4948
@click="modifyEndpointDialog = !modifyEndpointDialog"
5049
data-test="edit-endpoint"
5150
>
@@ -202,6 +201,7 @@ limitations under the License.
202201
<q-dialog
203202
v-model="modifyEndpointDialog"
204203
class="background-color:transparent"
204+
persistent
205205
>
206206
<zcl-create-modify-endpoint
207207
v-bind:endpointReference="endpointReference"

0 commit comments

Comments
 (0)