-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,246 @@ | ||
import { test } from '@affine-test/kit/playwright'; | ||
import { | ||
pasteByKeyboard, | ||
writeTextToClipboard, | ||
} from '@affine-test/kit/utils/keyboard'; | ||
import { openHomePage } from '@affine-test/kit/utils/load-page'; | ||
import { | ||
clickNewPageButton, | ||
createLinkedPage, | ||
waitForEmptyEditor, | ||
} from '@affine-test/kit/utils/page-logic'; | ||
import { expect, type Locator } from '@playwright/test'; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await openHomePage(page); | ||
await clickNewPageButton(page); | ||
await waitForEmptyEditor(page); | ||
}); | ||
|
||
async function notClickable(locator: Locator) { | ||
await expect(locator).toHaveAttribute('disabled', ''); | ||
} | ||
|
||
async function clickable(locator: Locator) { | ||
await expect(locator).not.toHaveAttribute('disabled', ''); | ||
} | ||
|
||
test('not allowed to switch to embed view when linking to the same document', async ({ | ||
page, | ||
}) => { | ||
await page.keyboard.press('Enter'); | ||
|
||
const url0 = new URL(page.url()); | ||
|
||
await writeTextToClipboard(page, url0.toString()); | ||
await pasteByKeyboard(page); | ||
|
||
const switchViewBtn = page.locator('Switch view'); | ||
const linkToInlineBtn = page.getByTestId('link-to-inline'); | ||
const linkToCardBtn = page.getByTestId('link-to-card'); | ||
const linkToEmbedBtn = page.getByTestId('link-to-embed'); | ||
|
||
// Inline | ||
await page.locator('affine-reference').hover(); | ||
await page.waitForTimeout(300); | ||
await switchViewBtn.click(); | ||
Check failure on line 46 in tests/affine-local/e2e/links.spec.ts GitHub Actions / E2E Test (3)links.spec.ts:28:5 › not allowed to switch to embed view when linking to the same document
Check failure on line 46 in tests/affine-local/e2e/links.spec.ts GitHub Actions / E2E Test (3)links.spec.ts:28:5 › not allowed to switch to embed view when linking to the same document
Check failure on line 46 in tests/affine-local/e2e/links.spec.ts GitHub Actions / E2E Test (3)links.spec.ts:28:5 › not allowed to switch to embed view when linking to the same document
Check failure on line 46 in tests/affine-local/e2e/links.spec.ts GitHub Actions / E2E Test (3)links.spec.ts:28:5 › not allowed to switch to embed view when linking to the same document
|
||
|
||
await notClickable(linkToInlineBtn); | ||
await clickable(linkToCardBtn); | ||
await notClickable(linkToEmbedBtn); | ||
|
||
// Switches to card view | ||
await linkToCardBtn.click(); | ||
|
||
// Card | ||
await page.locator('affine-embed-linked-doc-block').click(); | ||
// await switchViewBtn.click(); | ||
|
||
await clickable(linkToInlineBtn); | ||
await notClickable(linkToCardBtn); | ||
await notClickable(linkToEmbedBtn); | ||
}); | ||
|
||
test('not allowed to switch to embed view when linking to block', async ({ | ||
page, | ||
}) => { | ||
await page.keyboard.press('Enter'); | ||
await createLinkedPage(page, 'Test Page'); | ||
|
||
await page.locator('affine-reference').hover(); | ||
}); | ||
|
||
test('allow switching to embed view when linking to the other document without mode', async ({ | ||
page, | ||
}) => { | ||
await page.keyboard.press('Enter'); | ||
await createLinkedPage(page, 'Test Page'); | ||
|
||
const switchViewBtn = page.locator('Switch view'); | ||
const linkToInlineBtn = page.getByTestId('link-to-inline'); | ||
const linkToCardBtn = page.getByTestId('link-to-card'); | ||
const linkToEmbedBtn = page.getByTestId('link-to-embed'); | ||
|
||
// Inline | ||
await page.locator('affine-reference').hover(); | ||
await switchViewBtn.click(); | ||
Check failure on line 86 in tests/affine-local/e2e/links.spec.ts GitHub Actions / E2E Test (3)links.spec.ts:73:5 › allow switching to embed view when linking to the other document without mode
Check failure on line 86 in tests/affine-local/e2e/links.spec.ts GitHub Actions / E2E Test (3)links.spec.ts:73:5 › allow switching to embed view when linking to the other document without mode
Check failure on line 86 in tests/affine-local/e2e/links.spec.ts GitHub Actions / E2E Test (3)links.spec.ts:73:5 › allow switching to embed view when linking to the other document without mode
Check failure on line 86 in tests/affine-local/e2e/links.spec.ts GitHub Actions / E2E Test (3)links.spec.ts:73:5 › allow switching to embed view when linking to the other document without mode
|
||
|
||
await notClickable(linkToInlineBtn); | ||
await clickable(linkToCardBtn); | ||
await clickable(linkToEmbedBtn); | ||
|
||
// Switches to card view | ||
await linkToCardBtn.click(); | ||
|
||
// Card | ||
await page.locator('affine-embed-linked-doc-block').click(); | ||
await switchViewBtn.click(); | ||
|
||
await clickable(linkToInlineBtn); | ||
await notClickable(linkToCardBtn); | ||
await clickable(linkToEmbedBtn); | ||
|
||
// Switches to embed view | ||
await linkToEmbedBtn.click(); | ||
|
||
// Embed | ||
await page.locator('affine-embed-synced-doc-block').click(); | ||
await switchViewBtn.click(); | ||
|
||
await clickable(linkToInlineBtn); | ||
await clickable(linkToCardBtn); | ||
await notClickable(linkToEmbedBtn); | ||
|
||
// Closes | ||
await switchViewBtn.click(); | ||
await expect( | ||
page.locator('.affine-embed-synced-doc-container.page') | ||
).toBeVisible(); | ||
|
||
// Opens in peek view | ||
await page.locator('affine-embed-synced-doc-block').dblclick(); | ||
|
||
const peekViewModel = page.getByTestId('peek-view-modal'); | ||
await expect(peekViewModel).toBeVisible(); | ||
await expect(peekViewModel.locator('page-editor')).toBeVisible(); | ||
await page.keyboard.press('Escape'); | ||
await expect(peekViewModel).not.toBeVisible(); | ||
await page.waitForTimeout(300); | ||
|
||
await page.locator('affine-embed-synced-doc-block').click(); | ||
await switchViewBtn.click(); | ||
|
||
await clickable(linkToInlineBtn); | ||
await clickable(linkToCardBtn); | ||
await notClickable(linkToEmbedBtn); | ||
|
||
// Switches to card view | ||
await linkToCardBtn.click(); | ||
|
||
await page.locator('affine-embed-linked-doc-block').click(); | ||
await switchViewBtn.click(); | ||
|
||
await clickable(linkToInlineBtn); | ||
await notClickable(linkToCardBtn); | ||
await clickable(linkToEmbedBtn); | ||
|
||
// Switches to inline view | ||
await linkToInlineBtn.click(); | ||
|
||
await expect(page.locator('affine-reference')).toBeVisible(); | ||
}); | ||
|
||
test('allow switching to embed view when linking to the other document with mode', async ({ | ||
page, | ||
}) => { | ||
await page.keyboard.press('Enter'); | ||
await createLinkedPage(page, 'Test Page'); | ||
|
||
const switchViewBtn = page.locator('Switch view'); | ||
const linkToInlineBtn = page.getByTestId('link-to-inline'); | ||
const linkToCardBtn = page.getByTestId('link-to-card'); | ||
const linkToEmbedBtn = page.getByTestId('link-to-embed'); | ||
|
||
const url = new URL(page.url()); | ||
url.searchParams.append('mode', 'edgeless'); | ||
|
||
await page.locator('affine-reference').click(); | ||
await page.waitForTimeout(300); | ||
await page.keyboard.press('Enter'); | ||
|
||
await writeTextToClipboard(page, url.toString()); | ||
await pasteByKeyboard(page); | ||
|
||
// Inline | ||
await page.locator('affine-reference').hover(); | ||
await switchViewBtn.click(); | ||
Check failure on line 176 in tests/affine-local/e2e/links.spec.ts GitHub Actions / E2E Test (3)links.spec.ts:153:5 › allow switching to embed view when linking to the other document with mode
Check failure on line 176 in tests/affine-local/e2e/links.spec.ts GitHub Actions / E2E Test (3)links.spec.ts:153:5 › allow switching to embed view when linking to the other document with mode
|
||
|
||
await notClickable(linkToInlineBtn); | ||
await clickable(linkToCardBtn); | ||
await clickable(linkToEmbedBtn); | ||
|
||
// Switches to card view | ||
await linkToCardBtn.click(); | ||
|
||
// Card | ||
await page.locator('affine-embed-linked-doc-block').click(); | ||
await switchViewBtn.click(); | ||
|
||
await clickable(linkToInlineBtn); | ||
await notClickable(linkToCardBtn); | ||
await clickable(linkToEmbedBtn); | ||
|
||
// Switches to embed view | ||
await linkToEmbedBtn.click(); | ||
|
||
// Embed | ||
await page.locator('affine-embed-synced-doc-block').click(); | ||
await switchViewBtn.click(); | ||
|
||
await clickable(linkToInlineBtn); | ||
await clickable(linkToCardBtn); | ||
await notClickable(linkToEmbedBtn); | ||
|
||
// Closes | ||
await switchViewBtn.click(); | ||
await expect( | ||
page.locator('.affine-embed-synced-doc-container.edgeless') | ||
).toBeVisible(); | ||
|
||
// Opens in peek view | ||
await page.locator('affine-embed-synced-doc-block').dblclick(); | ||
|
||
const peekViewModel = page.getByTestId('peek-view-modal'); | ||
await expect(peekViewModel).toBeVisible(); | ||
await expect(peekViewModel.locator('edgeless-editor')).toBeVisible(); | ||
await page.keyboard.press('Escape'); | ||
await expect(peekViewModel).not.toBeVisible(); | ||
await page.waitForTimeout(300); | ||
|
||
await page.locator('affine-embed-synced-doc-block').click(); | ||
await switchViewBtn.click(); | ||
|
||
await clickable(linkToInlineBtn); | ||
await clickable(linkToCardBtn); | ||
await notClickable(linkToEmbedBtn); | ||
|
||
// Switches to card view | ||
await linkToCardBtn.click(); | ||
|
||
await page.locator('affine-embed-linked-doc-block').click(); | ||
await switchViewBtn.click(); | ||
|
||
await clickable(linkToInlineBtn); | ||
await notClickable(linkToCardBtn); | ||
await clickable(linkToEmbedBtn); | ||
|
||
// Switches to inline view | ||
await linkToInlineBtn.click(); | ||
|
||
await page.locator('affine-reference').click(); | ||
|
||
// Checks the url | ||
const url2 = new URL(page.url()); | ||
url2.searchParams.delete('refreshKey'); | ||
expect(url.toJSON()).toStrictEqual(url2.toJSON()); | ||
}); |