Skip to content

Commit

Permalink
console: Include e2e tests for unclaiming gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelJankoski committed Oct 24, 2024
1 parent 94f4007 commit cd1e2bc
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 10 deletions.
103 changes: 103 additions & 0 deletions cypress/e2e/console/gateways/managed/delete.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright © 2024 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

describe('Delete Managed Gateway', () => {
const userId = 'managed-gateway-test-user'
const user = {
ids: { user_id: userId },
primary_email_address: '[email protected]',
password: 'ABCDefg123!',
password_confirm: 'ABCDefg123!',
}

const gatewayId = 'test-managed-gateway'
const gateway = { ids: { gateway_id: gatewayId } }

const gatewayVersionIds = {
hardware_version: 'v1.1',
firmware_version: 'v1.1',
model_id: 'Managed gateway',
}

beforeEach(() => {
cy.dropAndSeedDatabase()
cy.createUser(user)
cy.createGateway(gateway, userId)

cy.intercept('GET', `/api/v3/gcs/gateways/managed/${gatewayId}*`, {
statusCode: 200,
body: {
ids: {
gateway_id: `eui-${gateway.eui}`,
eui: gateway.eui,
},
version_ids: gatewayVersionIds,
},
}).as('get-is-gtw-managed')

cy.intercept('POST', `/api/v3/gcls/claim/info`, {
statusCode: 200,
body: {
supports_claiming: true,
},
}).as('get-is-gtw-claimable')

cy.intercept('DELETE', `/api/v3/gcls/claim/${gatewayId}`, {
statusCode: 200,
}).as('unclaim-gtw')

cy.loginConsole({ user_id: user.ids.user_id, password: user.password })
cy.visit(`${Cypress.config('consoleRootPath')}/gateways/${gatewayId}`)
cy.wait('@get-is-gtw-managed')
cy.findByRole('heading', { name: 'test-managed-gateway' })
cy.get('button').contains('Managed gateway').should('be.visible')
})

it('succeeds to trigger unclaiming when deleting the gateway from the overview header', () => {
cy.findByTestId('gateway-overview-menu').should('be.visible').click()
cy.findByText('Unclaim and delete gateway').should('be.visible').click()
cy.findByTestId('modal-window')
.should('be.visible')
.within(() => {
cy.findByText('Confirm deletion', { selector: 'h1' }).should('be.visible')
cy.findByRole('button', { name: 'Unclaim and delete gateway' }).click()
})
cy.wait('@unclaim-gtw')
cy.findByTestId('error-notification').should('not.exist')
cy.findByTestId('toast-notification-success')
.should('be.visible')
.and('contain', 'Gateway deleted')
})

it('succeeds to trigger unclaiming when deleting the gateway from the general settings', () => {
cy.get('a').contains('General settings').click()
cy.location('pathname').should(
'eq',
`${Cypress.config('consoleRootPath')}/gateways/${gatewayId}/general-settings`,
)
cy.findByText('Basic settings').should('be.visible')
cy.findByRole('button', { name: 'Unclaim and delete gateway' }).click()
cy.findByTestId('modal-window')
.should('be.visible')
.within(() => {
cy.findByText('Confirm deletion', { selector: 'h1' }).should('be.visible')
cy.findByRole('button', { name: 'Unclaim and delete gateway' }).click()
})
cy.wait('@unclaim-gtw')
cy.findByTestId('error-notification').should('not.exist')
cy.findByTestId('toast-notification-success')
.should('be.visible')
.and('contain', 'Gateway deleted')
})
})
13 changes: 8 additions & 5 deletions pkg/webui/console/containers/delete-entity-header-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ const path = {
[GATEWAY]: '/gateways',
}

const deleteMessageMap = {
[APPLICATION]: sharedMessages.deleteApp,
[GATEWAY]: sharedMessages.deleteGateway,
}

const deletedMessageMap = {
[APPLICATION]: sharedMessages.deleteSuccess,
[GATEWAY]: sharedMessages.gatewayDeleted,
Expand Down Expand Up @@ -113,6 +108,14 @@ const DeleteEntityHeaderModal = props => {
const dispatch = useDispatch()
const navigate = useNavigate()

const deleteMessageMap = {
[APPLICATION]: sharedMessages.deleteApp,
[GATEWAY]:
supportsClaiming && isGateway
? sharedMessages.unclaimAndDeleteGateway
: sharedMessages.deleteGateway,
}

const mayPurgeEntity = useSelector(state => checkFromState(mayPurgeEntities, state))
const mayDeleteEntity = useSelector(state =>
checkFromState(mayDeleteEntitySelectorMap[entity], state),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ const GatewayOverviewHeader = ({ gateway }) => {
<Dropdown.Item title={sharedMessages.downloadGlobalConf} action={handleGlobalConfDownload} />
{/* <Dropdown.Item title={m.duplicateGateway} action={() => {}} />*/}
{mayDeleteGtw && (
<Dropdown.Item title={sharedMessages.deleteGateway} action={handleOpenDeleteGatewayModal} />
<Dropdown.Item
title={
supportsClaiming ? sharedMessages.unclaimAndDeleteGateway : sharedMessages.deleteGateway
}
action={handleOpenDeleteGatewayModal}
/>
)}
</>
)
Expand Down Expand Up @@ -158,6 +163,7 @@ const GatewayOverviewHeader = ({ gateway }) => {
noDropdownIcon
dropdownItems={menuDropdownItems}
dropdownPosition="below left"
data-test-id="gateway-overview-menu"
/>
</div>
<DeleteEntityHeaderModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ const BasicSettingsForm = React.memo(props => {
<Require condition={mayDeleteGtw}>
<Button
onClick={handleOpenDeleteGatewayModal}
message={supportsClaiming ? m.unclaimAndDeleteGateway : sharedMessages.deleteGateway}
message={
supportsClaiming
? sharedMessages.unclaimAndDeleteGateway
: sharedMessages.deleteGateway
}
type="button"
icon={IconTrash}
naked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const messages = defineMessages({
'Technical contact information for this gateway. Typically used to indicate who to contact with technical/security questions about the gateway.',
deleteGatewayDefaultMessage:
'This will <strong>PERMANENTLY DELETE THE ENTITY ITSELF AND ALL ASSOCIATED ENTITIES</strong>, including collaborator associations. It will also <strong>NOT BE POSSIBLE TO REUSE THE ENTITY ID</strong> until purged by an admin but the EUI can be reregistered later with a different ID.',
unclaimAndDeleteGateway: 'Unclaim and delete gateway',
})

export default messages
1 change: 1 addition & 0 deletions pkg/webui/lib/shared-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export default defineMessages({
'Delay too short. The lower bound ({minimumValue}ms) will be used by the Gateway Server.',
deleteGateway: 'Delete gateway',
unclaimAndDeleteDevice: 'Unclaim and delete end device',
unclaimAndDeleteGateway: 'Unclaim and delete gateway',
deleteDevice: 'Delete end device',
deleteApp: 'Delete application',
deleteSuccess: 'Application deleted',
Expand Down
2 changes: 1 addition & 1 deletion pkg/webui/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,6 @@
"console.views.gateway-general-settings.messages.adminContactDescription": "Administrative contact information for this gateway. Typically used to indicate who to contact with administrative questions about the gateway.",
"console.views.gateway-general-settings.messages.techContactDescription": "Technical contact information for this gateway. Typically used to indicate who to contact with technical/security questions about the gateway.",
"console.views.gateway-general-settings.messages.deleteGatewayDefaultMessage": "This will <strong>PERMANENTLY DELETE THE ENTITY ITSELF AND ALL ASSOCIATED ENTITIES</strong>, including collaborator associations. It will also <strong>NOT BE POSSIBLE TO REUSE THE ENTITY ID</strong> until purged by an admin but the EUI can be reregistered later with a different ID.",
"console.views.gateway-general-settings.messages.unclaimAndDeleteGateway": "Unclaim and delete gateway",
"console.views.organization-add.index.orgDescription": "Organizations are used to group multiple users and assigning collective rights for them. An organization can then be set as collaborator of applications or gateways. This makes it easy to grant or revoke rights to entities for a group of users.{break} Learn more in our guide on <Link>Organization Management</Link>.",
"console.views.user-settings-oauth-auth-settings.index.deleteButton": "Revoke authorization",
"console.views.user-settings-oauth-auth-settings.index.deleteSuccess": "This authorization was successfully revoked",
Expand Down Expand Up @@ -1312,6 +1311,7 @@
"lib.shared-messages.delayWarning": "Delay too short. The lower bound ({minimumValue}ms) will be used by the Gateway Server.",
"lib.shared-messages.deleteGateway": "Delete gateway",
"lib.shared-messages.unclaimAndDeleteDevice": "Unclaim and delete end device",
"lib.shared-messages.unclaimAndDeleteGateway": "Unclaim and delete gateway",
"lib.shared-messages.deleteDevice": "Delete end device",
"lib.shared-messages.deleteApp": "Delete application",
"lib.shared-messages.deleteSuccess": "Application deleted",
Expand Down
2 changes: 1 addition & 1 deletion pkg/webui/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,6 @@
"console.views.gateway-general-settings.messages.adminContactDescription": "",
"console.views.gateway-general-settings.messages.techContactDescription": "",
"console.views.gateway-general-settings.messages.deleteGatewayDefaultMessage": "",
"console.views.gateway-general-settings.messages.unclaimAndDeleteGateway": "",
"console.views.organization-add.index.orgDescription": "",
"console.views.user-settings-oauth-auth-settings.index.deleteButton": "",
"console.views.user-settings-oauth-auth-settings.index.deleteSuccess": "",
Expand Down Expand Up @@ -1312,6 +1311,7 @@
"lib.shared-messages.delayWarning": "遅延が短すぎます。ゲートウェイサーバーは下限値 ({minimumValue}ms) を使用します",
"lib.shared-messages.deleteGateway": "",
"lib.shared-messages.unclaimAndDeleteDevice": "",
"lib.shared-messages.unclaimAndDeleteGateway": "",
"lib.shared-messages.deleteDevice": "",
"lib.shared-messages.deleteApp": "",
"lib.shared-messages.deleteSuccess": "",
Expand Down

0 comments on commit cd1e2bc

Please sign in to comment.