Passed
Push — master ( d1aed2...edd986 )
by
unknown
01:59
created

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

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 54
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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