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

client/src/components/SecuredLink.spec.js   A

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 57
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 40
mnd 0
bc 0
fnc 3
dl 0
loc 57
rs 10
bpm 0
cpm 1
noi 1
c 0
b 0
f 0
1
import SecuredLink from './SecuredLink.svelte';
2
import {screen, render} from '@testing-library/svelte';
3
import {
4
  ROLE_COOPERATOR,
5
  ROLE_EMPLOYEE,
6
  ROLE_ACCOUNTANT
7
} from '../constants/roles';
8
import {user} from '../store';
9
10
beforeEach(() => {
11
  jest.resetModules(); // this is important - it clears the cache
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
12
  process.browser = true;
13
});
14
15
it('renders the secured link for authorized user', () => {
16
  user.set({
17
    firstName: 'Nicolas',
18
    lastName: 'Dievart',
19
    id: 12,
20
    role: ROLE_COOPERATOR
21
  });
22
23
  const className = 'link';
24
  const href = 'https://fairness.coop/';
25
  const roles = [ROLE_COOPERATOR, ROLE_EMPLOYEE];
26
27
  render(SecuredLink, {
28
    href,
29
    className,
30
    roles
31
  });
32
33
  const link = screen.getByRole('link');
34
  expect(link.href).toBe(href);
35
  expect(link.classList.contains('link')).toBe(true);
36
});
37
38
it('renders nothing for non-authorized user', () => {
39
  user.set({
40
    firstName: 'Nicolas',
41
    lastName: 'Dievart',
42
    id: 12,
43
    role: ROLE_ACCOUNTANT
44
  });
45
46
  const className = 'link';
47
  const href = 'https://fairness.coop/';
48
  const roles = [ROLE_COOPERATOR, ROLE_EMPLOYEE];
49
50
  render(SecuredLink, {
51
    href,
52
    className,
53
    roles
54
  });
55
56
  expect(screen.queryByRole('link')).toBeNull();
57
});
58