Skip to content

Commit 344aa9c

Browse files
authored
chore(components): upgrade LeafyGreen modal components COMPASS-9642 (#7594)
* Upgrade LG modal packages * Fix Modal to adopt LG Modal v20 * Fix connection-form to work around LG Modal v20 * Update generative-ai to adopt marketing-modal v7 * Fix compass-import-export to work around LG modal v20 * Update compass-welcome to adopt marketing-modal v7 * Update compass-explain-plan to LG Modal v20 * Fix compass-crud to adopt LG modal v20 * Update compass-schema to LG Modal v20 * Add workaround for jsdom missing HTMLDialogElement support * Update generative-ai to adopt LG modal v20 * Fix fullScreen prop on derived Modal * Remove use of deprecated backdropClassName * Remove workaround for MarketingModal button disabling * Fix remaining components tests * Revert workaround for LG-5593 * Update existing tests to handle dialog elements remaining in the DOM * Update databases-collections to allow immediate removal of the heading * Update e2e tests to use waitForDisplayed over waitForExist as this is more important with the new dialog * Update e2e tests removing [role=dialog] from confirm dialog selectors * Update e2e tests to wait for bulk delete modal to disappear * Update e2e tests to wait for connection form to be non-clickable in any case * Update e2e tests to fix modal regressions * Disable pointer events on a closed modal * Disable auto-focus on confirmation modal children by default * Add new modal specific commands * Update E2E tests to use new modal commands instead of waitForDisplayed * Default initialFocus to "null" to avoid breaking existing modals * Wait for confirm button to show instead of simply expecting it * Update FocusMode tests to handle LG Modal v20 * Update SettingsModal tests to handle LG Modal v20 * Clarify disabling the @typescript-eslint/no-namespace and add a TODO to move the code later * Partial revert of ddd6d70 * Fix auto-focus in bulk update and delete modals * Correcting sizing styles * Correcting sizing styles more * Use named imports * Upgrade confirm-modal package * Fix useConfirmation's confirmButtonProps types * Update use of ConfirmationModal * Set initial focus on cancel (fallback to confirm) button * Fix package lock
1 parent 8752bca commit 344aa9c

File tree

79 files changed

+1083
-946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1083
-946
lines changed

configs/mocha-config-compass/register/jsdom-extra-mocks-register.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ Object.assign(tabbable, {
3535
origTabbable.isTabbable(node, { ...options, displayCheck: 'none' }),
3636
});
3737

38+
// Workaround for missing HTMLDialogElement in jsdom
39+
// See https://github.com/jsdom/jsdom/issues/3294
40+
41+
Object.assign(HTMLDialogElement.prototype, {
42+
show() {
43+
this.open = true;
44+
this.style.display = '';
45+
},
46+
showModal() {
47+
this.open = true;
48+
this.style.display = '';
49+
},
50+
close(returnValue) {
51+
this.open = false;
52+
this.returnValue = returnValue;
53+
this.style.display = 'none';
54+
},
55+
});
56+
3857
// leafygreen (through `clipboard` library) uses deprecated API check that is
3958
// not working in jsdom if copy / paste APIs are supported
4059
if (!window.document.queryCommandSupported) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Assertion, util } from 'chai';
2+
3+
// TODO(COMPASS-10119): Move declaration into a separate .d.ts and implementation into a *-register.js file as we do with other global patching code intended for tests.
4+
5+
declare global {
6+
// eslint-disable-next-line @typescript-eslint/no-namespace -- We're following a pattern established in the `@types/chai-as-promised` package to add a Chai assertion property.
7+
export namespace Chai {
8+
interface Assertion {
9+
/** Asserts that a dialog is open */
10+
get open(): Assertion;
11+
/** Asserts that a dialog is closed */
12+
get closed(): Assertion;
13+
}
14+
}
15+
}
16+
17+
util.addProperty(
18+
Assertion.prototype,
19+
'open',
20+
function (this: typeof Assertion) {
21+
const obj = util.flag(this, 'object');
22+
new Assertion(obj).to.be.instanceof(HTMLDialogElement);
23+
new Assertion(obj as HTMLDialogElement).has.property(
24+
'open',
25+
true,
26+
'Expected dialog to be open'
27+
);
28+
}
29+
);
30+
31+
util.addProperty(
32+
Assertion.prototype,
33+
'closed',
34+
function (this: typeof Assertion) {
35+
const obj = util.flag(this, 'object');
36+
new Assertion(obj).to.be.instanceof(HTMLDialogElement);
37+
new Assertion(obj as HTMLDialogElement).has.property(
38+
'open',
39+
false,
40+
'Expected dialog to be closed'
41+
);
42+
}
43+
);

configs/testing-library-compass/src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ import { expect } from 'chai';
7373
import { Provider } from 'react-redux';
7474
import ConnectionString from 'mongodb-connection-string-url';
7575

76+
import './assertions';
77+
7678
function wait(ms: number) {
7779
return new Promise((resolve) => {
7880
setTimeout(resolve, ms);

0 commit comments

Comments
 (0)