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

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

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 42
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 25
mnd 0
bc 0
fnc 3
dl 0
loc 42
rs 10
bpm 0
cpm 1
noi 1
c 0
b 0
f 0
1
import '@testing-library/jest-dom/extend-expect';
2
import {screen, render} from '@testing-library/svelte';
3
import SecuredView from './SecuredView.svelte';
4
import {
5
  ROLE_COOPERATOR,
6
  ROLE_EMPLOYEE,
7
  ROLE_ACCOUNTANT
8
} from '../constants/roles';
9
import {user} from '../store';
10
11
beforeEach(() => {
12
  jest.resetModules();
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...
13
  process.browser = true;
14
});
15
16
it('renders the secured view for non-authorized user', () => {
17
  user.set({
18
    role: ROLE_ACCOUNTANT
19
  });
20
21
  const roles = [ROLE_COOPERATOR, ROLE_EMPLOYEE];
22
23
  render(SecuredView, {
24
    roles
25
  });
26
27
  expect(screen.getByText(/Accès interdit !/i)).toBeInTheDocument();
28
});
29
30
it('renders nothing for authorized user', () => {
31
  user.set({
32
    role: ROLE_COOPERATOR
33
  });
34
35
  const roles = [ROLE_COOPERATOR, ROLE_EMPLOYEE];
36
37
  render(SecuredView, {
38
    roles
39
  });
40
41
  expect(screen.queryByText(/Accès interdit !/i)).not.toBeInTheDocument();
42
});
43