-
Notifications
You must be signed in to change notification settings - Fork 79
fix(modal): handle removal of open attribute and prevent multiple beforeClose calls #7470
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 4 commits
a26b38d
9339bea
a6462d5
fee3910
f4a4aa3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,7 +109,7 @@ describe("calcite-modal properties", () => { | |
expect(styleH).toEqual("800px"); | ||
}); | ||
|
||
it("calls the beforeClose method prior to closing", async () => { | ||
it("calls the beforeClose method prior to closing via click", async () => { | ||
const page = await newE2EPage(); | ||
const mockCallBack = jest.fn(); | ||
await page.exposeFunction("beforeClose", mockCallBack); | ||
|
@@ -123,14 +123,40 @@ describe("calcite-modal properties", () => { | |
(elm.beforeClose = (window as typeof window & Pick<typeof elm, "beforeClose">).beforeClose) | ||
); | ||
await page.waitForChanges(); | ||
await modal.setProperty("open", true); | ||
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. is there any way to fix this without changing the property name? A prop name change is technically a breaking change. 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. This isn't a breaking change, no prop is being removed. |
||
modal.setProperty("open", true); | ||
await page.waitForChanges(); | ||
await modal.setProperty("open", false); | ||
expect(await modal.getProperty("opened")).toBe(true); | ||
const closeButton = await page.find(`calcite-modal >>> .${CSS.close}`); | ||
await closeButton.click(); | ||
await page.waitForChanges(); | ||
expect(mockCallBack).toHaveBeenCalled(); | ||
expect(mockCallBack).toHaveBeenCalledTimes(1); | ||
expect(await modal.getProperty("opened")).toBe(false); | ||
}); | ||
}); | ||
|
||
it("calls the beforeClose method prior to closing via attribute", async () => { | ||
const page = await newE2EPage(); | ||
const mockCallBack = jest.fn(); | ||
await page.exposeFunction("beforeClose", mockCallBack); | ||
await page.setContent(` | ||
<calcite-modal open></calcite-modal> | ||
`); | ||
const modal = await page.find("calcite-modal"); | ||
await page.$eval( | ||
"calcite-modal", | ||
(elm: HTMLCalciteModalElement) => | ||
driskull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(elm.beforeClose = (window as typeof window & Pick<typeof elm, "beforeClose">).beforeClose) | ||
driskull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
await page.waitForChanges(); | ||
modal.setProperty("open", true); | ||
await page.waitForChanges(); | ||
expect(await modal.getProperty("opened")).toBe(true); | ||
driskull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
modal.removeAttribute("open"); | ||
await page.waitForChanges(); | ||
expect(mockCallBack).toHaveBeenCalledTimes(1); | ||
expect(await modal.getProperty("opened")).toBe(false); | ||
}); | ||
|
||
describe("opening and closing behavior", () => { | ||
it("opens and closes", async () => { | ||
const page = await newE2EPage(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.