2023-07-13 12:05:01 +03:00
|
|
|
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
2023-05-09 09:09:39 +03:00
|
|
|
import {
|
2023-09-02 08:57:04 +03:00
|
|
|
clickNewPageButton,
|
2023-05-09 09:09:39 +03:00
|
|
|
getBlockSuiteEditorTitle,
|
2023-09-02 06:31:07 +03:00
|
|
|
waitForEditorLoad,
|
2023-07-13 12:05:01 +03:00
|
|
|
} from '@affine-test/kit/utils/page-logic';
|
|
|
|
import type { Page } from '@playwright/test';
|
|
|
|
import { expect, test } from '@playwright/test';
|
|
|
|
import fs from 'fs';
|
2023-05-09 09:09:39 +03:00
|
|
|
|
2023-05-23 12:35:11 +03:00
|
|
|
async function importImage(page: Page, url: string) {
|
|
|
|
await page.evaluate(
|
|
|
|
([url]) => {
|
|
|
|
const clipData = {
|
2023-07-07 02:24:03 +03:00
|
|
|
'text/html': `<img alt={'Sample image'} src=${url} />`,
|
2023-05-23 12:35:11 +03:00
|
|
|
};
|
|
|
|
const e = new ClipboardEvent('paste', {
|
|
|
|
clipboardData: new DataTransfer(),
|
|
|
|
});
|
|
|
|
Object.defineProperty(e, 'target', {
|
|
|
|
writable: false,
|
2023-08-05 02:55:28 +03:00
|
|
|
value: document,
|
2023-05-23 12:35:11 +03:00
|
|
|
});
|
|
|
|
Object.entries(clipData).forEach(([key, value]) => {
|
|
|
|
e.clipboardData?.setData(key, value);
|
|
|
|
});
|
2023-08-05 02:55:28 +03:00
|
|
|
document.dispatchEvent(e);
|
2023-05-23 12:35:11 +03:00
|
|
|
},
|
|
|
|
[url]
|
|
|
|
);
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function closeImagePreviewModal(page: Page) {
|
|
|
|
await page
|
|
|
|
.getByTestId('image-preview-modal')
|
2023-06-27 16:05:24 +03:00
|
|
|
.getByTestId('image-preview-close-button')
|
2023-05-23 12:35:11 +03:00
|
|
|
.first()
|
|
|
|
.click();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
}
|
|
|
|
|
2023-05-09 09:09:39 +03:00
|
|
|
test('image preview should be shown', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-05-09 09:09:39 +03:00
|
|
|
await page.keyboard.press('Enter');
|
2023-05-23 12:35:11 +03:00
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
2023-05-09 09:09:39 +03:00
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).toBeVisible();
|
2023-05-23 12:35:11 +03:00
|
|
|
await closeImagePreviewModal(page);
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).not.toBeVisible();
|
2023-05-09 09:09:39 +03:00
|
|
|
});
|
2023-05-23 12:35:11 +03:00
|
|
|
|
2023-08-05 02:55:28 +03:00
|
|
|
test('image go left and right', async ({ page }) => {
|
2023-05-23 12:35:11 +03:00
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-05-23 12:35:11 +03:00
|
|
|
let blobId: string;
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-05-23 12:35:11 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
blobId = (await page
|
|
|
|
.locator('img')
|
|
|
|
.nth(1)
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(blobId).toBeTruthy();
|
|
|
|
await closeImagePreviewModal(page);
|
|
|
|
}
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-05-23 12:35:11 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/affine-preview.png');
|
|
|
|
}
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
expect(locator.isVisible()).toBeTruthy();
|
|
|
|
await page.locator('img').first().dblclick();
|
2023-06-27 16:05:24 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-05-23 12:35:11 +03:00
|
|
|
{
|
2023-07-07 02:24:03 +03:00
|
|
|
const newBlobId = (await locator
|
2023-05-23 12:35:11 +03:00
|
|
|
.locator('img[data-blob-id]')
|
|
|
|
.first()
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(newBlobId).not.toBe(blobId);
|
|
|
|
}
|
|
|
|
await page.keyboard.press('ArrowRight');
|
2023-06-27 16:05:24 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-05-23 12:35:11 +03:00
|
|
|
{
|
2023-07-07 02:24:03 +03:00
|
|
|
const newBlobId = (await locator
|
2023-05-23 12:35:11 +03:00
|
|
|
.locator('img[data-blob-id]')
|
|
|
|
.first()
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(newBlobId).toBe(blobId);
|
|
|
|
}
|
|
|
|
});
|
2023-07-07 02:24:03 +03:00
|
|
|
|
|
|
|
test('image able to zoom in and out with mouse scroll', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-07-07 02:24:03 +03:00
|
|
|
let blobId: string;
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
blobId = (await page
|
|
|
|
.locator('img')
|
|
|
|
.nth(1)
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(blobId).toBeTruthy();
|
|
|
|
}
|
|
|
|
const locator = page.getByTestId('image-content');
|
|
|
|
const naturalWidth = await locator.evaluate(
|
|
|
|
(img: HTMLImageElement) => img.naturalWidth
|
|
|
|
);
|
|
|
|
expect(locator.isVisible()).toBeTruthy();
|
|
|
|
const { width, height } = await page.evaluate(() => ({
|
|
|
|
width: window.innerWidth,
|
|
|
|
height: window.innerHeight,
|
|
|
|
}));
|
|
|
|
|
2023-10-12 08:04:58 +03:00
|
|
|
// zoom in
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.mouse.move(width / 2, height / 2);
|
|
|
|
await page.mouse.wheel(0, 100);
|
|
|
|
await page.mouse.wheel(0, 100);
|
|
|
|
await page.mouse.wheel(0, 100);
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
let imageBoundary = await locator.boundingBox();
|
2023-10-12 08:04:58 +03:00
|
|
|
let imageWidth = imageBoundary?.width;
|
2023-07-07 02:24:03 +03:00
|
|
|
if (imageWidth) {
|
|
|
|
expect((imageWidth / naturalWidth).toFixed(2)).toBe('0.54');
|
|
|
|
}
|
|
|
|
|
2023-10-12 08:04:58 +03:00
|
|
|
// zoom in
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.mouse.move(width / 2, height / 2);
|
|
|
|
await page.mouse.wheel(0, -100);
|
|
|
|
await page.mouse.wheel(0, -100);
|
|
|
|
await page.mouse.wheel(0, -100);
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
imageBoundary = await locator.boundingBox();
|
2023-10-12 08:04:58 +03:00
|
|
|
imageWidth = imageBoundary?.width;
|
2023-07-07 02:24:03 +03:00
|
|
|
if (imageWidth) {
|
|
|
|
expect((imageWidth / naturalWidth).toFixed(2)).toBe('0.84');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('image able to zoom in and out with button click', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-07-07 02:24:03 +03:00
|
|
|
let blobId: string;
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
blobId = (await page
|
|
|
|
.locator('img')
|
|
|
|
.nth(1)
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(blobId).toBeTruthy();
|
|
|
|
}
|
|
|
|
const locator = page.getByTestId('image-content');
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).toBeVisible();
|
2023-07-07 02:24:03 +03:00
|
|
|
const naturalWidth = await locator.evaluate(
|
|
|
|
(img: HTMLImageElement) => img.naturalWidth
|
|
|
|
);
|
|
|
|
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
// zoom in
|
|
|
|
{
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
await locator.getByTestId('zoom-in-button').dblclick();
|
|
|
|
}
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
let imageBoundary = await locator.boundingBox();
|
2023-10-12 08:04:58 +03:00
|
|
|
let imageWidth = imageBoundary?.width;
|
2023-07-07 02:24:03 +03:00
|
|
|
if (imageWidth) {
|
|
|
|
expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.04');
|
|
|
|
}
|
|
|
|
|
|
|
|
// zooom out
|
|
|
|
await page.getByTestId('zoom-out-button').dblclick();
|
|
|
|
imageBoundary = await locator.boundingBox();
|
2023-10-12 08:04:58 +03:00
|
|
|
imageWidth = imageBoundary?.width;
|
2023-07-07 02:24:03 +03:00
|
|
|
if (imageWidth) {
|
|
|
|
expect((imageWidth / naturalWidth).toFixed(2)).toBe('0.84');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-05 02:55:28 +03:00
|
|
|
test('image should able to go left and right by buttons', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
let blobId: string;
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.locator('img').first().dblclick();
|
2023-08-05 02:55:28 +03:00
|
|
|
await page.waitForTimeout(500);
|
|
|
|
blobId = (await page
|
|
|
|
.locator('img')
|
|
|
|
.nth(1)
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(blobId).toBeTruthy();
|
|
|
|
await closeImagePreviewModal(page);
|
|
|
|
}
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/affine-preview.png');
|
|
|
|
}
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
await page.locator('img').first().dblclick();
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).toBeVisible();
|
2023-08-05 02:55:28 +03:00
|
|
|
{
|
|
|
|
const newBlobId = (await locator
|
|
|
|
.getByTestId('image-content')
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(newBlobId).not.toBe(blobId);
|
|
|
|
}
|
|
|
|
await locator.getByTestId('next-image-button').click();
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
{
|
|
|
|
const newBlobId = (await page
|
|
|
|
.getByTestId('image-content')
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(newBlobId).toBe(blobId);
|
|
|
|
}
|
|
|
|
await locator.getByTestId('previous-image-button').click();
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
{
|
|
|
|
const newBlobId = (await locator
|
|
|
|
.getByTestId('image-content')
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(newBlobId).not.toBe(blobId);
|
|
|
|
}
|
|
|
|
});
|
2023-07-07 02:24:03 +03:00
|
|
|
|
|
|
|
test('image able to fit to screen by button', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-07-07 02:24:03 +03:00
|
|
|
let blobId: string;
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
blobId = (await page
|
|
|
|
.locator('img')
|
|
|
|
.nth(1)
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(blobId).toBeTruthy();
|
|
|
|
}
|
|
|
|
const locator = page.getByTestId('image-content');
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).toBeVisible();
|
2023-07-07 02:24:03 +03:00
|
|
|
const naturalWidth = await locator.evaluate(
|
|
|
|
(img: HTMLImageElement) => img.naturalWidth
|
|
|
|
);
|
|
|
|
const [viewportWidth, viewportHeight] = await page.evaluate(() => {
|
|
|
|
return [window.innerWidth, window.innerHeight];
|
|
|
|
});
|
|
|
|
|
|
|
|
// zooom in
|
|
|
|
{
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
await locator.getByTestId('zoom-in-button').dblclick();
|
|
|
|
}
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
let imageBoundary = await locator.boundingBox();
|
2023-10-12 08:04:58 +03:00
|
|
|
let imageWidth = imageBoundary?.width;
|
2023-07-07 02:24:03 +03:00
|
|
|
if (imageWidth) {
|
|
|
|
expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.04');
|
|
|
|
} else {
|
|
|
|
throw new Error("Image doesn't exist!");
|
|
|
|
}
|
|
|
|
|
|
|
|
//reset zoom
|
|
|
|
{
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
await locator.getByTestId('fit-to-screen-button').click();
|
|
|
|
}
|
|
|
|
imageBoundary = await locator.boundingBox();
|
2023-10-12 08:04:58 +03:00
|
|
|
imageWidth = imageBoundary?.width;
|
|
|
|
const imageHeight = imageBoundary?.height;
|
2023-07-07 02:24:03 +03:00
|
|
|
if (imageWidth && imageHeight) {
|
|
|
|
expect(imageWidth).toBeLessThan(viewportWidth);
|
|
|
|
expect(imageHeight).toBeLessThan(viewportHeight);
|
|
|
|
} else {
|
|
|
|
throw new Error("Image doesn't exist!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('image able to reset zoom to 100%', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-07-07 02:24:03 +03:00
|
|
|
let blobId: string;
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
blobId = (await page
|
|
|
|
.locator('img')
|
|
|
|
.nth(1)
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(blobId).toBeTruthy();
|
|
|
|
}
|
|
|
|
const locator = page.getByTestId('image-content');
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).toBeVisible();
|
2023-07-07 02:24:03 +03:00
|
|
|
const naturalWidth = await locator.evaluate(
|
|
|
|
(img: HTMLImageElement) => img.naturalWidth
|
|
|
|
);
|
|
|
|
|
|
|
|
await page.waitForTimeout(500);
|
2023-10-12 08:04:58 +03:00
|
|
|
// zoom in
|
2023-07-07 02:24:03 +03:00
|
|
|
{
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
await locator.getByTestId('zoom-in-button').dblclick();
|
|
|
|
}
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
let imageBoundary = await locator.boundingBox();
|
2023-10-12 08:04:58 +03:00
|
|
|
let imageWidth = imageBoundary?.width;
|
2023-07-07 02:24:03 +03:00
|
|
|
if (imageWidth) {
|
|
|
|
expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.04');
|
|
|
|
} else {
|
|
|
|
throw new Error("Image doesn't exist!");
|
|
|
|
}
|
|
|
|
|
|
|
|
//reset zoom
|
|
|
|
{
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
await locator.getByTestId('reset-scale-button').click();
|
|
|
|
}
|
|
|
|
imageBoundary = await locator.boundingBox();
|
2023-10-12 08:04:58 +03:00
|
|
|
imageWidth = imageBoundary?.width;
|
2023-07-07 02:24:03 +03:00
|
|
|
if (imageWidth) {
|
|
|
|
expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.00');
|
|
|
|
} else {
|
|
|
|
throw new Error("Image doesn't exist!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('image able to copy to clipboard', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-07-07 02:24:03 +03:00
|
|
|
let blobId: string;
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
blobId = (await page
|
|
|
|
.locator('img')
|
|
|
|
.nth(1)
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(blobId).toBeTruthy();
|
|
|
|
}
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).toBeVisible();
|
2023-07-07 02:24:03 +03:00
|
|
|
await locator.getByTestId('copy-to-clipboard-button').click();
|
2023-10-12 08:04:58 +03:00
|
|
|
await new Promise<void>(resolve => {
|
|
|
|
page.on('console', message => {
|
|
|
|
expect(message.text()).toBe('Image copied to clipboard');
|
|
|
|
resolve();
|
|
|
|
});
|
2023-07-07 02:24:03 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('image able to download', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-07-07 02:24:03 +03:00
|
|
|
let blobId: string;
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
blobId = (await page
|
|
|
|
.locator('img')
|
|
|
|
.nth(1)
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(blobId).toBeTruthy();
|
|
|
|
}
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).toBeVisible();
|
2023-07-07 02:24:03 +03:00
|
|
|
const downloadPromise = page.waitForEvent('download');
|
|
|
|
await locator.getByTestId('download-button').click();
|
|
|
|
const download = await downloadPromise;
|
2023-09-28 05:53:04 +03:00
|
|
|
const name = download.suggestedFilename();
|
|
|
|
await download.saveAs(`download/ + ${name}`);
|
|
|
|
expect(fs.existsSync(`download/ + ${name}`)).toBeTruthy();
|
2023-07-07 02:24:03 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('image should only able to move when image is larger than viewport', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-07-07 02:24:03 +03:00
|
|
|
let blobId: string;
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
blobId = (await page
|
|
|
|
.locator('img')
|
|
|
|
.nth(1)
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(blobId).toBeTruthy();
|
|
|
|
}
|
|
|
|
const locator = page.getByTestId('image-content');
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).toBeVisible();
|
2023-07-07 02:24:03 +03:00
|
|
|
const { width, height } = await page.evaluate(() => ({
|
|
|
|
width: window.innerWidth,
|
|
|
|
height: window.innerHeight,
|
|
|
|
}));
|
|
|
|
let imageBoundary = await locator.boundingBox();
|
|
|
|
const initialXPos = imageBoundary?.x;
|
|
|
|
const initialYPos = imageBoundary?.y;
|
2023-10-12 08:04:58 +03:00
|
|
|
// check will it be able to move when zoomed in
|
2023-07-07 02:24:03 +03:00
|
|
|
{
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
await locator.getByTestId('zoom-in-button').dblclick();
|
|
|
|
await locator.getByTestId('zoom-in-button').dblclick();
|
|
|
|
}
|
|
|
|
await page.mouse.move(width / 2, height / 2);
|
|
|
|
await page.mouse.down();
|
|
|
|
await page.mouse.move(20, 20);
|
|
|
|
await page.mouse.up();
|
|
|
|
imageBoundary = await locator.boundingBox();
|
|
|
|
expect(initialXPos).not.toBe(imageBoundary?.x);
|
|
|
|
expect(initialYPos).not.toBe(imageBoundary?.y);
|
|
|
|
|
2023-10-12 08:04:58 +03:00
|
|
|
// check will it be able to move when zoomed out
|
2023-07-07 02:24:03 +03:00
|
|
|
{
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
await locator.getByTestId('fit-to-screen-button').click();
|
|
|
|
}
|
|
|
|
await page.mouse.move(width / 2, height / 2);
|
|
|
|
await page.mouse.down();
|
|
|
|
await page.mouse.move(20, 20);
|
|
|
|
await page.mouse.up();
|
|
|
|
imageBoundary = await locator.boundingBox();
|
|
|
|
expect(initialXPos).toBe(imageBoundary?.x);
|
|
|
|
expect(initialYPos).toBe(imageBoundary?.y);
|
|
|
|
});
|
|
|
|
|
2023-08-05 02:55:28 +03:00
|
|
|
test('image should able to delete and when delete, it will move to previous/next image', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
let blobId: string;
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
2023-07-29 05:53:29 +03:00
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
await page.waitForTimeout(500);
|
2023-08-05 02:55:28 +03:00
|
|
|
blobId = (await page
|
|
|
|
.locator('img')
|
|
|
|
.nth(1)
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(blobId).toBeTruthy();
|
|
|
|
await closeImagePreviewModal(page);
|
2023-07-07 02:24:03 +03:00
|
|
|
}
|
2023-08-05 02:55:28 +03:00
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/affine-preview.png');
|
|
|
|
}
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
await page.locator('img').first().dblclick();
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).toBeVisible();
|
2023-08-05 02:55:28 +03:00
|
|
|
// ensure the new image was imported
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
{
|
|
|
|
const newBlobId = (await locator
|
|
|
|
.getByTestId('image-content')
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(newBlobId).not.toBe(blobId);
|
|
|
|
}
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
await locator.getByTestId('delete-button').click();
|
|
|
|
{
|
|
|
|
const newBlobId = (await locator
|
|
|
|
.getByTestId('image-content')
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(newBlobId).toBe(blobId);
|
|
|
|
await closeImagePreviewModal(page);
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/affine-preview.png');
|
|
|
|
}
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
await locator.getByTestId('next-image-button').click();
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
{
|
|
|
|
const newBlobId = (await page
|
|
|
|
.getByTestId('image-content')
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(newBlobId).toBe(blobId);
|
|
|
|
}
|
|
|
|
await locator.getByTestId('delete-button').click();
|
|
|
|
{
|
|
|
|
const newBlobId = (await locator
|
|
|
|
.getByTestId('image-content')
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(newBlobId).not.toBe(blobId);
|
|
|
|
}
|
|
|
|
await locator.getByTestId('delete-button').click();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
{
|
|
|
|
const locator = await page.getByTestId('image-preview-modal').count();
|
|
|
|
expect(locator).toBe(0);
|
|
|
|
}
|
|
|
|
});
|
2023-07-07 02:24:03 +03:00
|
|
|
|
|
|
|
test('tooltips for all buttons should be visible when hovering', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-07-07 02:24:03 +03:00
|
|
|
let blobId: string;
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
blobId = (await page
|
|
|
|
.locator('img')
|
|
|
|
.nth(1)
|
|
|
|
.getAttribute('data-blob-id')) as string;
|
|
|
|
expect(blobId).toBeTruthy();
|
|
|
|
}
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
await locator.getByTestId('previous-image-button').hover();
|
2023-08-05 02:55:28 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-07-07 02:24:03 +03:00
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const element = page.getByRole('tooltip');
|
2023-07-07 02:24:03 +03:00
|
|
|
const previousImageTooltip = await element.getByText('Previous').count();
|
|
|
|
expect(previousImageTooltip).toBe(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
await locator.getByTestId('next-image-button').hover();
|
2023-08-05 02:55:28 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-07-07 02:24:03 +03:00
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const element = page.getByRole('tooltip');
|
2023-07-07 02:24:03 +03:00
|
|
|
const nextImageTooltip = await element.getByText('Next').count();
|
|
|
|
expect(nextImageTooltip).toBe(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
await locator.getByTestId('fit-to-screen-button').hover();
|
2023-08-05 02:55:28 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-07-07 02:24:03 +03:00
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const element = page.getByRole('tooltip');
|
2023-07-07 02:24:03 +03:00
|
|
|
const fitToScreenToolTip = await element.getByText('Fit to Screen').count();
|
|
|
|
expect(fitToScreenToolTip).toBe(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
await locator.getByTestId('zoom-out-button').hover();
|
2023-08-05 02:55:28 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-07-07 02:24:03 +03:00
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const element = page.getByRole('tooltip');
|
2023-07-07 02:24:03 +03:00
|
|
|
const zoomOutToolTip = await element.getByText('Zoom out').count();
|
|
|
|
expect(zoomOutToolTip).toBe(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
await locator.getByTestId('reset-scale-button').hover();
|
2023-08-05 02:55:28 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-07-07 02:24:03 +03:00
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const element = page.getByRole('tooltip');
|
2023-07-07 02:24:03 +03:00
|
|
|
const resetScaleTooltip = await element.getByText('Reset Scale').count();
|
|
|
|
expect(resetScaleTooltip).toBe(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
await locator.getByTestId('zoom-in-button').hover();
|
2023-08-05 02:55:28 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-07-07 02:24:03 +03:00
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const element = page.getByRole('tooltip');
|
2023-07-07 02:24:03 +03:00
|
|
|
const zoominToolTip = await element.getByText('Zoom in').count();
|
|
|
|
expect(zoominToolTip).toBe(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
await locator.getByTestId('download-button').hover();
|
2023-08-17 01:18:43 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-07-07 02:24:03 +03:00
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const element = page.getByRole('tooltip');
|
2023-07-07 02:24:03 +03:00
|
|
|
const downloadTooltip = await element.getByText('Download').count();
|
|
|
|
expect(downloadTooltip).toBe(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
await locator.getByTestId('copy-to-clipboard-button').hover();
|
2023-08-05 02:55:28 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-07-07 02:24:03 +03:00
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const element = page.getByRole('tooltip');
|
2023-07-07 02:24:03 +03:00
|
|
|
const downloadTooltip = await element
|
|
|
|
.getByText('Copy to clipboard')
|
|
|
|
.count();
|
|
|
|
expect(downloadTooltip).toBe(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
await locator.getByTestId('delete-button').hover();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
{
|
2023-10-12 08:04:58 +03:00
|
|
|
const element = page.getByRole('tooltip');
|
2023-07-07 02:24:03 +03:00
|
|
|
const downloadTooltip = await element.getByText('Delete').count();
|
|
|
|
expect(downloadTooltip).toBe(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('keypress esc should close the modal', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
expect(locator.isVisible()).toBeTruthy();
|
|
|
|
await page.keyboard.press('Escape');
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
expect(await locator.isVisible()).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when mouse moves outside, the modal should be closed', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).toBeVisible();
|
2023-07-07 02:24:03 +03:00
|
|
|
// animation delay
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
await page.mouse.click(10, 10);
|
|
|
|
await page.waitForTimeout(1000);
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(locator).not.toBeVisible();
|
2023-07-07 02:24:03 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('caption should be visible and different styles were applied if image zoomed larger than viewport', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
const sampleCaption = 'affine owns me and all';
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-10-12 08:04:58 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-08-05 02:55:28 +03:00
|
|
|
await title.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
|
|
|
await page.locator('img').first().hover();
|
2023-08-08 06:01:47 +03:00
|
|
|
await page
|
|
|
|
.locator('.embed-editing-state')
|
|
|
|
.locator('icon-button')
|
2023-08-10 07:19:24 +03:00
|
|
|
.nth(1)
|
2023-08-08 06:01:47 +03:00
|
|
|
.click();
|
2023-07-07 02:24:03 +03:00
|
|
|
await page.getByPlaceholder('Write a caption').fill(sampleCaption);
|
|
|
|
await page.locator('img').first().dblclick();
|
|
|
|
const locator = page.getByTestId('image-preview-modal');
|
|
|
|
expect(await locator.isVisible()).toBeTruthy();
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
let captionLocator = locator.getByTestId('image-caption-zoomedout');
|
|
|
|
await expect(captionLocator).toBeVisible();
|
|
|
|
expect(await captionLocator.innerText()).toBe(sampleCaption);
|
|
|
|
await page.getByTestId('zoom-in-button').click({ clickCount: 4 });
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(captionLocator).not.toBeVisible();
|
2023-07-07 02:24:03 +03:00
|
|
|
captionLocator = locator.getByTestId('image-caption-zoomedin');
|
2023-10-12 08:04:58 +03:00
|
|
|
await expect(captionLocator).toBeVisible();
|
2023-07-07 02:24:03 +03:00
|
|
|
expect(await captionLocator.innerText()).toBe(sampleCaption);
|
|
|
|
});
|