Skip to content

Commit

Permalink
Add landing page test
Browse files Browse the repository at this point in the history
  • Loading branch information
yunusefendi52 committed Nov 10, 2024
1 parent 6f08f1d commit 1318c0f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ coverage
.wrangler/tmp
server/prisma-client/
prisma/app.db*
test-results/
test-results/
playwright/.auth
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"drizzle:generate": "drizzle-kit generate",
"drizzle:migrate": "bun run server/db/migrate.ts",
"deploy": "bun run build --preset=cloudflare-pages && npx wrangler pages deploy dist/",
"e2e": "playwright test",
"e2e": "NODE_OPTIONS=--require=dotenv/config playwright test",
"tests": "vitest test",
"build-cli": "bun build cli/cli.ts --target node > cli/cli.mjs"
},
Expand Down Expand Up @@ -60,6 +60,7 @@
"@vue/test-utils": "^2.4.6",
"autoprefixer": "^10.4.19",
"bun-types": "^1.1.30",
"dotenv": "^16.4.5",
"drizzle-kit": "^0.27.1",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
Expand Down
23 changes: 3 additions & 20 deletions playwright.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,18 @@ import type { ConfigOptions } from '@nuxt/test-utils/playwright'
export default defineConfig<ConfigOptions>({
use: {
nuxt: {
host: 'http://localhost:3000'
host: process.env.TEST_APP_URL!,
},
},
testDir: './tests-e2e',
projects: [
// {
// name: 'Setup global',
// testMatch: /global\.setup\.mts/,
// },
{ name: 'Setup', testMatch: '**/*.setup.mts' },
{
name: 'Chromium',
use: {
...devices['Desktop Chrome'],
storageState: {
cookies: [{
name: 'app-auth',
value: process.env.APP_MOCK_COOKIE!,
httpOnly: false,
secure: true,
sameSite: 'Lax',
path: '/',
domain: 'localhost',
expires: -1,
}],
origins: [],
},
storageState: 'playwright/.auth/user.json',
},
// dependencies: ['Setup global'],
},
],
// ...
})
25 changes: 6 additions & 19 deletions tests-e2e/home.test.mts
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import { expect, test } from '@nuxt/test-utils/playwright'
import { uuidv7 } from 'uuidv7'

test('Can open distapp and show login page', async ({ page, goto }) => {
test('Can open distapp and show get started', async ({ page, goto, context }) => {
await context.clearCookies()
await goto('/')
await expect(page.getByText('DistApp')).toHaveCount(1)
await expect(page.getByText('Get Started')).toHaveCount(1)
})

test('User can add organization', async ({ context, goto, page }) => {
test('Logged in user open distapp and show go to apps', async ({ page, goto, context }) => {
await goto('/')
await page.locator('div.p-splitbutton:nth-child(1) > button:nth-child(2)').click()
await page.locator('#pv_id_1_overlay_0_label').click()
await expect(page.locator('.p-dialog-title', {
hasText: 'Add Organization',
})).toBeVisible()
const testId = uuidv7()
const expectedOrgName = `Org Testing ${testId}`
const expectedOrgNameNormalized = `/orgs/org-testing-${testId}`
await page.getByTestId('orgname').fill(expectedOrgName)
await page.getByTestId('orgname').press('Enter')
await expect(page.getByText(expectedOrgName)).toBeVisible()
await expect(page.locator('//a', {
hasText: expectedOrgName,
})).toHaveAttribute('href', expectedOrgNameNormalized)
})
await expect(page.getByText('Go To Apps')).toHaveCount(1)
})
20 changes: 20 additions & 0 deletions tests-e2e/setup/auth.setup.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { test as setup, expect } from '@playwright/test'
import path from 'path';

const authFile = path.join(import.meta.dirname, '../../playwright/.auth/user.json');

setup('authenticate', async ({ page }) => {
const domain = process.env.TEST_APP_URL!.replaceAll('https://', '').replaceAll('http://', '').replaceAll(':3000', '')
await page.context().addCookies([{
name: 'app-auth',
value: process.env.TEST_APP_AUTH_COOKIES!,
httpOnly: false,
secure: true,
sameSite: 'Lax',
path: '/',
domain: domain,
expires: -1,
}])

await page.context().storageState({ path: authFile });
})

0 comments on commit 1318c0f

Please sign in to comment.