test(ct): react router (#18602)
This commit is contained in:
parent
84529595cc
commit
ccf9c8d487
|
|
@ -3,11 +3,14 @@
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"react": "^17.0.2",
|
||||||
|
"react-dom": "^17.0.2",
|
||||||
|
"react-router-dom": "^6.4.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
"@types/node": "^16.11.26",
|
"@types/node": "^16.11.26",
|
||||||
"@types/react": "^17.0.39",
|
"@types/react": "^17.0.39",
|
||||||
"@types/react-dom": "^17.0.13",
|
"@types/react-dom": "^17.0.13",
|
||||||
"react": "^17.0.2",
|
|
||||||
"react-dom": "^17.0.2",
|
|
||||||
"react-scripts": "5.0.0",
|
"react-scripts": "5.0.0",
|
||||||
"typescript": "^4.6.2"
|
"typescript": "^4.6.2"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
.App {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.App-logo {
|
|
||||||
height: 40vmin;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-reduced-motion: no-preference) {
|
|
||||||
.App-logo {
|
|
||||||
animation: App-logo-spin infinite 20s linear;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.App-header {
|
|
||||||
background-color: #282c34;
|
|
||||||
min-height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
font-size: calc(10px + 2vmin);
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.App-link {
|
|
||||||
color: #61dafb;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes App-logo-spin {
|
|
||||||
from {
|
|
||||||
transform: rotate(0deg);
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +1,20 @@
|
||||||
|
import { Routes, Route, Link } from 'react-router-dom';
|
||||||
import logo from './assets/logo.svg';
|
import logo from './assets/logo.svg';
|
||||||
import './App.css';
|
import LoginPage from './pages/LoginPage';
|
||||||
|
import DashboardPage from './pages/DashboardPage';
|
||||||
|
|
||||||
function App() {
|
export default function App() {
|
||||||
return (
|
return <>
|
||||||
<div className="App">
|
<header>
|
||||||
<header className="App-header">
|
<img src={logo} alt="logo" width={125} height={125} />
|
||||||
<img src={logo} className="App-logo" alt="logo" />
|
<Link to="/">Login</Link>
|
||||||
<p>
|
<Link to="/dashboard">Dashboard</Link>
|
||||||
Edit <code>src/App.tsx</code> and save to reload.
|
</header>
|
||||||
</p>
|
<Routes>
|
||||||
<a
|
<Route path="/">
|
||||||
className="App-link"
|
<Route index element={<LoginPage />} />
|
||||||
href="https://reactjs.org"
|
<Route path="dashboard" element={<DashboardPage />} />
|
||||||
target="_blank"
|
</Route>
|
||||||
rel="noopener noreferrer"
|
</Routes>
|
||||||
>
|
</>
|
||||||
Learn React
|
|
||||||
</a>
|
|
||||||
</header>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App;
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import './App.css';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
|
import './assets/index.css';
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<App />
|
<BrowserRouter><App /></BrowserRouter>
|
||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
);
|
);
|
||||||
|
|
|
||||||
3
tests/components/ct-react/src/pages/DashboardPage.tsx
Normal file
3
tests/components/ct-react/src/pages/DashboardPage.tsx
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
export default function DashboardPage() {
|
||||||
|
return <main>Dashboard</main>
|
||||||
|
}
|
||||||
3
tests/components/ct-react/src/pages/LoginPage.tsx
Normal file
3
tests/components/ct-react/src/pages/LoginPage.tsx
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
export default function LoginPage() {
|
||||||
|
return <main>Login</main>
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import { test, expect } from '@playwright/experimental-ct-react';
|
import { test, expect } from '@playwright/experimental-ct-react';
|
||||||
const { serverFixtures } = require('../../../../tests/config/serverFixtures');
|
const { serverFixtures } = require('../../../../tests/config/serverFixtures');
|
||||||
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
|
import App from './App';
|
||||||
import Fetch from './components/Fetch';
|
import Fetch from './components/Fetch';
|
||||||
import DelayedData from './components/DelayedData';
|
import DelayedData from './components/DelayedData';
|
||||||
import Button from './components/Button';
|
import Button from './components/Button';
|
||||||
|
|
@ -148,6 +150,15 @@ test('get textContent of the empty fragment', async ({ mount }) => {
|
||||||
await expect(component).toHaveText('');
|
await expect(component).toHaveText('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('navigate to a page by clicking a link', async ({ page, mount }) => {
|
||||||
|
const component = await mount(<BrowserRouter><App /></BrowserRouter>);
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
|
||||||
const testWithServer = test.extend(serverFixtures);
|
const testWithServer = test.extend(serverFixtures);
|
||||||
testWithServer('components routing should go through context', async ({ mount, context, server }) => {
|
testWithServer('components routing should go through context', async ({ mount, context, server }) => {
|
||||||
server.setRoute('/hello', (req: any, res: any) => {
|
server.setRoute('/hello', (req: any, res: any) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue