-
Notifications
You must be signed in to change notification settings - Fork 245
chore(components): upgrade LeafyGreen modal components COMPASS-9642 #7594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d9894b2
8096983
1a79dee
baf002b
9fc6af6
e1855b4
c5274cb
37a6cc7
5f418d2
65831d9
09eb31d
cd281f6
21f3682
aa0f76f
5cc4946
5ae783d
669e0cd
e473a04
01c66a3
b343940
3cdb6c7
ad72a99
5e5ce3b
2778a71
d1fe84b
6ab317e
70e7015
f839793
cf032a1
bb6ff36
3799746
7ca774e
de78fec
920efc6
2f73260
c2e5d46
9646d87
d43fc16
dbe7574
9767e4f
564fc1e
6fa377d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { Assertion, util } from 'chai'; | ||
|
|
||
| declare global { | ||
| // eslint-disable-next-line @typescript-eslint/no-namespace | ||
| export namespace Chai { | ||
| interface Assertion { | ||
| /** Asserts that a dialog is open */ | ||
| get open(): Assertion; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Anemy FYI for the eslint plugin you are working on in devtools-shared, new terminator assertion |
||
| /** Asserts that a dialog is closed */ | ||
| get closed(): Assertion; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| util.addProperty( | ||
| Assertion.prototype, | ||
| 'open', | ||
| function (this: typeof Assertion) { | ||
| const obj = util.flag(this, 'object'); | ||
| new Assertion(obj).to.be.instanceof(HTMLDialogElement); | ||
| new Assertion(obj as HTMLDialogElement).has.property( | ||
| 'open', | ||
| true, | ||
| 'Expected dialog to be open' | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| util.addProperty( | ||
| Assertion.prototype, | ||
| 'closed', | ||
| function (this: typeof Assertion) { | ||
| const obj = util.flag(this, 'object'); | ||
| new Assertion(obj).to.be.instanceof(HTMLDialogElement); | ||
| new Assertion(obj as HTMLDialogElement).has.property( | ||
| 'open', | ||
| false, | ||
| 'Expected dialog to be closed' | ||
| ); | ||
| } | ||
| ); | ||
|
Comment on lines
5
to
43
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding new assertions to determine if a I'm putting this here (instead of the |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ import { | |
| screen, | ||
| userEvent, | ||
| waitFor, | ||
| waitForElementToBeRemoved, | ||
| within, | ||
| } from '@mongodb-js/testing-library-compass'; | ||
| import { | ||
|
|
@@ -628,8 +627,9 @@ describe('CompassAssistantProvider', function () { | |
| userEvent.click(clearButton); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByTestId('assistant-confirm-clear-chat-modal')).to | ||
| .exist; | ||
| expect( | ||
| screen.getByTestId('assistant-confirm-clear-chat-modal').firstChild | ||
| ).to.exist; | ||
| }); | ||
|
|
||
| // There should be messages in the chat | ||
|
|
@@ -640,9 +640,11 @@ describe('CompassAssistantProvider', function () { | |
| const confirmButton = within(modal).getByText('Clear chat'); | ||
| userEvent.click(confirmButton); | ||
|
|
||
| await waitForElementToBeRemoved(() => | ||
| screen.getByTestId('assistant-confirm-clear-chat-modal') | ||
| ); | ||
| await waitFor(() => { | ||
| expect( | ||
| screen.getByTestId('assistant-confirm-clear-chat-modal').firstChild | ||
| ).to.not.exist; | ||
| }); | ||
|
|
||
| expect(mockChat.messages).to.be.empty; | ||
| expect(screen.queryByTestId('assistant-message-1')).to.not.exist; | ||
|
|
@@ -658,8 +660,9 @@ describe('CompassAssistantProvider', function () { | |
| userEvent.click(clearButton); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByTestId('assistant-confirm-clear-chat-modal')).to | ||
| .exist; | ||
| expect( | ||
| screen.getByTestId('assistant-confirm-clear-chat-modal').firstChild | ||
| ).to.exist; | ||
| }); | ||
|
|
||
| // There should be messages in the chat | ||
|
|
@@ -670,9 +673,11 @@ describe('CompassAssistantProvider', function () { | |
| const cancelButton = within(modal).getByText('Cancel'); | ||
| userEvent.click(cancelButton); | ||
|
|
||
| await waitForElementToBeRemoved(() => | ||
| screen.getByTestId('assistant-confirm-clear-chat-modal') | ||
| ); | ||
| await waitFor(() => { | ||
| expect( | ||
| screen.getByTestId('assistant-confirm-clear-chat-modal').firstChild | ||
| ).to.not.exist; | ||
| }); | ||
|
|
||
| expect(mockChat.messages).to.deep.equal(mockMessages); | ||
| expect(screen.getByTestId('assistant-message-1')).to.exist; | ||
|
|
@@ -690,8 +695,9 @@ describe('CompassAssistantProvider', function () { | |
| userEvent.click(clearButton); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByTestId('assistant-confirm-clear-chat-modal')).to | ||
| .exist; | ||
| expect( | ||
| screen.getByTestId('assistant-confirm-clear-chat-modal').firstChild | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
| ).to.exist; | ||
| }); | ||
|
|
||
| // There should be messages in the chat | ||
|
|
@@ -704,9 +710,11 @@ describe('CompassAssistantProvider', function () { | |
| const confirmButton = within(modal).getByText('Clear chat'); | ||
| userEvent.click(confirmButton); | ||
|
|
||
| await waitForElementToBeRemoved(() => | ||
| screen.getByTestId('assistant-confirm-clear-chat-modal') | ||
| ); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI this changes the test because waitForRemoved specifically exists to check first that the element exists before being removed, just waitFor doesn't do it, but I guess it's good enough if we checked before
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree that does change the test - but also, that behavior seems like a race-condition to me 🤔 It depends on an implementation detail of the This might be an inherent property of the testing library?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not related to testing-library, it depends just on how it's rendered on the screen |
||
| await waitFor(() => { | ||
| expect( | ||
| screen.getByTestId('assistant-confirm-clear-chat-modal').firstChild | ||
| ).to.not.exist; | ||
| }); | ||
|
|
||
| // The non-genuine warning message should still be in the chat | ||
| expect(screen.getByTestId('assistant-message-non-genuine-warning')).to | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@mongodb-js/testing-library-compass'; | ||
| import { expect } from 'chai'; | ||
|
|
||
| import { Modal } from './modal'; | ||
|
|
||
| describe('Modal Component', function () { | ||
| it('opens and closes', () => { | ||
| const { rerender } = render( | ||
| <Modal data-testid="modal" open={false}> | ||
| <p data-testid="modal-content">The content!</p> | ||
| </Modal> | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('modal')).to.be.closed; | ||
|
|
||
| rerender( | ||
| <Modal data-testid="modal" open={true}> | ||
| <p data-testid="modal-content">The content!</p> | ||
| </Modal> | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('modal')).to.be.open; | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.