|
1
|
|
|
import { fireEvent, render, screen } from '@testing-library/svelte'; |
|
2
|
|
|
import CustomersInput from './CustomersInput.svelte'; |
|
3
|
|
|
|
|
4
|
|
|
it('renders the customers input select with the selected customer', () => { |
|
5
|
|
|
const customerId = '8a1dd502-c974-447e-9be3-a18e7abfebe3'; |
|
6
|
|
|
const customers = [ |
|
7
|
|
|
{ id: '8a1dd502-c974-447e-9be3-a18e7abfebe3', name: 'Customer 1' }, |
|
8
|
|
|
{ id: '14900cf1-49b1-4410-81d4-0c31086c7e6d', name: 'Customer 2' }, |
|
9
|
|
|
]; |
|
10
|
|
|
render(CustomersInput, { customerId, customers }); |
|
11
|
|
|
|
|
12
|
|
|
expect(screen.getByRole('combobox').value).toBe( |
|
13
|
|
|
'8a1dd502-c974-447e-9be3-a18e7abfebe3' |
|
14
|
|
|
); |
|
15
|
|
|
|
|
16
|
|
|
const options = screen.getAllByRole('option'); |
|
17
|
|
|
const optionNames = options.map((option) => option.textContent.trim()); |
|
18
|
|
|
expect(optionNames).toMatchInlineSnapshot(` |
|
19
|
|
|
Array [ |
|
20
|
|
|
"-- Choisir un client --", |
|
21
|
|
|
"Customer 1", |
|
22
|
|
|
"Customer 2", |
|
23
|
|
|
] |
|
24
|
|
|
`); |
|
25
|
|
|
}); |
|
26
|
|
|
|
|
27
|
|
|
it('renders the customers input select, on change other customer selected', () => { |
|
28
|
|
|
const customerId = '8a1dd502-c974-447e-9be3-a18e7abfebe3'; |
|
29
|
|
|
const customers = [ |
|
30
|
|
|
{ id: '8a1dd502-c974-447e-9be3-a18e7abfebe3', name: 'Customer 1' }, |
|
31
|
|
|
{ id: '14900cf1-49b1-4410-81d4-0c31086c7e6d', name: 'Customer 2' }, |
|
32
|
|
|
]; |
|
33
|
|
|
render(CustomersInput, { customerId, customers }); |
|
34
|
|
|
|
|
35
|
|
|
const select = screen.getByRole('combobox'); |
|
36
|
|
|
|
|
37
|
|
|
// Switch to "customer 2" |
|
38
|
|
|
fireEvent.change(select, { |
|
39
|
|
|
target: { value: '14900cf1-49b1-4410-81d4-0c31086c7e6d' }, |
|
40
|
|
|
}); |
|
41
|
|
|
|
|
42
|
|
|
expect(select.value).toBe('14900cf1-49b1-4410-81d4-0c31086c7e6d'); |
|
43
|
|
|
}); |
|
44
|
|
|
|