|
1 | 1 | import { expect, it } from 'vitest'; |
2 | | -import { screen, fireEvent, within } from '@testing-library/react'; |
| 2 | +import { screen, fireEvent } from '@testing-library/react'; |
3 | 3 | import { setupIntegrationTestViewer } from '@tests/utils/test-utils'; |
4 | 4 | import config from '../mirador-configs/single-van-gogh'; |
5 | 5 |
|
@@ -45,12 +45,20 @@ describe('Annotations in Mirador', () => { |
45 | 45 | // Re. this regex: be sure that the number of annotations starts with a non zero digit |
46 | 46 | const annoCountSubtitle = await screen.findByText(/Showing [1-9]\d* annotations/); |
47 | 47 | expect(annoCountSubtitle).toBeInTheDocument(); |
48 | | - const annotationCount = annoCountSubtitle.innerText.match(/\d+/)[0]; |
| 48 | + const annotationCount = annoCountSubtitle.textContent.match(/\d+/)[0]; |
49 | 49 |
|
50 | | - const annotationPanel = await screen.findByRole('complementary', { name: /annotations/i }); |
51 | | - expect(annotationPanel).toBeInTheDocument(); |
| 50 | + // NOTE: findByRole was causing mysterious failures so we are using querySelector |
| 51 | + // for the rest of this test. |
| 52 | + /* eslint-disable testing-library/no-node-access */ |
| 53 | + const annotationPanel = annoCountSubtitle.closest('aside'); |
| 54 | + const menu = annotationPanel.querySelector('[role="menu"]'); |
52 | 55 |
|
53 | | - const listItems = await within(annotationPanel).findAllByRole('menuitem'); |
54 | | - expect(listItems).toHaveLength(annotationCount); |
| 56 | + // Find all menu items |
| 57 | + const listItems = menu.querySelectorAll('[role="menuitem"]'); |
| 58 | + /* eslint-enable testing-library/no-node-access */ |
| 59 | + |
| 60 | + // Convert annotationCount (likely a string) to number |
| 61 | + const expectedCount = Number(annotationCount); |
| 62 | + expect(listItems.length).toBe(expectedCount); |
55 | 63 | }); |
56 | 64 | }); |
0 commit comments