|
1
|
|
|
import { fireEvent, render, screen } from '@testing-library/svelte'; |
|
2
|
|
|
import UsersInput from './UsersInput.svelte'; |
|
3
|
|
|
|
|
4
|
|
|
it('renders the users input select with the selected user', () => { |
|
5
|
|
|
const userId = '8a1dd502-c974-447e-9be3-a18e7abfebe3'; |
|
6
|
|
|
const users = [ |
|
7
|
|
|
{ |
|
8
|
|
|
id: '8a1dd502-c974-447e-9be3-a18e7abfebe3', |
|
9
|
|
|
firstName: 'Nicolas', |
|
10
|
|
|
lastName: 'Dievart', |
|
11
|
|
|
}, |
|
12
|
|
|
{ |
|
13
|
|
|
id: '14900cf1-49b1-4410-81d4-0c31086c7e6d', |
|
14
|
|
|
firstName: 'Mathieu', |
|
15
|
|
|
lastName: 'Marchois', |
|
16
|
|
|
}, |
|
17
|
|
|
]; |
|
18
|
|
|
render(UsersInput, { userId, users }); |
|
19
|
|
|
|
|
20
|
|
|
const select = screen.getByRole('combobox'); |
|
21
|
|
|
expect(select.value).toBe('8a1dd502-c974-447e-9be3-a18e7abfebe3'); |
|
22
|
|
|
const options = screen.getAllByRole('option'); |
|
23
|
|
|
const optionNames = options.map((option) => option.textContent.trim()); |
|
24
|
|
|
expect(optionNames).toMatchInlineSnapshot(` |
|
25
|
|
|
Array [ |
|
26
|
|
|
"-- Choisir un coopérateur - salarié --", |
|
27
|
|
|
"Nicolas Dievart", |
|
28
|
|
|
"Mathieu Marchois", |
|
29
|
|
|
] |
|
30
|
|
|
`); |
|
31
|
|
|
}); |
|
32
|
|
|
|
|
33
|
|
|
it('renders the users input select, on change other user selected', () => { |
|
34
|
|
|
const userId = '8a1dd502-c974-447e-9be3-a18e7abfebe3'; |
|
35
|
|
|
const users = [ |
|
36
|
|
|
{ |
|
37
|
|
|
id: '8a1dd502-c974-447e-9be3-a18e7abfebe3', |
|
38
|
|
|
firstName: 'Nicolas', |
|
39
|
|
|
lastName: 'Dievart', |
|
40
|
|
|
}, |
|
41
|
|
|
{ |
|
42
|
|
|
id: '14900cf1-49b1-4410-81d4-0c31086c7e6d', |
|
43
|
|
|
firstName: 'Mathieu', |
|
44
|
|
|
lastName: 'Marchois', |
|
45
|
|
|
}, |
|
46
|
|
|
]; |
|
47
|
|
|
render(UsersInput, { userId, users }); |
|
48
|
|
|
const select = screen.getByRole('combobox'); |
|
49
|
|
|
|
|
50
|
|
|
// Switch to "mathieu" |
|
51
|
|
|
fireEvent.change(select, { |
|
52
|
|
|
target: { value: '14900cf1-49b1-4410-81d4-0c31086c7e6d' }, |
|
53
|
|
|
}); |
|
54
|
|
|
|
|
55
|
|
|
expect(select.value).toBe('14900cf1-49b1-4410-81d4-0c31086c7e6d'); |
|
56
|
|
|
}); |
|
57
|
|
|
|