-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67732e7
commit 0248f73
Showing
14 changed files
with
138 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
NODE_OPTIONS=--dns-result-order=ipv4first | ||
NUXT_PUBLIC_DIRECTUS_AUTH_MODE=cookie | ||
NUXT_PUBLIC_DIRECTUS_AUTH_MODE=session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
<template> | ||
<div> | ||
<client-only> | ||
<div data-testid="hydration-check" /> | ||
</client-only> | ||
<nuxt-page /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
<template> | ||
<div> | ||
<h1>Rest</h1> | ||
<p>{{ data }}</p> | ||
<button @click="refresh()"> | ||
Refresh | ||
</button> | ||
<p data-testid="rest-data"> | ||
{{ data }} | ||
</p> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useDirectusRest, readItems, useAsyncData } from '#imports' | ||
const { data, refresh } = await useAsyncData(() => | ||
const { data } = await useAsyncData(() => | ||
useDirectusRest(readItems('country')), | ||
) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
import { test } from '@playwright/test' | ||
import { test, expect } from '@playwright/test' | ||
import { goto, login, reload, tokenTimeout } from './utils' | ||
|
||
test('should be logged in', async () => { | ||
test('should be logged in', async ({ browser }) => { | ||
const context = await browser.newContext() | ||
const page = await context.newPage() | ||
await login(page) | ||
|
||
await reload(page) | ||
await expect(page.getByRole('heading', { name: 'Home' })).toBeVisible() | ||
|
||
await goto(page, '/') | ||
await expect(page.getByRole('heading', { name: 'Home' })).toBeVisible() | ||
|
||
await page.goto('/404') | ||
await expect(page.getByRole('heading', { name: '404' })).toBeVisible() | ||
await page.getByRole('link', { name: 'Go back home' }).click() | ||
await expect(page.getByRole('heading', { name: 'Home' })).toBeVisible() | ||
}) | ||
|
||
test('should refresh session', async () => { | ||
test('should refresh session', async ({ browser }) => { | ||
const context = await browser.newContext() | ||
const page = await context.newPage() | ||
await login(page) | ||
|
||
await expect(page.getByTestId('user-data')).toContainText('id') | ||
|
||
await page.waitForTimeout(tokenTimeout) | ||
await page.getByRole('button', { name: 'Fetch user' }).click() | ||
await page.waitForTimeout(2000) | ||
await expect(page.getByTestId('user-data')).toContainText('id') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { test, expect } from '@playwright/test' | ||
import { goto, login, readCounter } from './utils' | ||
|
||
test('should query data', async ({ browser }) => { | ||
const context = await browser.newContext() | ||
const page = await context.newPage() | ||
await login(page) | ||
|
||
await goto(page, '/graphql') | ||
await expect(page.getByRole('heading', { name: 'GraphQL' })).toBeVisible() | ||
|
||
await readCounter(page) | ||
|
||
await context.close() | ||
}) | ||
|
||
test('should mutate and subscribe', async ({ browser }) => { | ||
const context = await browser.newContext() | ||
const page = await context.newPage() | ||
await login(page) | ||
|
||
await goto(page, '/graphql') | ||
await expect(page.getByRole('heading', { name: 'GraphQL' })).toBeVisible() | ||
|
||
const initialValue = await readCounter(page) | ||
|
||
await page.getByRole('button', { name: 'Increment' }).click() | ||
await page.waitForTimeout(2000) | ||
|
||
if (process.env.NUXT_PUBLIC_DIRECTUS_AUTH_MODE === 'session') { | ||
await page.getByRole('button', { name: 'Refresh' }).click() | ||
await page.waitForTimeout(2000) | ||
} | ||
|
||
const updatedValue = await readCounter(page) | ||
|
||
expect(updatedValue).toBeGreaterThanOrEqual(initialValue) | ||
|
||
await context.close() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { test, expect } from '@playwright/test' | ||
import { login, goto } from './utils' | ||
|
||
test('should read items', async ({ browser }) => { | ||
const context = await browser.newContext() | ||
const page = await context.newPage() | ||
await login(page) | ||
|
||
await goto(page, '/rest') | ||
await expect(page.getByRole('heading', { name: 'Rest' })).toBeVisible() | ||
|
||
await expect(page.getByTestId('rest-data')).toContainText('id') | ||
|
||
await context.close() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,16 @@ import { type Page, expect } from '@playwright/test' | |
|
||
export const credentials = { email: '[email protected]', password: 'abc123' } | ||
|
||
export const tokenTimeout = 16000 | ||
|
||
export async function goto(page: Page, path: string) { | ||
await page.goto(path) | ||
await expect(page.getByTestId('hydration-check')).toBeAttached() | ||
} | ||
|
||
export async function reload(page: Page) { | ||
await page.reload() | ||
await expect(page.getByTestId('hydration-check')).toBeAttached() | ||
expect(page.getByTestId('hydration-check')).toBeDefined() | ||
} | ||
|
||
export async function login(page: Page) { | ||
|
@@ -21,7 +23,8 @@ export async function login(page: Page) { | |
await expect(page.getByRole('heading', { name: 'Home' })).toBeVisible() | ||
} | ||
|
||
export async function logout(page: Page) { | ||
await page.getByRole('button', { name: 'Logout' }).click() | ||
await expect(page.getByRole('heading', { name: 'Login' })).toBeVisible() | ||
export async function readCounter(page: Page) { | ||
const counter = await page.getByTestId('counter').textContent() | ||
expect(counter).not.toBeNaN() | ||
return Number.parseInt(counter as string) | ||
} |