-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathAuthenticated.spec.js
More file actions
82 lines (67 loc) · 2.07 KB
/
Authenticated.spec.js
File metadata and controls
82 lines (67 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React from 'react';
import {shallow} from 'enzyme';
import {expect} from 'chai';
import Authenticated from '../../src/components/Authenticated';
describe('<Authenticated/>', () => {
let userContext;
let noUserContext;
before(() => {
userContext = {
user: {
groups: {
basic: true,
unbasic: true
}
}
};
noUserContext = {};
});
describe('without inGroup property', () => {
it('should render content if there is a user', () => {
const element = shallow(
<Authenticated>Shown</Authenticated>,
{context: userContext}
);
expect(element).to.be.ok;
expect(element.text()).to.equal('Shown');
});
it('should not render content if there is no user', () => {
const element = shallow(
<Authenticated>Not Shown</Authenticated>,
{context: noUserContext}
);
expect(element).to.be.ok;
expect(element.text()).not.to.be.ok;
expect(element.text()).not.to.equal('Not Shown');
});
});
describe('with inGroup property', () => {
it('should not render content if there is no user', () => {
const element = shallow(
<Authenticated>Not Shown</Authenticated>,
{context: noUserContext}
);
expect(element).to.be.ok;
expect(element.text()).not.to.be.ok;
expect(element.text()).not.to.equal('Not Shown');
});
it('should not render content if the user is not in the group', () => {
const element = shallow(
<Authenticated inGroup="admin">Not Shown</Authenticated>,
{context: userContext}
);
expect(element).to.be.ok;
expect(element.text()).not.to.be.ok;
expect(element.text()).not.to.equal('Not Shown');
});
it('should render content if the user is in the group', () => {
const element = shallow(
<Authenticated inGroup="basic">Shown</Authenticated>,
{context: userContext}
);
expect(element).to.be.ok;
expect(element.text()).to.be.ok;
expect(element.text()).to.equal('Shown');
});
});
});