mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2025-09-04 00:20:39 +00:00
Testing (#44)
* testing * try playwrigth * testing * add pr support * not on each commit * add test ids * make backend more configuratble * 2.0.2 * spec
This commit is contained in:
BIN
test/assets/AES.pdf
(Stored with Git LFS)
Normal file
BIN
test/assets/AES.pdf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
test/assets/Pigeons.zip
(Stored with Git LFS)
Normal file
BIN
test/assets/Pigeons.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
test/assets/alfred-kenneally-UIu4RmMxnHU-unsplash.jpg
(Stored with Git LFS)
Normal file
BIN
test/assets/alfred-kenneally-UIu4RmMxnHU-unsplash.jpg
(Stored with Git LFS)
Normal file
Binary file not shown.
5
test/file/files.ts
Normal file
5
test/file/files.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export default {
|
||||
PDF: 'test/assets/AES.pdf',
|
||||
Image: 'test/assets/alfred-kenneally-UIu4RmMxnHU-unsplash.jpg',
|
||||
Zip: 'test/assets/Pigeons.zip',
|
||||
}
|
11
test/file/multiple.spec.ts
Normal file
11
test/file/multiple.spec.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkForDownload, createNote, getFileChecksum } from '../utils'
|
||||
import Files from './files'
|
||||
|
||||
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 })
|
||||
await checkLinkForDownload(page, link, 'alfred-kenneally', checksums[1])
|
||||
await checkLinkForDownload(page, link, 'AES.pdf', checksums[0])
|
||||
})
|
24
test/file/simple.spec.ts
Normal file
24
test/file/simple.spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkDoesNotExist, checkLinkForDownload, checkLinkForText, createNote, getFileChecksum } from '../utils'
|
||||
import Files from './files'
|
||||
|
||||
test('simple pdf', async ({ page }) => {
|
||||
const files = [Files.PDF]
|
||||
const link = await createNote(page, { files })
|
||||
await checkLinkForText(page, link, 'AES.pdf')
|
||||
await checkLinkDoesNotExist(page, link)
|
||||
})
|
||||
|
||||
test('pdf content', async ({ page }) => {
|
||||
const files = [Files.PDF]
|
||||
const checksum = await getFileChecksum(files[0])
|
||||
const link = await createNote(page, { files })
|
||||
await checkLinkForDownload(page, link, 'AES.pdf', checksum)
|
||||
})
|
||||
|
||||
test('image content', async ({ page }) => {
|
||||
const files = [Files.Image]
|
||||
const checksum = await getFileChecksum(files[0])
|
||||
const link = await createNote(page, { files })
|
||||
await checkLinkForDownload(page, link, 'alfred-kenneally', checksum)
|
||||
})
|
14
test/text/expiration.spec.ts
Normal file
14
test/text/expiration.spec.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkDoesNotExist, checkLinkForText, createNote } from '../utils'
|
||||
|
||||
test('1 minute', async ({ page }) => {
|
||||
const text = `Virtues value ascetic revaluation sea dead strong burying.`
|
||||
const minutes = 1
|
||||
const timeout = minutes * 60_000
|
||||
test.setTimeout(timeout * 2)
|
||||
const shareLink = await createNote(page, { text, expiration: minutes })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await page.waitForTimeout(timeout)
|
||||
await checkLinkDoesNotExist(page, shareLink)
|
||||
})
|
8
test/text/simple.spec.ts
Normal file
8
test/text/simple.spec.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkForText, createNote } from '../utils'
|
||||
|
||||
test('simple', async ({ page }) => {
|
||||
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 shareLink = await createNote(page, { text })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
})
|
18
test/text/views.spec.ts
Normal file
18
test/text/views.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkDoesNotExist, checkLinkForText, createNote } from '../utils'
|
||||
|
||||
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 shareLink = await createNote(page, { text })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkDoesNotExist(page, shareLink)
|
||||
})
|
||||
|
||||
test('view 3 times', async ({ page }) => {
|
||||
const text = `Justice holiest overcome fearful strong ultimate holiest christianity.`
|
||||
const shareLink = await createNote(page, { text, views: 3 })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkDoesNotExist(page, shareLink)
|
||||
})
|
71
test/utils.ts
Normal file
71
test/utils.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { expect, type Page } from '@playwright/test'
|
||||
import { createHash } from 'crypto'
|
||||
import { readFile } from 'fs/promises'
|
||||
|
||||
type CreatePage = { text?: string; files?: string[]; views?: number; expiration?: number; error?: string }
|
||||
export async function createNote(page: Page, options: CreatePage): Promise<string> {
|
||||
await page.goto('/')
|
||||
|
||||
if (options.text) {
|
||||
await page.locator('[data-testid="text-field"]').fill(options.text)
|
||||
} else if (options.files) {
|
||||
await page.locator('[data-testid="switch-file"]').click()
|
||||
|
||||
const [fileChooser] = await Promise.all([
|
||||
page.waitForEvent('filechooser'),
|
||||
page.locator('text=No Files Selected').click(),
|
||||
])
|
||||
await fileChooser.setFiles(options.files)
|
||||
}
|
||||
|
||||
if (options.views) {
|
||||
await page.locator('[data-testid="switch-advanced"]').click()
|
||||
await page.locator('[data-testid="field-views"]').fill(options.views.toString())
|
||||
} else if (options.expiration) {
|
||||
await page.locator('[data-testid="switch-advanced"]').click()
|
||||
await page.locator('[data-testid="switch-advanced-toggle"]').click()
|
||||
await page.locator('[data-testid="field-expiration"]').fill(options.expiration.toString())
|
||||
}
|
||||
|
||||
await page.locator('button:has-text("create")').click()
|
||||
|
||||
if (options.error) {
|
||||
await expect(page.locator('.error-text')).toContainText(options.error, { timeout: 60_000 })
|
||||
}
|
||||
|
||||
const shareLink = await page.locator('[data-testid="share-link"]').inputValue()
|
||||
return shareLink
|
||||
}
|
||||
|
||||
export async function checkLinkForDownload(page: Page, link: string, text: string, checksum: string) {
|
||||
await page.goto('/')
|
||||
await page.goto(link)
|
||||
await page.locator('[data-testid="show-note-button"]').click()
|
||||
|
||||
const [download] = await Promise.all([
|
||||
page.waitForEvent('download'),
|
||||
page.locator(`[data-testid="result"] >> text=${text}`).click(),
|
||||
])
|
||||
const path = await download.path()
|
||||
if (!path) throw new Error('Download failed')
|
||||
const cs = await getFileChecksum(path)
|
||||
await expect(cs).toBe(checksum)
|
||||
}
|
||||
export async function checkLinkForText(page: Page, link: string, text: string) {
|
||||
await page.goto('/')
|
||||
await page.goto(link)
|
||||
await page.locator('[data-testid="show-note-button"]').click()
|
||||
await expect(await page.locator('[data-testid="result"] >> .note').innerText()).toContain(text)
|
||||
}
|
||||
|
||||
export async function checkLinkDoesNotExist(page: Page, link: string) {
|
||||
await page.goto('/') // Required due to firefox: https://github.com/microsoft/playwright/issues/15781
|
||||
await page.goto(link)
|
||||
await expect(page.locator('main')).toContainText('note was not found or was already deleted')
|
||||
}
|
||||
|
||||
export async function getFileChecksum(file: string) {
|
||||
const buffer = await readFile(file)
|
||||
const hash = createHash('sha3-256').update(buffer).digest('hex')
|
||||
return hash
|
||||
}
|
Reference in New Issue
Block a user