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

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

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 43
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 43
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
1
import CustomersInput from './CustomersInput.svelte';
2
import {screen, render, fireEvent} from '@testing-library/svelte';
3
4
it('renders the customers input select with the selected customer', () => {
5
  const customerId = '8a1dd502-c974-447e-9be3-a18e7abfebe3';
6
  const customers = [
7
    {id: '8a1dd502-c974-447e-9be3-a18e7abfebe3', name: 'Customer 1'},
8
    {id: '14900cf1-49b1-4410-81d4-0c31086c7e6d', name: 'Customer 2'}
9
  ];
10
  render(CustomersInput, {customerId, customers});
11
12
  expect(screen.getByRole('combobox').value).toBe(
13
    '8a1dd502-c974-447e-9be3-a18e7abfebe3'
14
  );
15
16
  const options = screen.getAllByRole('option');
17
  const optionNames = options.map((option) => option.textContent.trim());
18
  expect(optionNames).toMatchInlineSnapshot(`
19
  Array [
20
    "-- Choisir un client --",
21
    "Customer 1",
22
    "Customer 2",
23
  ]
24
`);
25
});
26
27
it('renders the customers input select, on change other customer selected', () => {
28
  const customerId = '8a1dd502-c974-447e-9be3-a18e7abfebe3';
29
  const customers = [
30
    {id: '8a1dd502-c974-447e-9be3-a18e7abfebe3', name: 'Customer 1'},
31
    {id: '14900cf1-49b1-4410-81d4-0c31086c7e6d', name: 'Customer 2'}
32
  ];
33
  render(CustomersInput, {customerId, customers});
34
35
  const select = screen.getByRole('combobox');
36
37
  // Switch to "customer 2"
38
  fireEvent.change(select, {
39
    target: {value: '14900cf1-49b1-4410-81d4-0c31086c7e6d'}
40
  });
41
42
  expect(select.value).toBe('14900cf1-49b1-4410-81d4-0c31086c7e6d');
43
});
44