-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathapp.component.spec.ts
More file actions
96 lines (80 loc) · 3.24 KB
/
app.component.spec.ts
File metadata and controls
96 lines (80 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { page } from 'vitest/browser';
import { AppComponent } from './app.component';
import { appConfig } from './app.config';
describe('AppComponent', () => {
beforeEach(async () => {
TestBed.configureTestingModule({
providers: appConfig.providers,
});
const router = TestBed.inject(Router);
router.initialNavigation();
TestBed.createComponent(AppComponent);
});
describe('When component is rendered', () => {
it('Then should display the portal title', async () => {
const heading = page.getByRole('heading', {
name: /user management portal/i,
});
await expect.element(heading).toBeInTheDocument();
});
it('Then should display correct information in the user list', async () => {
await expect
.element(page.getByText('Max Mustermann'))
.toBeInTheDocument();
await expect.element(page.getByText('John Doe')).toBeInTheDocument();
await expect.element(page.getByText('Jane Smith')).toBeInTheDocument();
});
});
describe('Given a user wants to add a new user', () => {
it('Then should navigate to add form and create user', async () => {
const addButton = page.getByRole('button', { name: /add user/i }).first();
await addButton.click();
await expect
.element(page.getByRole('heading', { name: /add new user/i }))
.toBeInTheDocument();
await page.getByLabelText(/firstname/i).fill('Antigravity');
await page.getByLabelText(/lastname/i).fill('AI');
await page.getByLabelText(/age/i).fill('1');
await page.getByLabelText(/grade/i).fill('10');
await page.getByRole('button', { name: /add/i }).click();
await expect
.element(page.getByText('Antigravity AI'))
.toBeInTheDocument();
});
});
describe('Given a user wants to edit an existing user', () => {
it('Then should update the user successfully', async () => {
await expect.element(page.getByText('Jane Smith')).toBeInTheDocument();
const editButtons = await page
.getByRole('button', { name: /edit/i })
.all();
// Jane Smith is the 3rd user in list (id 3)
await editButtons[2].click();
await expect
.element(page.getByRole('heading', { name: /edit user/i }))
.toBeInTheDocument();
await expect
.element(page.getByLabelText(/firstname/i))
.toHaveValue('Jane');
await page.getByLabelText(/firstname/i).fill('Janet');
await page.getByRole('button', { name: /update/i }).click();
await expect.element(page.getByText('Janet Smith')).toBeInTheDocument();
await expect
.element(page.getByText('Jane Smith'))
.not.toBeInTheDocument();
});
});
describe('Given a user wants to delete a user', () => {
it('Then should remove the user from the list', async () => {
await expect.element(page.getByText('John Doe')).toBeInTheDocument();
const deleteButtons = await page
.getByRole('button', { name: /delete/i })
.all();
// John Doe is the 2nd user in list
await deleteButtons[1].click();
await expect.element(page.getByText('John Doe')).not.toBeInTheDocument();
});
});
});