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