Skip to content

Commit d24b5ff

Browse files
author
Tanner Reits
committed
test(modal): add half-sheet test
1 parent 35d04dc commit d24b5ff

File tree

3 files changed

+93
-9
lines changed

3 files changed

+93
-9
lines changed

core/src/components/modal/test/shape/index.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
1515

1616
<style>
17-
ion-modal {
18-
--box-shadow: 0px 0px 30px 10px rgba(0, 0, 0, 0.1);
19-
}
20-
2117
.container {
2218
margin-bottom: 20px;
2319
}

core/src/components/modal/test/sheet/index.html

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
.grid-item {
7373
height: 200px;
7474
}
75+
76+
.half-sheet {
77+
--height: 50%;
78+
}
7579
</style>
7680
</head>
7781

@@ -140,6 +144,13 @@
140144
Backdrop is inactive
141145
</button>
142146

147+
<button
148+
id="half-sheet"
149+
onclick="presentHalfSheetModal({ cssClass: 'half-sheet', backdropBreakpoint: 0.5, initialBreakpoint: 1, breakpoints: [1] })"
150+
>
151+
Half Sheet w/ Footer
152+
</button>
153+
143154
<div class="grid">
144155
<div class="grid-item red"></div>
145156
<div class="grid-item green"></div>
@@ -214,12 +225,65 @@
214225
modal.remove();
215226
}
216227

217-
async function presentCardModal() {
218-
const presentingEl = document.querySelectorAll('.ion-page')[1];
219-
const modal = createModal('card', {
220-
presentingElement: presentingEl,
228+
async function presentHalfSheetModal(options) {
229+
let items = '';
230+
231+
for (var i = 0; i < 3; i++) {
232+
items += `<ion-item>Item ${i}</ion-item>`;
233+
}
234+
235+
// create component to open
236+
const element = document.createElement('div');
237+
element.innerHTML = `
238+
<ion-header>
239+
<ion-toolbar>
240+
<ion-title>Super Modal</ion-title>
241+
<ion-buttons slot="end">
242+
<ion-button class="dismiss">Dismiss Modal</ion-button>
243+
</ion-buttons>
244+
</ion-toolbar>
245+
</ion-header>
246+
<ion-content>
247+
<ion-list>
248+
${items}
249+
</ion-list>
250+
</ion-content>
251+
<ion-footer>
252+
<ion-toolbar>
253+
<ion-button expand="block">Action</ion-button>
254+
</ion-toolbar>
255+
</ion-footer>
256+
`;
257+
258+
let extraOptions = {
259+
initialBreakpoint: 0.25,
260+
breakpoints: [0, 0.25, 0.5, 0.75, 1],
261+
};
262+
263+
if (options) {
264+
extraOptions = {
265+
...extraOptions,
266+
...options,
267+
};
268+
}
269+
270+
// present the modal
271+
const modalElement = Object.assign(document.createElement('ion-modal'), {
272+
component: element,
273+
...extraOptions,
221274
});
222-
await modal.present();
275+
276+
// listen for close event
277+
const button = element.querySelector('ion-button');
278+
button.addEventListener('click', () => {
279+
modalElement.dismiss();
280+
});
281+
document.body.appendChild(modalElement);
282+
283+
await modalElement.present();
284+
285+
await modalElement.onDidDismiss();
286+
modalElement.remove();
223287
}
224288
</script>
225289
</body>

core/src/components/modal/test/sheet/modal.e2e.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
1616
});
1717
});
1818

19+
configs({ modes: ['ionic-md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
20+
test.describe(title('sheet modal: half screen rendering'), () => {
21+
test('should not have visual regressions', async ({ page }) => {
22+
await page.goto('/src/components/modal/test/sheet', config);
23+
const ionModalDidPresent = await page.spyOnEvent('ionModalDidPresent');
24+
25+
await page.click('#half-sheet');
26+
27+
await ionModalDidPresent.next();
28+
29+
await expect(page).toHaveScreenshot(screenshot(`modal-half-sheet-present`), {
30+
/**
31+
* Animations must be enabled to capture the screenshot.
32+
* By default, animations are disabled with toHaveScreenshot,
33+
* and when capturing the screenshot will call animation.finish().
34+
* This will cause the modal to close and the screenshot capture
35+
* to be invalid.
36+
*/
37+
animations: 'allow',
38+
});
39+
});
40+
});
41+
});
42+
1943
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => {
2044
test.describe(title('sheet modal: backdrop'), () => {
2145
test.beforeEach(async ({ page }) => {

0 commit comments

Comments
 (0)