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

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

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 51
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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