test(ct): vue cli router (#18603)

This commit is contained in:
sand4rt 2022-11-08 17:40:29 +01:00 committed by GitHub
parent ccf9c8d487
commit 712ce0dce9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 55 additions and 39 deletions

View File

@ -10,13 +10,15 @@
},
"dependencies": {
"core-js": "^3.8.3",
"vue": "^3.2.13"
"vue": "^3.2.13",
"vue-router": "^4.1.5"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-plugin-router": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"@vue/tsconfig": "^0.1.3",
"eslint": "^7.32.0",

View File

@ -1,12 +1,13 @@
//@ts-check
import '../src/assets/index.css';
import { beforeMount, afterMount } from '@playwright/experimental-ct-vue/hooks';
import { router } from '../src/router';
import '../src/assets/index.css';
export type HooksConfig = {
route: string;
}
beforeMount<HooksConfig>(async ({ app, hooksConfig }) => {
app.use(router);
console.log(`Before mount: ${JSON.stringify(hooksConfig)}, app: ${!!app}`);
});

View File

@ -1,21 +1,8 @@
<template>
<img alt="Vue logo" src="./assets/logo.png">
<header>
<img alt="Vue logo" class="logo" src="./assets/logo.png" width="125" height="125" />
<router-link to="/">Login</router-link>
<router-link to="/dashboard">Dashboard</router-link>
</header>
<router-view />
</template>
<script>
export default {
name: 'App',
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>

View File

@ -1,5 +1,6 @@
import { createApp } from 'vue'
import App from './App.vue'
import { createApp } from 'vue';
import { router } from './router';
import App from './App.vue';
import './assets/index.css';
createApp(App).mount('#app')
createApp(App).use(router).mount('#app');

View File

@ -1,4 +1,5 @@
import { test, expect } from '@playwright/experimental-ct-vue'
import App from './App.vue';
import Button from './components/Button.vue'
import Counter from './components/Counter.vue'
import DefaultSlot from './components/DefaultSlot.vue'
@ -119,3 +120,12 @@ test('get textContent of the empty template', async ({ mount }) => {
expect(await component.textContent()).toBe('');
await expect(component).toHaveText('');
});
test('navigate to a page by clicking a link', async ({ page, mount }) => {
const component = await mount(<App />);
await expect(component.getByRole('main')).toHaveText('Login');
await expect(page).toHaveURL('/');
await component.getByRole('link', { name: 'Dashboard' }).click();
await expect(component.getByRole('main')).toHaveText('Dashboard');
await expect(page).toHaveURL('/dashboard');
});

View File

@ -1,4 +1,5 @@
import { test, expect } from '@playwright/experimental-ct-vue'
import App from './App.vue';
import Button from './components/Button.vue'
import Counter from './components/Counter.vue'
import DefaultSlot from './components/DefaultSlot.vue'
@ -125,3 +126,12 @@ test('get textContent of the empty template', async ({ mount }) => {
expect(await component.textContent()).toBe('');
await expect(component).toHaveText('');
});
test('navigate to a page by clicking a link', async ({ page, mount }) => {
const component = await mount(App);
await expect(component.getByRole('main')).toHaveText('Login');
await expect(page).toHaveURL('/');
await component.getByRole('link', { name: 'Dashboard' }).click();
await expect(component.getByRole('main')).toHaveText('Dashboard');
await expect(page).toHaveURL('/dashboard');
});

View File

@ -0,0 +1,3 @@
<template>
<main>Dashboard</main>
</template>

View File

@ -0,0 +1,3 @@
<template>
<main>Login</main>
</template>

View File

@ -0,0 +1,11 @@
import DashboardPage from '../pages/DashboardPage.vue';
import LoginPage from '../pages/LoginPage.vue';
import { createRouter, createWebHistory } from 'vue-router';
export const router = createRouter({
history: createWebHistory('/'),
routes: [
{ path: '/', component: LoginPage },
{ path: '/dashboard', component: DashboardPage },
],
})

View File

@ -1,8 +1,8 @@
{
"extends": "./tsconfig.app.json",
"include": ["playwright"],
"exclude": [],
"include": ["playwright", "src/**/*"],
"compilerOptions": {
"allowJs": true,
"composite": true,
"lib": [],
"jsx": "react-jsx",

View File

@ -1,16 +1,4 @@
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
pages: {
index: {
entry: 'src/main.js',
template: 'public/index.html',
filename: 'index.html',
},
tests: {
entry: 'src/tests.js',
template: 'src/tests.html',
filename: 'tests.html',
},
}
})