From 2d71724678998dec348a0897d3a3c695020bdb77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B3=E5=90=9B=E5=81=A5?= <40288193@qq.com> Date: Thu, 7 Dec 2023 20:23:49 +0800 Subject: [PATCH] docs(image): add container/image's e2e test (#1058) --- .../pc/app/container/basic-usage.spec.js | 49 ++++++++++++++++++- .../app/container/custom-with-height.spec.js | 12 ++++- .../demos/pc/app/image/basic-usage.spec.ts | 11 ++++- .../sites/demos/pc/app/image/events.spec.ts | 4 +- .../pc/app/image/lazy-composition-api.vue | 4 +- .../sites/demos/pc/app/image/lazy.spec.ts | 11 +++-- examples/sites/demos/pc/app/image/lazy.vue | 4 +- .../pc/app/image/preview-in-dialog.spec.ts | 16 +++++- .../sites/demos/pc/app/image/preview.spec.ts | 41 +++++++++++----- .../sites/demos/pc/app/image/slot.spec.ts | 3 ++ 10 files changed, 126 insertions(+), 29 deletions(-) diff --git a/examples/sites/demos/pc/app/container/basic-usage.spec.js b/examples/sites/demos/pc/app/container/basic-usage.spec.js index a71752b5d..a54c1d193 100644 --- a/examples/sites/demos/pc/app/container/basic-usage.spec.js +++ b/examples/sites/demos/pc/app/container/basic-usage.spec.js @@ -2,8 +2,53 @@ import { test, expect } from '@playwright/test' test('基础用法', async ({ page }) => { page.on('pageerror', (exception) => expect(exception).toBeNull()) - await page.goto('container#basic-usage') - const header = page.locator('.pc-demo-container .tiny-container__header') + + const preview = page.locator('.pc-demo-container') + const header = preview.locator('.tiny-container__header') + const aside = preview.locator('.tiny-container__aside') + const main = preview.locator('.tiny-container__main') + const footer = preview.locator('.tiny-container__footer') + const btnCalssic = preview.getByText('经典') + const btnSimple = preview.getByText('简约') + const btnfashion = preview.getByText('时尚') + const btnlegend = preview.getByText('传奇') + + // 默认显示 await expect(header).toHaveText('Header') + await expect(main).toHaveCSS('top', '60px') + await expect(main).toHaveCSS('left', '200px') + await page.waitForTimeout(20) + + // 经典模式 + await btnCalssic.click() + await expect(footer).toHaveText('Footer') + await expect(main).toHaveCSS('top', '60px') + await expect(main).toHaveCSS('bottom', '60px') + await expect(main).toHaveCSS('left', '0px') + await page.waitForTimeout(20) + + // 简约 + await btnSimple.click() + await expect(header).toHaveCount(0) + await expect(main).toHaveCSS('top', '0px') + await expect(main).toHaveCSS('left', '200px') + await page.waitForTimeout(20) + + // 时尚 + await btnfashion.click() + await expect(header).toHaveCount(1) + await expect(header).toHaveCSS('top', '0px') + await expect(header).toHaveCSS('left', '200px') + await expect(main).toHaveCSS('top', '60px') + await expect(main).toHaveCSS('left', '200px') + await page.waitForTimeout(20) + + // 传奇 + await btnlegend.click() + await expect(header).toHaveCount(1) + await expect(main).toHaveCSS('top', '60px') + await expect(main).toHaveCSS('left', '200px') + await expect(aside).toHaveCSS('top', '60px') + await expect(footer).toHaveCSS('left', '200px') }) diff --git a/examples/sites/demos/pc/app/container/custom-with-height.spec.js b/examples/sites/demos/pc/app/container/custom-with-height.spec.js index 254465b57..f62c68c0d 100644 --- a/examples/sites/demos/pc/app/container/custom-with-height.spec.js +++ b/examples/sites/demos/pc/app/container/custom-with-height.spec.js @@ -2,8 +2,16 @@ import { test, expect } from '@playwright/test' test('自定义宽度和高度', async ({ page }) => { page.on('pageerror', (exception) => expect(exception).toBeNull()) - await page.goto('container#custom-with-height') - const header = page.locator('.pc-demo-container .tiny-container__header') + + const preview = page.locator('.pc-demo-container') + const header = preview.locator('.tiny-container__header') + const aside = preview.locator('.tiny-container__aside') + const main = preview.locator('.tiny-container__main') + const footer = preview.locator('.tiny-container__footer') + await expect(header).toHaveCSS('height', '80px') + await expect(aside).toHaveCSS('width', '200px') + await expect(main).toHaveCSS('top', '80px') + await expect(footer).toHaveCSS('height', '80px') }) diff --git a/examples/sites/demos/pc/app/image/basic-usage.spec.ts b/examples/sites/demos/pc/app/image/basic-usage.spec.ts index ad6f58ee3..ec3c37bdf 100644 --- a/examples/sites/demos/pc/app/image/basic-usage.spec.ts +++ b/examples/sites/demos/pc/app/image/basic-usage.spec.ts @@ -4,6 +4,13 @@ test('基础用法', async ({ page }) => { page.on('pageerror', (exception) => expect(exception).toBeNull()) await page.goto('image#basic-usage') - const img = page.locator('.tiny-image > .tiny-image__inner') - await expect(img).toHaveCount(5) + const preview = page.locator('.pc-demo-container') + const imgs = preview.locator('.tiny-image > .tiny-image__inner') + await expect(imgs).toHaveCount(5) + + await expect(imgs.nth(0)).toHaveCSS('object-fit', 'fill') + await expect(imgs.nth(1)).toHaveCSS('object-fit', 'contain') + await expect(imgs.nth(2)).toHaveCSS('object-fit', 'cover') + await expect(imgs.nth(3)).toHaveCSS('object-fit', 'none') + await expect(imgs.nth(4)).toHaveCSS('object-fit', 'scale-down') }) diff --git a/examples/sites/demos/pc/app/image/events.spec.ts b/examples/sites/demos/pc/app/image/events.spec.ts index 25cfc4755..8f6b9da50 100644 --- a/examples/sites/demos/pc/app/image/events.spec.ts +++ b/examples/sites/demos/pc/app/image/events.spec.ts @@ -4,6 +4,8 @@ test('事件', async ({ page }) => { page.on('pageerror', (exception) => expect(exception).toBeNull()) await page.goto('image#events') const errorSlot = page.locator('.tiny-image__error') - await page.waitForTimeout(300) + const eventMsg = page.getByText('加载失败触发事件') + await expect(errorSlot).toHaveCount(1) + await expect(eventMsg).toHaveCount(1) }) diff --git a/examples/sites/demos/pc/app/image/lazy-composition-api.vue b/examples/sites/demos/pc/app/image/lazy-composition-api.vue index 0f2ada76b..900058176 100644 --- a/examples/sites/demos/pc/app/image/lazy-composition-api.vue +++ b/examples/sites/demos/pc/app/image/lazy-composition-api.vue @@ -2,7 +2,7 @@