Passed
Pull Request — master (#111)
by Nicolas
01:41
created

client/src/components/inputs/TasksInput.spec.js   A

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 41
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 23
mnd 0
bc 0
fnc 3
dl 0
loc 41
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
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