1
|
|
|
import ProjectsInput from './ProjectsInput.svelte'; |
2
|
|
|
import {screen, render, fireEvent} from '@testing-library/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 (Customer 1)' |
25
|
|
|
); |
26
|
|
|
}); |
27
|
|
|
|
28
|
|
|
it('renders the projects input select, on change other project selected', () => { |
29
|
|
|
const projectId = '8a1dd502-c974-447e-9be3-a18e7abfebe3'; |
30
|
|
|
const projects = [ |
31
|
|
|
{ |
32
|
|
|
id: '8a1dd502-c974-447e-9be3-a18e7abfebe3', |
33
|
|
|
name: 'Project 1', |
34
|
|
|
customer: {name: 'Customer 1'} |
35
|
|
|
}, |
36
|
|
|
{ |
37
|
|
|
id: '14900cf1-49b1-4410-81d4-0c31086c7e6d', |
38
|
|
|
name: 'Project 2', |
39
|
|
|
customer: {name: 'Customer 2'} |
40
|
|
|
} |
41
|
|
|
]; |
42
|
|
|
render(ProjectsInput, {projectId, projects}); |
43
|
|
|
const select = screen.getByRole('combobox'); |
44
|
|
|
|
45
|
|
|
// Switch to "Project 2" |
46
|
|
|
fireEvent.change(select, { |
47
|
|
|
target: {value: '14900cf1-49b1-4410-81d4-0c31086c7e6d'} |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
expect(select.value).toBe('14900cf1-49b1-4410-81d4-0c31086c7e6d'); |
51
|
|
|
}); |
52
|
|
|
|