Skip to content

Commit c78201d

Browse files
Adarsh0427arkid15r
andauthored
Fixed SortBy component test cases #2173 (#2180)
* fixed SortBy component testcases * fixed bot suggestions * Update code --------- Co-authored-by: Arkadii Yakovets <[email protected]>
1 parent 90d0b5a commit c78201d

File tree

3 files changed

+1432
-1785
lines changed

3 files changed

+1432
-1785
lines changed

frontend/__tests__/unit/components/SortBy.test.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,31 @@ describe('<SortBy />', () => {
2222
await act(async () => {
2323
render(<SortBy {...defaultProps} />)
2424
})
25-
const select = screen.getByLabelText('Sort By :')
26-
expect(select).toBeInTheDocument()
27-
expect(select).toHaveValue('name')
25+
const sortButton = screen.getByRole('button', { name: /Sort By/ })
26+
expect(sortButton).toBeInTheDocument()
27+
const selectedOption = screen.getByText('Name', { selector: '[data-slot="value"]' })
28+
expect(selectedOption).toBeInTheDocument()
2829
})
2930

3031
it('renders all options and selects the correct one', async () => {
3132
await act(async () => {
3233
render(<SortBy {...defaultProps} />)
3334
})
34-
const select = screen.getByLabelText('Sort By :')
35-
expect(select).toHaveValue('name')
36-
// The dropdown options aren't directly visible in the DOM
37-
// We're checking for the selected value instead
38-
const selectedOption = screen.getByText('Name', { selector: '[data-slot="value"]' })
39-
expect(selectedOption).toBeInTheDocument()
35+
const sortButton = screen.getByRole('button', { name: /Sort By/ })
36+
await act(async () => {
37+
sortButton.click()
38+
})
39+
expect(await screen.findByRole('option', { name: 'Name' })).toBeInTheDocument()
40+
expect(await screen.findByRole('option', { name: 'Date' })).toBeInTheDocument()
4041
})
4142

4243
it('calls onSortChange when a different option is selected', async () => {
4344
await act(async () => {
4445
render(<SortBy {...defaultProps} />)
4546
})
4647
await act(async () => {
47-
fireEvent.change(screen.getByLabelText('Sort By :'), { target: { value: 'date' } })
48+
const hiddenSelect = screen.getByRole('combobox', { hidden: true })
49+
fireEvent.change(hiddenSelect, { target: { value: 'date' } })
4850
})
4951
expect(defaultProps.onSortChange).toHaveBeenCalledWith('date')
5052
})
@@ -83,12 +85,13 @@ describe('<SortBy />', () => {
8385
await act(async () => {
8486
render(<SortBy {...defaultProps} />)
8587
})
86-
const select = screen.getByLabelText('Sort By :')
87-
expect(select.tagName).toBe('SELECT')
88+
const hiddenSelect = screen.getByRole('combobox', { hidden: true })
89+
expect(hiddenSelect.tagName).toBe('SELECT')
8890

8991
// Use getAllByText to handle multiple elements with same text
90-
const containers = screen.getAllByText('Sort By :')
91-
const container = containers[0].closest('div')
92+
const sortButton = screen.getByRole('button', { name: /Sort By/ })
93+
const container = sortButton.closest('div')
9294
expect(container).toBeInTheDocument()
95+
expect(hiddenSelect).toHaveAccessibleName(/Sort By/)
9396
})
9497
})

frontend/package.json

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,21 @@
2323
"@fortawesome/free-brands-svg-icons": "^6.7.2",
2424
"@fortawesome/free-regular-svg-icons": "^6.7.2",
2525
"@fortawesome/free-solid-svg-icons": "^6.7.2",
26-
"@fortawesome/react-fontawesome": "^3.0.1",
26+
"@fortawesome/react-fontawesome": "^3.0.2",
2727
"@graphql-typed-document-node/core": "^3.2.0",
28-
"@heroui/button": "^2.2.24",
29-
"@heroui/modal": "^2.2.21",
30-
"@heroui/react": "^2.8.2",
31-
"@heroui/select": "^2.4.25",
32-
"@heroui/skeleton": "^2.2.15",
33-
"@heroui/system": "^2.4.20",
34-
"@heroui/theme": "^2.4.20",
35-
"@heroui/toast": "^2.0.14",
36-
"@heroui/tooltip": "^2.2.21",
28+
"@heroui/button": "^2.2.25",
29+
"@heroui/modal": "^2.2.22",
30+
"@heroui/react": "^2.8.3",
31+
"@heroui/select": "^2.4.26",
32+
"@heroui/skeleton": "^2.2.16",
33+
"@heroui/system": "^2.4.21",
34+
"@heroui/theme": "^2.4.21",
35+
"@heroui/toast": "^2.0.15",
36+
"@heroui/tooltip": "^2.2.22",
3737
"@next/eslint-plugin-next": "^15.5.2",
3838
"@next/third-parties": "^15.5.2",
39-
"@sentry/nextjs": "^10.8.0",
39+
"@sentry/nextjs": "^10.9.0",
4040
"@testing-library/user-event": "^14.6.1",
41-
"@types/leaflet.markercluster": "^1.5.5",
4241
"@types/lodash": "^4.17.20",
4342
"apexcharts": "^5.3.4",
4443
"class-variance-authority": "^0.7.1",
@@ -84,14 +83,14 @@
8483
"@testing-library/react": "^16.3.0",
8584
"@types/jest": "^29.5.14",
8685
"@types/leaflet": "^1.9.20",
87-
"@types/leaflet.markercluster": "^1.5.5",
86+
"@types/leaflet.markercluster": "^1.5.6",
8887
"@types/markdown-it": "^14.1.2",
8988
"@types/node": "^22.18.0",
9089
"@types/react": "^19.1.12",
9190
"@types/react-dom": "^19.1.9",
9291
"@types/react-gtm-module": "^2.0.4",
93-
"@typescript-eslint/eslint-plugin": "^8.41.0",
94-
"@typescript-eslint/parser": "^8.41.0",
92+
"@typescript-eslint/eslint-plugin": "^8.42.0",
93+
"@typescript-eslint/parser": "^8.42.0",
9594
"eslint": "^9.34.0",
9695
"eslint-config-next": "^15.5.2",
9796
"eslint-config-prettier": "^10.1.8",
@@ -106,7 +105,7 @@
106105
"import-in-the-middle": "^1.14.2",
107106
"jest": "^29.7.0",
108107
"jest-axe": "^10.0.0",
109-
"jest-environment-jsdom": "^30.1.1",
108+
"jest-environment-jsdom": "^30.1.2",
110109
"open": "^10.2.0",
111110
"postcss": "^8.5.6",
112111
"prettier": "^3.6.2",
@@ -116,7 +115,7 @@
116115
"ts-jest": "^29.4.1",
117116
"ts-node": "^10.9.2",
118117
"typescript": "~5.8.3",
119-
"typescript-eslint": "^8.41.0",
118+
"typescript-eslint": "^8.42.0",
120119
"util": "^0.12.5"
121120
},
122121
"engines": {

0 commit comments

Comments
 (0)