| Total Complexity | 3 |
| Complexity/F | 1 |
| Lines of Code | 57 |
| Function Count | 3 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
|
|
|||
| 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 |
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.