Skip to content

Commit cca86c7

Browse files
committed
Adjust annotations integration test to remove findByRole
This fixes mysterious failures
1 parent fda2f8a commit cca86c7

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

__tests__/integration/mirador/tests/annotations.test.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, it } from 'vitest';
2-
import { screen, fireEvent, within } from '@testing-library/react';
2+
import { screen, fireEvent } from '@testing-library/react';
33
import { setupIntegrationTestViewer } from '@tests/utils/test-utils';
44
import config from '../mirador-configs/single-van-gogh';
55

@@ -45,12 +45,20 @@ describe('Annotations in Mirador', () => {
4545
// Re. this regex: be sure that the number of annotations starts with a non zero digit
4646
const annoCountSubtitle = await screen.findByText(/Showing [1-9]\d* annotations/);
4747
expect(annoCountSubtitle).toBeInTheDocument();
48-
const annotationCount = annoCountSubtitle.innerText.match(/\d+/)[0];
48+
const annotationCount = annoCountSubtitle.textContent.match(/\d+/)[0];
4949

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"]');
5255

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);
5563
});
5664
});

0 commit comments

Comments
 (0)