1
|
|
|
import { fireEvent, render, screen } from '@testing-library/svelte'; |
2
|
|
|
import ProjectsInput from './ProjectsInput.svelte'; |
3
|
|
|
|
4
|
|
|
it('renders the projects input select with the selected project', () => { |
5
|
|
|
const projectId = '8a1dd502-c974-447e-9be3-a18e7abfebe3'; |
6
|
|
|
const projects = [ |
7
|
|
|
{ |
8
|
|
|
id: '8a1dd502-c974-447e-9be3-a18e7abfebe3', |
9
|
|
|
name: 'Project 1', |
10
|
|
|
customer: { name: 'Customer 1' }, |
11
|
|
|
}, |
12
|
|
|
{ |
13
|
|
|
id: '14900cf1-49b1-4410-81d4-0c31086c7e6d', |
14
|
|
|
name: 'Project 2', |
15
|
|
|
customer: { name: 'Customer 2' }, |
16
|
|
|
}, |
17
|
|
|
]; |
18
|
|
|
render(ProjectsInput, { projectId, projects }); |
19
|
|
|
|
20
|
|
|
const select = screen.getByRole('combobox'); |
21
|
|
|
const options = screen.getAllByRole('option'); |
22
|
|
|
expect(select.value).toBe('8a1dd502-c974-447e-9be3-a18e7abfebe3'); |
23
|
|
|
expect(options[select.selectedIndex].textContent).toContain( |
24
|
|
|
'Project 1' |
25
|
|
|
); |
26
|
|
|
expect(options[select.selectedIndex].textContent).toContain( |
27
|
|
|
'(Customer 1)' |
28
|
|
|
); |
29
|
|
|
}); |
30
|
|
|
|
31
|
|
|
it('renders the projects input select, on change other project selected', () => { |
32
|
|
|
const projectId = '8a1dd502-c974-447e-9be3-a18e7abfebe3'; |
33
|
|
|
const projects = [ |
34
|
|
|
{ |
35
|
|
|
id: '8a1dd502-c974-447e-9be3-a18e7abfebe3', |
36
|
|
|
name: 'Project 1', |
37
|
|
|
customer: { name: 'Customer 1' }, |
38
|
|
|
}, |
39
|
|
|
{ |
40
|
|
|
id: '14900cf1-49b1-4410-81d4-0c31086c7e6d', |
41
|
|
|
name: 'Project 2', |
42
|
|
|
customer: { name: 'Customer 2' }, |
43
|
|
|
}, |
44
|
|
|
]; |
45
|
|
|
render(ProjectsInput, { projectId, projects }); |
46
|
|
|
const select = screen.getByRole('combobox'); |
47
|
|
|
|
48
|
|
|
// Switch to "Project 2" |
49
|
|
|
fireEvent.change(select, { |
50
|
|
|
target: { value: '14900cf1-49b1-4410-81d4-0c31086c7e6d' }, |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
|
expect(select.value).toBe('14900cf1-49b1-4410-81d4-0c31086c7e6d'); |
54
|
|
|
}); |
55
|
|
|
|