From 48dd9b8fbf2292bbe380dbb4a7649bc59e75e188 Mon Sep 17 00:00:00 2001 From: Nicolas Van Labeke Date: Sat, 4 Jan 2025 23:49:20 +0000 Subject: [PATCH] test(29159): add tests --- .../adapters/AdapterActionMenu.spec.cy.tsx | 125 ++++++++++++++++-- .../components/adapters/AdapterActionMenu.tsx | 18 +-- 2 files changed, 124 insertions(+), 19 deletions(-) diff --git a/hivemq-edge/src/frontend/src/modules/ProtocolAdapters/components/adapters/AdapterActionMenu.spec.cy.tsx b/hivemq-edge/src/frontend/src/modules/ProtocolAdapters/components/adapters/AdapterActionMenu.spec.cy.tsx index f12cc56925..8e9dd38bd2 100644 --- a/hivemq-edge/src/frontend/src/modules/ProtocolAdapters/components/adapters/AdapterActionMenu.spec.cy.tsx +++ b/hivemq-edge/src/frontend/src/modules/ProtocolAdapters/components/adapters/AdapterActionMenu.spec.cy.tsx @@ -1,12 +1,13 @@ /// -import { mockAdapter } from '@/api/hooks/useProtocolAdapters/__handlers__' +import { mockAdapter, mockProtocolAdapter } from '@/api/hooks/useProtocolAdapters/__handlers__' import { Adapter, Status } from '@/api/__generated__' import AdapterActionMenu from '@/modules/ProtocolAdapters/components/adapters/AdapterActionMenu.tsx' +import { WorkspaceAdapterCommand } from '@/modules/ProtocolAdapters/types.ts' describe('AdapterActionMenu', () => { beforeEach(() => { - cy.viewport(350, 400) + cy.viewport(350, 600) }) it('should render properly', () => { @@ -48,7 +49,6 @@ describe('AdapterActionMenu', () => { const onEdit = cy.stub().as('onEdit') const onCreate = cy.stub().as('onCreate') const onDelete = cy.stub().as('onDelete') - const onViewWorkspace = cy.stub().as('onViewWorkspace') const onExport = cy.stub().as('onExport') cy.mountWithProviders( @@ -57,7 +57,6 @@ describe('AdapterActionMenu', () => { onEdit={onEdit} onCreate={onCreate} onDelete={onDelete} - onViewWorkspace={onViewWorkspace} onExport={onExport} /> ) @@ -80,12 +79,6 @@ describe('AdapterActionMenu', () => { cy.get('@onDelete').should('have.been.calledWith', 'my-adapter') cy.getByTestId('adapter-action-delete').should('not.be.visible') - cy.get('@onViewWorkspace').should('not.have.been.called') - cy.getByAriaLabel('Actions').click() - cy.getByTestId('adapter-action-workspace').click() - cy.get('@onViewWorkspace').should('have.been.calledWith', 'my-adapter', 'simulation') - cy.getByTestId('adapter-action-workspace').should('not.be.visible') - cy.get('@onExport').should('not.have.been.called') cy.getByAriaLabel('Actions').click() cy.getByTestId('adapter-action-export').click() @@ -104,4 +97,116 @@ describe('AdapterActionMenu', () => { }) cy.percySnapshot('Component: AdapterActionMenu') }) + + describe('Workspace group', () => { + it('should render workspace commands', () => { + cy.mountWithProviders() + cy.getByAriaLabel('Actions').click() + + cy.get('[role="group"] p').should('have.text', 'Manage from Workspace') + cy.getByTestId('adapter-action-tags').should('be.visible').should('have.text', 'Device tags') + cy.getByTestId('adapter-action-filters').should('be.visible').should('have.text', 'Topic filters') + cy.getByTestId('adapter-action-mappings-northbound') + .should('be.visible') + .should('have.text', 'Northbound mappings') + cy.getByTestId('adapter-action-mappings-southbound').should('not.exist') + cy.getByTestId('adapter-action-filters').should('be.visible').should('have.text', 'Topic filters') + }) + + it('should render southbound command', () => { + cy.mountWithProviders( + + ) + cy.getByAriaLabel('Actions').click() + + cy.get('[role="group"] p').should('have.text', 'Manage from Workspace') + cy.getByTestId('adapter-action-tags').should('be.visible').should('have.text', 'Device tags') + cy.getByTestId('adapter-action-filters').should('be.visible').should('have.text', 'Topic filters') + cy.getByTestId('adapter-action-mappings-northbound') + .should('be.visible') + .should('have.text', 'Northbound mappings') + cy.getByTestId('adapter-action-mappings-southbound') + .should('be.visible') + .should('have.text', 'Southbound mappings') + }) + + it('should trigger actions', () => { + const onViewWorkspace = cy.stub().as('onViewWorkspace') + + cy.mountWithProviders( + + ) + + cy.get('@onViewWorkspace').should( + 'not.have.been.calledWith', + 'my-adapter', + 'simulation', + WorkspaceAdapterCommand.VIEW + ) + cy.getByAriaLabel('Actions').click() + cy.getByTestId('adapter-action-workspace').click() + cy.get('@onViewWorkspace').should( + 'have.been.calledWith', + 'my-adapter', + 'simulation', + WorkspaceAdapterCommand.VIEW + ) + cy.getByTestId('adapter-action-workspace').should('not.be.visible') + + cy.get('@onViewWorkspace').should( + 'not.have.been.calledWith', + 'my-adapter', + 'simulation', + WorkspaceAdapterCommand.TAGS + ) + cy.getByAriaLabel('Actions').click() + cy.getByTestId('adapter-action-tags').click() + cy.get('@onViewWorkspace').should( + 'have.been.calledWith', + 'my-adapter', + 'simulation', + WorkspaceAdapterCommand.TAGS + ) + cy.getByTestId('adapter-action-workspace').should('not.be.visible') + + cy.get('@onViewWorkspace').should( + 'not.have.been.calledWith', + 'my-adapter', + 'simulation', + WorkspaceAdapterCommand.TOPIC_FILTERS + ) + cy.getByAriaLabel('Actions').click() + cy.getByTestId('adapter-action-filters').click() + cy.get('@onViewWorkspace').should( + 'have.been.calledWith', + 'my-adapter', + 'simulation', + WorkspaceAdapterCommand.TOPIC_FILTERS + ) + cy.getByTestId('adapter-action-workspace').should('not.be.visible') + + cy.get('@onViewWorkspace').should( + 'not.have.been.calledWith', + 'my-adapter', + 'simulation', + WorkspaceAdapterCommand.MAPPINGS + ) + cy.getByAriaLabel('Actions').click() + cy.getByTestId('adapter-action-mappings-northbound').click() + cy.get('@onViewWorkspace').should( + 'have.been.calledWith', + 'my-adapter', + 'simulation', + WorkspaceAdapterCommand.MAPPINGS + ) + cy.getByTestId('adapter-action-workspace').should('not.be.visible') + }) + }) }) diff --git a/hivemq-edge/src/frontend/src/modules/ProtocolAdapters/components/adapters/AdapterActionMenu.tsx b/hivemq-edge/src/frontend/src/modules/ProtocolAdapters/components/adapters/AdapterActionMenu.tsx index d6ea819b75..071cea5f4b 100644 --- a/hivemq-edge/src/frontend/src/modules/ProtocolAdapters/components/adapters/AdapterActionMenu.tsx +++ b/hivemq-edge/src/frontend/src/modules/ProtocolAdapters/components/adapters/AdapterActionMenu.tsx @@ -65,7 +65,7 @@ const AdapterActionMenu: FC = ({ {capabilities?.includes('READ') && ( onViewWorkspace?.(id, type as string, WorkspaceAdapterCommand.MAPPINGS)} icon={} > @@ -74,21 +74,21 @@ const AdapterActionMenu: FC = ({ )} {capabilities?.includes('WRITE') && ( onViewWorkspace?.(id, type as string, WorkspaceAdapterCommand.MAPPINGS)} icon={} > {t('protocolAdapter.table.actions.workspace.mappings.south')} )} + onViewWorkspace?.(id, type as string, WorkspaceAdapterCommand.VIEW)} + icon={} + > + {t('protocolAdapter.table.actions.workspace.view')} + - onViewWorkspace?.(id, type as string, WorkspaceAdapterCommand.VIEW)} - icon={} - > - {t('protocolAdapter.table.actions.workspace.view')} - onExport?.(id, type as string)}> {t('protocolAdapter.table.actions.export')}