diff --git a/test/cross/file/simple.spec.ts b/test/cross/file/simple.spec.ts index 103d29c..252b7a6 100644 --- a/test/cross/file/simple.spec.ts +++ b/test/cross/file/simple.spec.ts @@ -1,7 +1,8 @@ import { test } from '@playwright/test' -import { CLI, checkLinkForDownload, checkLinkForText, createNote, getLinkFromCLI } from '../../utils' -import { Files, getFileChecksum, rm, tmpFile } from '../../files' -import { basename } from 'path' +import { rm } from 'node:fs/promises' +import { basename } from 'node:path' +import { Files, getFileChecksum, tmpFile } from '../../files' +import { CLI, checkLinkForDownload, createNoteSuccessfully, getLinkFromCLI } from '../../utils' const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.` const password = 'password' @@ -30,7 +31,7 @@ test.describe('text @cross', () => { test('web to cli', async ({ page }) => { const files = [Files.Image] const checksum = await getFileChecksum(files[0]) - const link = await createNote(page, { files }) + const link = await createNoteSuccessfully(page, { files }) const filename = basename(files[0]) await CLI('open', link, '--all') @@ -42,7 +43,7 @@ test.describe('text @cross', () => { test('web to cli with password', async ({ page }) => { const files = [Files.Image] const checksum = await getFileChecksum(files[0]) - const link = await createNote(page, { files, password }) + const link = await createNoteSuccessfully(page, { files, password }) const filename = basename(files[0]) await CLI('open', link, '--all', '--password', password) diff --git a/test/cross/text/simple.spec.ts b/test/cross/text/simple.spec.ts index 02f52e6..4c3bf16 100644 --- a/test/cross/text/simple.spec.ts +++ b/test/cross/text/simple.spec.ts @@ -1,5 +1,5 @@ import { test } from '@playwright/test' -import { CLI, checkLinkForText, createNote, getLinkFromCLI } from '../../utils' +import { CLI, checkLinkForText, createNoteSuccessfully, getLinkFromCLI } from '../../utils' const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.` const password = 'password' @@ -13,7 +13,7 @@ test.describe('text @cross', () => { }) test('web to cli', async ({ page }) => { - const link = await createNote(page, { text }) + const link = await createNoteSuccessfully(page, { text }) const retrieved = await CLI('open', link) test.expect(retrieved.stdout.trim()).toBe(text) }) @@ -25,7 +25,7 @@ test.describe('text @cross', () => { }) test('web to cli with password', async ({ page }) => { - const link = await createNote(page, { text, password }) + const link = await createNoteSuccessfully(page, { text, password }) const retrieved = await CLI('open', link, '--password', password) test.expect(retrieved.stdout.trim()).toBe(text) }) diff --git a/test/utils.ts b/test/utils.ts index 4292510..a18ed27 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -6,17 +6,22 @@ import { getFileChecksum } from './files' const exec = promisify(execFile) type CreatePage = { - text?: string - files?: string[] views?: number expiration?: number error?: string password?: string -} -export async function createNote(page: Page, options: CreatePage): Promise { +} & ( + | { + text: string + } + | { + files: string[] + } +) +async function createNote(page: Page, options: CreatePage): Promise { await page.goto('/') - if (options.text) { + if ('text' in options) { await page.getByTestId('text-field').fill(options.text) } else if (options.files) { await page.getByTestId('switch-file').click() @@ -31,7 +36,8 @@ export async function createNote(page: Page, options: CreatePage): Promise { + await createNote(page, options) return await page.getByTestId('share-link').inputValue() } +export async function createNoteError(page: Page, options: CreatePage, error: string): Promise { + await createNote(page, options) + await expect(page.locator('._toastContainer')).toContainText(error) +} + type CheckLinkBase = { link: string text: string @@ -69,7 +78,7 @@ export async function checkLinkForDownload(page: Page, options: CheckLinkBase & const path = await download.path() if (!path) throw new Error('Download failed') const cs = await getFileChecksum(path) - await expect(cs).toBe(options.checksum) + expect(cs).toBe(options.checksum) } export async function checkLinkForText(page: Page, options: CheckLinkBase) { @@ -78,7 +87,7 @@ export async function checkLinkForText(page: Page, options: CheckLinkBase) { if (options.password) await page.getByTestId('show-note-password').fill(options.password) await page.getByTestId('show-note-button').click() const text = await page.getByTestId('result').locator('.note').innerText() - await expect(text).toContain(options.text) + expect(text).toContain(options.text) } export async function checkLinkDoesNotExist(page: Page, link: string) { diff --git a/test/web/file/multiple.spec.ts b/test/web/file/multiple.spec.ts index fea086d..3997098 100644 --- a/test/web/file/multiple.spec.ts +++ b/test/web/file/multiple.spec.ts @@ -1,12 +1,12 @@ import { test } from '@playwright/test' import { Files, getFileChecksum } from '../../files' -import { checkLinkForDownload, createNote } from '../../utils' +import { checkLinkForDownload, createNoteSuccessfully } from '../../utils' test.describe('@web', () => { test('multiple', async ({ page }) => { const files = [Files.PDF, Files.Image] const checksums = await Promise.all(files.map(getFileChecksum)) - const link = await createNote(page, { files, views: 2 }) + const link = await createNoteSuccessfully(page, { files, views: 2 }) await checkLinkForDownload(page, { link, text: 'image.jpg', checksum: checksums[1] }) await checkLinkForDownload(page, { link, text: 'AES.pdf', checksum: checksums[0] }) }) diff --git a/test/web/file/simple.spec.ts b/test/web/file/simple.spec.ts index 00a600d..92d6d03 100644 --- a/test/web/file/simple.spec.ts +++ b/test/web/file/simple.spec.ts @@ -1,11 +1,11 @@ import { test } from '@playwright/test' import { Files, getFileChecksum } from '../../files' -import { checkLinkDoesNotExist, checkLinkForDownload, checkLinkForText, createNote } from '../../utils' +import { checkLinkDoesNotExist, checkLinkForDownload, checkLinkForText, createNoteSuccessfully } from '../../utils' test.describe('@web', () => { test('simple pdf', async ({ page }) => { const files = [Files.PDF] - const link = await createNote(page, { files }) + const link = await createNoteSuccessfully(page, { files }) await checkLinkForText(page, { link, text: 'AES.pdf' }) await checkLinkDoesNotExist(page, link) }) @@ -13,21 +13,21 @@ test.describe('@web', () => { test('pdf content', async ({ page }) => { const files = [Files.PDF] const checksum = await getFileChecksum(files[0]) - const link = await createNote(page, { files }) + const link = await createNoteSuccessfully(page, { files }) await checkLinkForDownload(page, { link, text: 'AES.pdf', checksum }) }) test('image content', async ({ page }) => { const files = [Files.Image] const checksum = await getFileChecksum(files[0]) - const link = await createNote(page, { files }) + const link = await createNoteSuccessfully(page, { files }) await checkLinkForDownload(page, { link, text: 'image.jpg', checksum }) }) test('simple pdf with password', async ({ page }) => { const files = [Files.PDF] const password = 'password' - const link = await createNote(page, { files, password }) + const link = await createNoteSuccessfully(page, { files, password }) await checkLinkForText(page, { link, text: 'AES.pdf', password }) await checkLinkDoesNotExist(page, link) }) diff --git a/test/web/file/too-big.spec.ts b/test/web/file/too-big.spec.ts index f677d55..e24e505 100644 --- a/test/web/file/too-big.spec.ts +++ b/test/web/file/too-big.spec.ts @@ -1,10 +1,10 @@ import { test } from '@playwright/test' -import { createNote } from '../../utils' import { Files } from '../../files' +import { createNoteError } from '../../utils' test.describe('@web', () => { test('to big zip', async ({ page }) => { const files = [Files.Zip] - await createNote(page, { files, error: 'note is to big' }) + await createNoteError(page, { files }, 'note is to big') }) }) diff --git a/test/web/text/expiration.spec.ts b/test/web/text/expiration.spec.ts index 6ff3e4d..e26a0ea 100644 --- a/test/web/text/expiration.spec.ts +++ b/test/web/text/expiration.spec.ts @@ -1,5 +1,5 @@ import { test } from '@playwright/test' -import { checkLinkDoesNotExist, checkLinkForText, createNote } from '../../utils' +import { checkLinkDoesNotExist, checkLinkForText, createNoteSuccessfully } from '../../utils' test.describe('@web', () => { test('1 minute', async ({ page }) => { @@ -7,7 +7,7 @@ test.describe('@web', () => { const minutes = 1 const timeout = minutes * 60_000 test.setTimeout(timeout * 2) - const link = await createNote(page, { text, expiration: minutes }) + const link = await createNoteSuccessfully(page, { text, expiration: minutes }) await checkLinkForText(page, { link, text }) await checkLinkForText(page, { link, text }) await page.waitForTimeout(timeout) diff --git a/test/web/text/simple.spec.ts b/test/web/text/simple.spec.ts index ef144c2..18940ba 100644 --- a/test/web/text/simple.spec.ts +++ b/test/web/text/simple.spec.ts @@ -1,17 +1,17 @@ import { test } from '@playwright/test' -import { checkLinkForText, createNote } from '../../utils' +import { checkLinkForText, createNoteSuccessfully } from '../../utils' test.describe('@web', () => { test('simple', async ({ page }) => { const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of deceive play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.` - const link = await createNote(page, { text }) + const link = await createNoteSuccessfully(page, { text }) await checkLinkForText(page, { link, text }) }) test('simple with password', async ({ page }) => { const text = 'Foo bar' const password = '123' - const shareLink = await createNote(page, { text, password }) + const shareLink = await createNoteSuccessfully(page, { text, password }) await checkLinkForText(page, { link: shareLink, text, password }) }) }) diff --git a/test/web/text/views.spec.ts b/test/web/text/views.spec.ts index 48a9c98..b2e75b3 100644 --- a/test/web/text/views.spec.ts +++ b/test/web/text/views.spec.ts @@ -1,17 +1,17 @@ import { test } from '@playwright/test' -import { checkLinkDoesNotExist, checkLinkForText, createNote } from '../../utils' +import { checkLinkDoesNotExist, checkLinkForText, createNoteSuccessfully } from '../../utils' test.describe('@web', () => { test('only shown once', async ({ page }) => { const text = `Christian victorious reason suicide dead. Right ultimate gains god hope truth burying selfish society joy. Ultimate.` - const link = await createNote(page, { text }) + const link = await createNoteSuccessfully(page, { text }) await checkLinkForText(page, { link, text }) await checkLinkDoesNotExist(page, link) }) test('view 3 times', async ({ page }) => { const text = `Justice holiest overcome fearful strong ultimate holiest christianity.` - const link = await createNote(page, { text, views: 3 }) + const link = await createNoteSuccessfully(page, { text, views: 3 }) await checkLinkForText(page, { link, text }) await checkLinkForText(page, { link, text }) await checkLinkForText(page, { link, text })