-
Notifications
You must be signed in to change notification settings - Fork 25
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
US152268 - Migrate dialog-confirm and dialog-ifrau vdiff tests #3935
Changes from all commits
b98ec8b
a1c73fe
5d76917
15b20a4
7521163
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import '../../button/button.js'; | ||
import '../dialog-confirm.js'; | ||
import { expect, fixture, html } from '@brightspace-ui/testing'; | ||
|
||
const buttons = html` | ||
<d2l-button slot="footer" primary>Yes</d2l-button> | ||
<d2l-button slot="footer" id="cancel">No</d2l-button> | ||
`; | ||
|
||
const confirmDialog = html` | ||
<d2l-dialog-confirm id="confirm" title-text="Title" text="Are you sure?" opened> | ||
${buttons} | ||
</d2l-dialog-confirm> | ||
`; | ||
|
||
describe('dialog-confirm', () => { | ||
|
||
[/*'native',*/ 'custom'].forEach((type) => { | ||
|
||
describe(type, () => { | ||
before(() => window.D2L.DialogMixin.preferNative = type === 'native'); | ||
|
||
[ | ||
{ screen: 'wide', viewport: { width: 800, height: 500 } }, | ||
{ screen: 'narrow', viewport: { width: 600, height: 500 } } | ||
].forEach(({ screen, viewport }) => { | ||
describe(screen, () => { | ||
[ | ||
{ name: 'opened', template: confirmDialog }, | ||
{ name: 'rtl', rtl: true, template: confirmDialog }, | ||
].forEach(({ name, template, rtl }) => { | ||
it(name, async() => { | ||
await fixture(template, { viewport, rtl }); | ||
await expect(document).to.be.golden(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('internal', () => { | ||
|
||
[ | ||
{ name: 'short', template: confirmDialog }, | ||
{ name: 'long-title', template: html` | ||
<d2l-dialog-confirm title-text="A title that is really long and should wrap onto a second line." text="Are you sure?" opened> | ||
${buttons} | ||
</d2l-dialog-confirm> | ||
` }, | ||
{ name: 'no-title', template: html`<d2l-dialog-confirm text="Are you sure?" opened>${buttons}</d2l-dialog-confirm>` }, | ||
{ name: 'long-text', template: html` | ||
<d2l-dialog-confirm title-text="Title" text="Some confirm dialog content that should wrap onto a second line?" opened> | ||
${buttons} | ||
</d2l-dialog-confirm> | ||
` }, | ||
{ name: 'long-buttons', template: html` | ||
<d2l-dialog-confirm title-text="Title" text="Are you sure?" opened> | ||
<d2l-button slot="footer" primary>A really long workflow button.</d2l-button> | ||
<d2l-button slot="footer" id="cancel">Another really long workflow button.</d2l-button> | ||
</d2l-dialog-confirm> | ||
` }, | ||
{ name: 'multiple-paragraphs', template: html` | ||
<d2l-dialog-confirm title-text="Title" text="Paragraph 1 Paragraph 2" opened> | ||
${buttons} | ||
</d2l-dialog-confirm> | ||
` } | ||
].forEach(({ name, template }) => { | ||
it(name, async() => { | ||
const elem = await fixture(template, { viewport: { width: 800, height: 500 } }); | ||
await expect(elem).to.be.golden(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,24 +18,13 @@ | |
<body class="d2l-typography"> | ||
<d2l-button id="open">Open Dialog</d2l-button> | ||
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 left this |
||
|
||
<d2l-dialog id="ifrau-dialog" title-text="Title" width="400"> | ||
<d2l-dialog id="ifrau-dialog" title-text="Title" width="400" opened> | ||
<div>Line 1</div> | ||
<div>Line 2</div> | ||
<div>Line 3</div> | ||
<div>Line 4</div> | ||
<d2l-button slot="footer" primary>Yes</d2l-button> | ||
<d2l-button slot="footer" id="cancel">No</d2l-button> | ||
</d2l-dialog> | ||
|
||
<script> | ||
const dialog = document.getElementById('ifrau-dialog'); | ||
dialog.addEventListener('d2l-dialog-open', () => { | ||
window.parent.postMessage('ifrau-dialog-open', '*'); | ||
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. Are these postMessage values no longer being used? 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. Yeah, they were used to open the dialog (and then close it in 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. Gotcha. Makes sense. |
||
}); | ||
dialog.addEventListener('d2l-dialog-close', () => { | ||
window.parent.postMessage('ifrau-dialog-close', '*'); | ||
}); | ||
</script> | ||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { expect, fixture, html } from '@brightspace-ui/testing'; | ||
import { Host } from 'ifrau/host.js'; | ||
|
||
describe('dialog-ifrau', () => { | ||
|
||
[/*'native',*/ 'custom'].forEach((type) => { | ||
|
||
describe(type, () => { | ||
let iframeSrc; | ||
|
||
before(() => { | ||
const preferNative = (type === 'native' ? '' : '?preferNative=false'); | ||
iframeSrc = `${window.location.origin}/components/dialog/test/dialog-ifrau-contents.vdiff.html${preferNative}`; | ||
|
||
const iframeOrigin = new URL(iframeSrc).origin; | ||
const verifyPostMessage = (evt, expectedData) => { | ||
return evt && evt.data === expectedData && iframeOrigin === evt.origin; | ||
}; | ||
const handleIsFramedRequest = evt => { | ||
if (!verifyPostMessage(evt, 'isFramedRequest')) return; | ||
evt.source.postMessage({ isFramed: true }, iframeSrc); | ||
}; | ||
window.addEventListener('message', handleIsFramedRequest, false); | ||
}); | ||
|
||
[ | ||
{ name: 'ifrau top height lt dialog top margin', ifrau: { availableHeight: 500, top: 50 } }, | ||
{ name: 'ifrau top height gt dialog top margin', ifrau: { availableHeight: 500, top: 120 } }, | ||
{ name: 'ifrau available height lt host height', ifrau: { availableHeight: 300, top: 50 } }, | ||
{ name: 'host scrolled down', ifrau: { availableHeight: 400, top: -50 } } | ||
].forEach(({ name, ifrau }) => { | ||
it(name, async() => { | ||
const elem = await fixture(html`<div id="ifrau-dialog-container" style="width: 650px; line-height: 0;"></div>`, { viewport: { width: 726, height: 300 } }); | ||
const ifrauHost = new Host( | ||
() => elem, | ||
iframeSrc, | ||
{ height: '450px' } | ||
); | ||
|
||
await ifrauHost.registerService('dialogWC', '0.1', { | ||
showBackdrop: () => { | ||
return { | ||
availableHeight: ifrau.availableHeight, | ||
top: ifrau.top | ||
}; | ||
}, | ||
hideBackdrop: async() => {} | ||
}); | ||
await ifrauHost.connect(); | ||
|
||
await expect(document).to.be.golden(); | ||
}).timeout(5000); // ifrau connecting can be very slow | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting up by using
opened
attribute is definitely much cleaner, which is great. I think the helper was implicitly also testing thed2l-dialog-open
&d2l-dialog-close
events. I think the open event may still be covered by some unit tests (also implicitly), but I'm not sure the close event is covered. I'm wondering if it would be a good idea for us to add an explicit unit test for those events, since consumers do rely on them. Or maybe you already checked and found they are covered?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'd say that's kinda covered by the dialog-mixin.vdiff.js tests. But I like the idea of adding non-vdiff, dedicated tests - I'll add some to this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do, I'm thinking those unit tests should be for the general mixin case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, just pushed a new file - it'll fail until we expose
oneDefaultPreventedEvent
in@brightspace-ui/testing
, but is that what you had in mind?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, merged the change in
@brightspace-ui/testing
and now CI here is passing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, exactly. Looks great!