test(infinite-scroll): migrate tests to playwright (#26085)

This commit is contained in:
Liam DeBeasi
2022-10-10 08:04:28 -05:00
committed by GitHub
parent 3a83781374
commit 01ac2f80a4
9 changed files with 70 additions and 88 deletions

View File

@ -1,44 +0,0 @@
import { newE2EPage } from '@stencil/core/testing';
import type { E2EPage } from '@stencil/core/testing';
/**
* Scrolls an `ion-content` element to the bottom, triggering the `ionInfinite` event.
* Waits for the custom event to complete.
*/
const scrollIonContentPage = async (page: E2EPage) => {
const content = await page.find('ion-content');
await content.callMethod('scrollToBottom');
await page.waitForChanges();
const ev = await page.spyOnEvent('ionInfiniteComplete', 'document');
await ev.next();
};
describe('infinite-scroll: basic', () => {
it('should match existing visual screenshots', async () => {
const page = await newE2EPage({
url: '/src/components/infinite-scroll/test/basic?ionic:_testing=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});
describe('when enabled', () => {
it('should load more items when scrolled to the bottom', async () => {
const page = await newE2EPage({
url: '/src/components/infinite-scroll/test/basic?ionic:_testing=true',
});
const initialItems = await page.findAll('ion-item');
expect(initialItems.length).toBe(30);
await scrollIonContentPage(page);
const updatedItems = await page.findAll('ion-item');
expect(updatedItems.length).toBe(60);
});
});
});

View File

@ -47,7 +47,7 @@
infiniteScroll.complete();
appendItems();
// Custom event consumed in the e2e tests
document.dispatchEvent(new CustomEvent('ionInfiniteComplete'));
window.dispatchEvent(new CustomEvent('ionInfiniteComplete'));
});
function appendItems() {

View File

@ -0,0 +1,22 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('infinite-scroll: basic', () => {
test.beforeEach(({ skip }) => {
skip.rtl();
skip.mode('ios');
});
test('should load more items when scrolled to the bottom', async ({ page }) => {
await page.goto('/src/components/infinite-scroll/test/basic');
const ionInfiniteComplete = await page.spyOnEvent('ionInfiniteComplete');
const content = page.locator('ion-content');
const items = page.locator('ion-item');
expect(await items.count()).toBe(30);
await content.evaluate((el: HTMLIonContentElement) => el.scrollToBottom(0));
await ionInfiniteComplete.next();
expect(await items.count()).toBe(60);
});
});

View File

@ -1,32 +0,0 @@
import { newE2EPage } from '@stencil/core/testing';
import type { E2EPage } from '@stencil/core/testing';
import { scrollToBottom } from '@utils/test';
/**
* Scrolls an `ion-content` element to the bottom, triggering the `ionInfinite` event.
* Waits for the custom event to complete.
*/
async function scrollPage(page: E2EPage) {
await scrollToBottom(page, '#scroll-target');
await page.waitForChanges();
const ev = await page.spyOnEvent('ionInfiniteComplete', 'document');
await ev.next();
}
describe('infinite-scroll: custom scroll target', () => {
it('should load more items when scrolled to the bottom', async () => {
const page = await newE2EPage({
url: '/src/components/infinite-scroll/test/scroll-target?ionic:_testing=true',
});
const initialItems = await page.findAll('ion-item');
expect(initialItems.length).toBe(30);
await scrollPage(page);
const items = await page.findAll('ion-item');
expect(items.length).toBe(60);
});
});

View File

@ -51,7 +51,7 @@
infiniteScroll.complete();
appendItems();
// Custom event consumed in the e2e tests
document.dispatchEvent(new CustomEvent('ionInfiniteComplete'));
window.dispatchEvent(new CustomEvent('ionInfiniteComplete'));
});
function appendItems() {

View File

@ -0,0 +1,22 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('infinite-scroll: scroll-target', () => {
test.beforeEach(({ skip }) => {
skip.rtl();
skip.mode('ios');
});
test('should load more items when scroll target is scrolled to the bottom', async ({ page }) => {
await page.goto('/src/components/infinite-scroll/test/scroll-target');
const ionInfiniteComplete = await page.spyOnEvent('ionInfiniteComplete');
const content = page.locator('#scroll-target');
const items = page.locator('ion-item');
expect(await items.count()).toBe(30);
await content.evaluate((el: HTMLElement) => (el.scrollTop = el.scrollHeight));
await ionInfiniteComplete.next();
expect(await items.count()).toBe(60);
});
});

View File

@ -1,10 +0,0 @@
import { newE2EPage } from '@stencil/core/testing';
test('infinite-scroll: basic', async () => {
const page = await newE2EPage({
url: '/src/components/infinite-scroll/test/basic?ionic:_testing=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});

View File

@ -47,6 +47,8 @@
await wait(500);
infiniteScroll.complete();
appendItems();
// Custom event consumed in the e2e tests
window.dispatchEvent(new CustomEvent('ionInfiniteComplete'));
console.log('Done');
});

View File

@ -0,0 +1,22 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('infinite-scroll: top', () => {
test.beforeEach(({ skip }) => {
skip.rtl();
skip.mode('ios');
});
test('should load more items when scrolled to the top', async ({ page }) => {
await page.goto('/src/components/infinite-scroll/test/top');
const ionInfiniteComplete = await page.spyOnEvent('ionInfiniteComplete');
const content = page.locator('ion-content');
const items = page.locator('ion-item');
expect(await items.count()).toBe(30);
await content.evaluate((el: HTMLIonContentElement) => el.scrollToTop(0));
await ionInfiniteComplete.next();
expect(await items.count()).toBe(60);
});
});