Skip to content

Commit 84b5697

Browse files
committed
Fix remaining components tests
1 parent 5fb1130 commit 84b5697

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

packages/compass-components/src/components/content-with-fallback.spec.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@ describe('ContentWithFallback', function () {
5858
{ container }
5959
);
6060

61-
expect(container.children.length).to.equal(2);
62-
const [contentContainer, contextMenuContainer] = Array.from(
63-
container.children
64-
);
61+
expect(container.children.length).to.equal(3);
62+
const [contentContainer, contextMenuContainer, confirmationModal] =
63+
Array.from(container.children);
6564
expect(contentContainer.children.length).to.equal(0);
6665
expect(contextMenuContainer.getAttribute('data-testid')).to.equal(
6766
'context-menu-container'
6867
);
68+
expect(confirmationModal.getAttribute('data-testid')).to.equal(
69+
// TODO: Change to 'confirmation-modal' when https://github.com/mongodb/leafygreen-ui/pull/3183 gets released
70+
'lg-confirmation_modal'
71+
);
6972
});
7073

7174
it('should render fallback when the timeout passes', async function () {

packages/compass-components/src/components/modals/confirmation-modal.spec.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import React from 'react';
2-
import { render, screen, cleanup } from '@mongodb-js/testing-library-compass';
2+
import {
3+
render,
4+
screen,
5+
cleanup,
6+
within,
7+
} from '@mongodb-js/testing-library-compass';
38
import { expect } from 'chai';
49

510
import ConfirmationModal from './confirmation-modal';
@@ -23,8 +28,8 @@ describe('ConfirmationModal Component', function () {
2328
});
2429

2530
it('should show the modal button', function () {
26-
renderModal();
27-
const button = screen.getByText('Confirm').closest('button');
31+
const { container } = renderModal();
32+
const button = within(container).getByText('Confirm').closest('button');
2833
expect(button).to.not.match('disabled');
2934
});
3035

packages/compass-components/src/hooks/use-confirmation.spec.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
render,
33
screen,
44
waitFor,
5-
waitForElementToBeRemoved,
65
within,
76
userEvent,
87
} from '@mongodb-js/testing-library-compass';
@@ -34,7 +33,8 @@ describe('use-confirmation', function () {
3433
);
3534
userEvent.click(screen.getByText('Open Modal'));
3635
await waitFor(() => {
37-
modal = screen.getByTestId('confirmation-modal');
36+
// TODO: Change to 'confirmation-modal' when https://github.com/mongodb/leafygreen-ui/pull/3183 gets released
37+
modal = screen.getByTestId('lg-confirmation_modal');
3838
});
3939
});
4040

@@ -49,18 +49,14 @@ describe('use-confirmation', function () {
4949

5050
it('handles cancel action', async function () {
5151
userEvent.click(within(modal).getByText('Cancel'));
52-
await waitForElementToBeRemoved(() =>
53-
screen.getByTestId('confirmation-modal')
54-
);
52+
await waitFor(() => expect(modal).to.not.be.displayed);
5553
const confirmed = await response;
5654
expect(confirmed).to.be.false;
5755
});
5856

5957
it('handles confirm action', async function () {
6058
userEvent.click(within(modal).getByText('Yes'));
61-
await waitForElementToBeRemoved(() =>
62-
screen.getByTestId('confirmation-modal')
63-
);
59+
await waitFor(() => expect(modal).to.not.be.displayed);
6460
const confirmed = await response;
6561
expect(confirmed).to.be.true;
6662
});

0 commit comments

Comments
 (0)