Skip to content

Commit

Permalink
test(29159): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vanch3d committed Jan 6, 2025
1 parent 3d3058e commit 48dd9b8
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/// <reference types="cypress" />

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', () => {
Expand Down Expand Up @@ -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(
Expand All @@ -57,7 +57,6 @@ describe('AdapterActionMenu', () => {
onEdit={onEdit}
onCreate={onCreate}
onDelete={onDelete}
onViewWorkspace={onViewWorkspace}
onExport={onExport}
/>
)
Expand All @@ -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()
Expand All @@ -104,4 +97,116 @@ describe('AdapterActionMenu', () => {
})
cy.percySnapshot('Component: AdapterActionMenu')
})

describe('Workspace group', () => {
it('should render workspace commands', () => {
cy.mountWithProviders(<AdapterActionMenu adapter={mockAdapter} protocol={mockProtocolAdapter} />)
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(
<AdapterActionMenu
adapter={mockAdapter}
protocol={{ ...mockProtocolAdapter, capabilities: ['READ', 'WRITE'] }}
/>
)
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(
<AdapterActionMenu
adapter={mockAdapter}
onViewWorkspace={onViewWorkspace}
protocol={{ ...mockProtocolAdapter, capabilities: ['READ', 'WRITE'] }}
/>
)

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')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const AdapterActionMenu: FC<AdapterActionMenuProps> = ({
</MenuItem>
{capabilities?.includes('READ') && (
<MenuItem
data-testid="adapter-action-mappings"
data-testid="adapter-action-mappings-northbound"
onClick={() => onViewWorkspace?.(id, type as string, WorkspaceAdapterCommand.MAPPINGS)}
icon={<Icon as={deviceCapabilityIcon['READ']} />}
>
Expand All @@ -74,21 +74,21 @@ const AdapterActionMenu: FC<AdapterActionMenuProps> = ({
)}
{capabilities?.includes('WRITE') && (
<MenuItem
data-testid="adapter-action-mappings"
data-testid="adapter-action-mappings-southbound"
onClick={() => onViewWorkspace?.(id, type as string, WorkspaceAdapterCommand.MAPPINGS)}
icon={<Icon as={deviceCapabilityIcon['WRITE']} />}
>
{t('protocolAdapter.table.actions.workspace.mappings.south')}
</MenuItem>
)}
<MenuItem
data-testid="adapter-action-workspace"
onClick={() => onViewWorkspace?.(id, type as string, WorkspaceAdapterCommand.VIEW)}
icon={<WorkspaceIcon />}
>
{t('protocolAdapter.table.actions.workspace.view')}
</MenuItem>
</MenuGroup>
<MenuItem
data-testid="adapter-action-workspace"
onClick={() => onViewWorkspace?.(id, type as string, WorkspaceAdapterCommand.VIEW)}
icon={<WorkspaceIcon />}
>
{t('protocolAdapter.table.actions.workspace.view')}
</MenuItem>
<MenuDivider />
<MenuItem data-testid="adapter-action-export" onClick={() => onExport?.(id, type as string)}>
{t('protocolAdapter.table.actions.export')}
Expand Down

0 comments on commit 48dd9b8

Please sign in to comment.