Skip to content

Commit 03a1cea

Browse files
committed
Fix tests
1 parent 275cad7 commit 03a1cea

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

jest-setup.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
// Jest setup provided by Grafana scaffolding
22
import './.config/jest-setup';
3+
4+
// Polyfill for TextEncoder/TextDecoder in Node.js environment
5+
import { TextEncoder, TextDecoder } from 'util';
6+
7+
global.TextEncoder = TextEncoder;
8+
global.TextDecoder = TextDecoder;
9+
10+
// Polyfill for IntersectionObserver
11+
class MockIntersectionObserver {
12+
constructor() {}
13+
observe() {}
14+
unobserve() {}
15+
disconnect() {}
16+
}
17+
18+
global.IntersectionObserver = MockIntersectionObserver;

src/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { describeMetric } from 'utils';
99
import { renderWithESProvider } from 'test-helpers/render';
1010

1111
describe('Terms Settings Editor', () => {
12-
it('Pipeline aggregations should not be in "order by" options', () => {
12+
it('Pipeline aggregations should not be in "order by" options', async () => {
1313
const termsAgg: Terms = {
1414
id: '1',
1515
type: 'terms',
@@ -36,6 +36,6 @@ describe('Terms Settings Editor', () => {
3636
// TopMetrics cannot be used as order by option
3737
expect(screen.queryByText(describeMetric(topMetrics))).not.toBeInTheDocument();
3838
// All other metric aggregations can be used in order by
39-
expect(screen.getByText(describeMetric(avg))).toBeInTheDocument();
39+
expect(await screen.findByText(describeMetric(avg))).toBeInTheDocument();
4040
});
4141
});

src/components/hooks/useCreatableSelectPersistedBehaviour.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('useCreatableSelectPersistedBehaviour', () => {
3232

3333
// we type in the input 'Option 2', which should prompt an option creation
3434
await userEvent.type(input, 'Option 2');
35-
const creatableOption = screen.getByLabelText('Select option');
35+
const creatableOption = screen.getByTestId('data-testid Select option');
3636
expect(creatableOption).toHaveTextContent('Option 2');
3737

3838
// we click on the creatable option to trigger its creation
@@ -83,7 +83,7 @@ describe('useCreatableSelectPersistedBehaviour', () => {
8383

8484
// we type in the input 'Option 2', which should prompt an option creation
8585
await userEvent.type(input, 'Option 2');
86-
await userEvent.click(screen.getByLabelText('Select option'));
86+
await userEvent.click(screen.getByTestId('data-testid Select option'));
8787

8888
expect(onChange).toHaveBeenLastCalledWith({ value: 'Option 2' });
8989
});

src/configuration/DataLinks.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('DataLinks tests', () => {
2020
it('should render correctly with no fields', async () => {
2121
setup();
2222

23-
expect(screen.getByRole('heading', { name: 'Data links' }));
23+
expect(screen.getByText('Data links')).toBeInTheDocument();
2424
expect(screen.getByRole('button', { name: 'Add' })).toBeInTheDocument();
2525
expect(await screen.findAllByRole('button')).toHaveLength(1);
2626
});
@@ -29,7 +29,7 @@ describe('DataLinks tests', () => {
2929
setup({ value: testValue });
3030

3131
expect(await screen.findAllByRole('button', { name: 'Remove field' })).toHaveLength(2);
32-
expect(await screen.findAllByRole('checkbox', { name: 'Internal link' })).toHaveLength(2);
32+
expect(await screen.findAllByRole('switch', { name: 'Internal link' })).toHaveLength(2);
3333
});
3434

3535
it('should call onChange to add a new field when the add button is clicked', async () => {

0 commit comments

Comments
 (0)