Skip to content

Commit b7a6b74

Browse files
committed
test: components
1 parent 0980005 commit b7a6b74

File tree

6 files changed

+227
-457
lines changed

6 files changed

+227
-457
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@
5353
"@nuxt/schema": "^3.12.1",
5454
"@nuxt/test-utils": "^3.13.1",
5555
"@types/node": "^20.14.2",
56+
"@vue/test-utils": "^2.4.6",
5657
"changelogen": "^0.5.5",
5758
"eslint": "^9.4.0",
5859
"nuxt": "^3.12.1",
60+
"playwright-core": "^1.46.1",
5961
"typescript": "latest",
6062
"vitest": "^1.6.0",
6163
"vue-tsc": "^2.0.21"

pnpm-lock.yaml

Lines changed: 131 additions & 457 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/component.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { fileURLToPath } from 'node:url'
2+
import { describe, expect, it } from 'vitest'
3+
import { setup, createPage } from '@nuxt/test-utils/e2e'
4+
5+
describe('Components', async () => {
6+
await setup({
7+
rootDir: fileURLToPath(new URL('./fixtures/components', import.meta.url)),
8+
})
9+
10+
it('should render correctly', async () => {
11+
const page = await createPage('/')
12+
13+
expect(await page.getByTestId('view-can').isVisible()).toBeTruthy()
14+
expect(await page.getByTestId('view-not-can').isVisible()).toBeFalsy()
15+
expect(await page.getByTestId('view-cannot').isVisible()).toBeFalsy()
16+
expect(await page.getByTestId('view-not-cannot').isVisible()).toBeTruthy()
17+
18+
await page.close()
19+
})
20+
})
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<script lang="ts" setup>
2+
import { defineAbility } from '#imports'
3+
import { Can } from '#components'
4+
5+
const can = defineAbility(() => {
6+
return true
7+
})
8+
9+
const cannot = defineAbility(() => {
10+
return false
11+
})
12+
</script>
13+
14+
<template>
15+
<div>
16+
<Can
17+
:bouncer-ability="can"
18+
:args="[]"
19+
>
20+
<div data-testid="view-can">
21+
Can
22+
</div>
23+
</Can>
24+
25+
<Can
26+
:bouncer-ability="cannot"
27+
:args="[]"
28+
>
29+
<div data-testid="view-not-can">
30+
Cannot
31+
</div>
32+
</Can>
33+
34+
<Cannot
35+
:bouncer-ability="can"
36+
:args="[]"
37+
>
38+
<div data-testid="view-cannot">
39+
Cannot
40+
</div>
41+
</Cannot>
42+
43+
<Cannot
44+
:bouncer-ability="cannot"
45+
:args="[]"
46+
>
47+
<div data-testid="view-not-cannot">
48+
Can
49+
</div>
50+
</Cannot>
51+
</div>
52+
</template>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { defineNuxtPlugin } from '#app'
2+
3+
export default defineNuxtPlugin({
4+
name: 'authorization-resolver',
5+
parallel: true,
6+
setup() {
7+
return {
8+
provide: {
9+
authorization: {
10+
resolveClientUser: () => ({ id: 2, name: 'User 1' }),
11+
},
12+
},
13+
}
14+
},
15+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default defineNuxtConfig({
2+
modules: ['../../src/module.ts'],
3+
4+
future: {
5+
compatibilityVersion: 4,
6+
},
7+
})

0 commit comments

Comments
 (0)