Skip to content

Commit 2f2b35d

Browse files
committed
Fix remaining components tests
1 parent abe1bb0 commit 2f2b35d

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ describe('use-confirmation', function () {
3434
);
3535
userEvent.click(screen.getByText('Open Modal'));
3636
await waitFor(() => {
37-
modal = screen.getByTestId('confirmation-modal');
37+
// TODO: Change to 'confirmation-modal' when https://github.com/mongodb/leafygreen-ui/pull/3183 gets released
38+
modal = screen.getByTestId('lg-confirmation_modal');
3839
});
3940
});
4041

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

5051
it('handles cancel action', async function () {
5152
userEvent.click(within(modal).getByText('Cancel'));
52-
await waitForElementToBeRemoved(() =>
53-
screen.getByTestId('confirmation-modal')
54-
);
53+
await waitFor(() => expect(modal).to.not.be.displayed);
5554
const confirmed = await response;
5655
expect(confirmed).to.be.false;
5756
});
5857

5958
it('handles confirm action', async function () {
6059
userEvent.click(within(modal).getByText('Yes'));
61-
await waitForElementToBeRemoved(() =>
62-
screen.getByTestId('confirmation-modal')
63-
);
60+
await waitFor(() => expect(modal).to.not.be.displayed);
6461
const confirmed = await response;
6562
expect(confirmed).to.be.true;
6663
});

0 commit comments

Comments
 (0)