|
1 |
| -import { render, screen } from '@testing-library/angular'; |
| 1 | +import { render, screen, waitForElementToBeRemoved } from '@testing-library/angular'; |
| 2 | +import userEvent from '@testing-library/user-event'; |
2 | 3 |
|
3 |
| -import { DetailComponent, MasterComponent, HiddenDetailComponent } from './09-router'; |
| 4 | +import { DetailComponent, RootComponent, HiddenDetailComponent } from './09-router'; |
4 | 5 |
|
5 | 6 | test('it can navigate to routes', async () => {
|
6 |
| - const { navigate } = await render(MasterComponent, { |
| 7 | + await render(RootComponent, { |
| 8 | + declarations: [DetailComponent, HiddenDetailComponent], |
| 9 | + routes: [ |
| 10 | + { |
| 11 | + path: '', |
| 12 | + children: [ |
| 13 | + { |
| 14 | + path: 'detail/:id', |
| 15 | + component: DetailComponent, |
| 16 | + }, |
| 17 | + { |
| 18 | + path: 'hidden-detail', |
| 19 | + component: HiddenDetailComponent, |
| 20 | + }, |
| 21 | + ], |
| 22 | + }, |
| 23 | + ], |
| 24 | + }); |
| 25 | + |
| 26 | + expect(screen.queryByText(/Detail one/i)).not.toBeInTheDocument(); |
| 27 | + |
| 28 | + userEvent.click(screen.getByRole('link', { name: /load one/i })); |
| 29 | + expect(await screen.findByRole('heading', { name: /Detail one/i })).toBeInTheDocument(); |
| 30 | + |
| 31 | + userEvent.click(screen.getByRole('link', { name: /load three/i })); |
| 32 | + await waitForElementToBeRemoved(() => screen.queryByRole('heading', { name: /Detail one/i })); |
| 33 | + expect(await screen.findByRole('heading', { name: /Detail three/i })).toBeInTheDocument(); |
| 34 | + |
| 35 | + userEvent.click(screen.getByRole('link', { name: /back to parent/i })); |
| 36 | + await waitForElementToBeRemoved(() => screen.queryByRole('heading', { name: /Detail three/i })); |
| 37 | + |
| 38 | + userEvent.click(screen.getByRole('link', { name: /load two/i })); |
| 39 | + expect(await screen.findByRole('heading', { name: /Detail two/i })).toBeInTheDocument(); |
| 40 | + |
| 41 | + userEvent.click(screen.getByRole('link', { name: /hidden x/i })); |
| 42 | + expect(await screen.findByText(/You found the treasure!/i)).toBeInTheDocument(); |
| 43 | +}); |
| 44 | + |
| 45 | +test('it can navigate to routes - workaround', async () => { |
| 46 | + const { navigate } = await render(RootComponent, { |
7 | 47 | declarations: [DetailComponent, HiddenDetailComponent],
|
8 | 48 | routes: [
|
9 | 49 | {
|
@@ -42,7 +82,7 @@ test('it can navigate to routes', async () => {
|
42 | 82 |
|
43 | 83 | test('it can navigate to routes with a base path', async () => {
|
44 | 84 | const basePath = 'base';
|
45 |
| - const { navigate } = await render(MasterComponent, { |
| 85 | + const { navigate } = await render(RootComponent, { |
46 | 86 | declarations: [DetailComponent, HiddenDetailComponent],
|
47 | 87 | routes: [
|
48 | 88 | {
|
|
0 commit comments