Skip to content

Commit

Permalink
chore: add test for disabling buttons on small screen
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikThePendric committed Dec 10, 2024
1 parent 8b99f54 commit d501076
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/pages/view/FilterBar/__tests__/FilterBadge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import { render } from '@testing-library/react'
import React from 'react'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import { useWindowDimensions } from '../../../../components/WindowDimensionsProvider.js'
import FilterBadge from '../FilterBadge.js'

jest.mock('@dhis2/app-runtime', () => ({
useDhis2ConnectionStatus: jest.fn(() => ({ isConnected: true })),
}))
jest.mock('../../../../components/WindowDimensionsProvider.js', () => ({
useWindowDimensions: () => ({
width: 1920,
height: 1080,
}),
useWindowDimensions: jest.fn(() => ({ width: 1920, height: 1080 })),
}))

const baseState = { selected: { id: 'dashboard1' } }
Expand Down Expand Up @@ -80,6 +78,7 @@ test('Has enabled buttons when online', () => {
expect(getByTestId('filter-badge-button')).toBeEnabled()
expect(getByTestId('filter-badge-clear-button')).toBeEnabled()
})

test('Has disabled buttons when offline', () => {
useDhis2ConnectionStatus.mockImplementation(() => ({ isConnected: false }))
const filter = {
Expand All @@ -100,3 +99,24 @@ test('Has disabled buttons when offline', () => {
expect(getByTestId('filter-badge-button')).toBeDisabled()
expect(getByTestId('filter-badge-clear-button')).toBeDisabled()
})

test('Has disabled buttons when on small screen', () => {
useWindowDimensions.mockImplementation(() => ({ width: 440, height: 780 }))
const filter = {
id: 'ponies',
name: 'Ponies',
values: [{ name: 'Twilight Sparkle' }],
}
const { getByTestId } = render(
<Provider store={createMockStore()}>
<FilterBadge
filter={filter}
openFilterModal={jest.fn()}
removeFilter={jest.fn}
onRemove={Function.prototype}
/>
</Provider>
)
expect(getByTestId('filter-badge-button')).toBeDisabled()
expect(getByTestId('filter-badge-clear-button')).toBeDisabled()
})

0 comments on commit d501076

Please sign in to comment.