@madie/madie-design-system 1.0.39 → 1.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Modal/index.jsx +1 -5
- package/components/Popover/index.js +19 -0
- package/coverage/clover.xml +191 -371
- package/coverage/coverage-final.json +14 -23
- package/coverage/lcov-report/SvgComponents.jsx.html +1702 -0
- package/coverage/lcov-report/components/Accordion/index.html +116 -0
- package/coverage/lcov-report/components/Accordion/index.jsx.html +370 -0
- package/coverage/lcov-report/components/Button/index.html +116 -0
- package/coverage/lcov-report/components/Button/index.js.html +385 -0
- package/coverage/lcov-report/components/Error/Collapsible.jsx.html +364 -0
- package/coverage/lcov-report/components/Error/ErrorUI.jsx.html +178 -0
- package/coverage/lcov-report/components/Error/index.html +131 -0
- package/coverage/lcov-report/components/Footer/FooterUI.jsx.html +496 -0
- package/coverage/lcov-report/components/Footer/LegacyFooterUI.jsx.html +697 -0
- package/coverage/lcov-report/components/Footer/index.html +131 -0
- package/coverage/lcov-report/components/Infotip/Infotip.jsx.html +310 -0
- package/coverage/lcov-report/components/Infotip/InfotipIcon.jsx.html +208 -0
- package/coverage/lcov-report/components/Infotip/index.html +146 -0
- package/coverage/lcov-report/components/Infotip/index.js.html +94 -0
- package/coverage/lcov-report/components/InputLabel/index.html +116 -0
- package/coverage/lcov-report/components/InputLabel/index.jsx.html +244 -0
- package/coverage/lcov-report/components/MadieAlert/index.html +116 -0
- package/coverage/lcov-report/components/MadieAlert/index.jsx.html +304 -0
- package/coverage/lcov-report/components/MadieDeleteDialog/index.html +116 -0
- package/coverage/lcov-report/components/MadieDeleteDialog/index.jsx.html +244 -0
- package/coverage/lcov-report/components/MadieDialog/index.html +116 -0
- package/coverage/lcov-report/components/MadieDialog/index.jsx.html +856 -0
- package/coverage/lcov-report/components/MadieDiscardDialog/index.html +116 -0
- package/coverage/lcov-report/components/MadieDiscardDialog/index.jsx.html +232 -0
- package/coverage/lcov-report/components/MadieSpinner/index.html +116 -0
- package/coverage/lcov-report/components/MadieSpinner/index.jsx.html +190 -0
- package/coverage/lcov-report/components/Modal/LegacyModal.jsx.html +307 -0
- package/coverage/lcov-report/components/Modal/index.html +116 -0
- package/coverage/lcov-report/components/Pagination/index.html +116 -0
- package/coverage/lcov-report/components/Pagination/index.jsx.html +736 -0
- package/coverage/lcov-report/components/Popover/index.html +116 -0
- package/coverage/lcov-report/components/Popover/index.js.html +472 -0
- package/coverage/lcov-report/components/ReadOnlyTextField/index.html +116 -0
- package/coverage/lcov-report/components/ReadOnlyTextField/index.jsx.html +313 -0
- package/coverage/lcov-report/components/SanitizedContent/index.html +116 -0
- package/coverage/lcov-report/components/SanitizedContent/index.jsx.html +685 -0
- package/coverage/lcov-report/components/Select/index.html +116 -0
- package/coverage/lcov-report/components/Select/index.jsx.html +610 -0
- package/coverage/lcov-report/components/TextField/index.html +116 -0
- package/coverage/lcov-report/components/TextField/index.jsx.html +496 -0
- package/coverage/lcov-report/components/Toast/index.html +116 -0
- package/coverage/lcov-report/components/Toast/index.jsx.html +430 -0
- package/coverage/lcov-report/components/Tooltip/Tooltip.jsx.html +349 -0
- package/coverage/lcov-report/components/Tooltip/index.html +146 -0
- package/coverage/lcov-report/components/Tooltip/index.js.html +94 -0
- package/coverage/lcov-report/components/Tooltip/position.js.html +313 -0
- package/coverage/lcov-report/index.html +87 -132
- package/coverage/lcov-report/index.js.html +385 -0
- package/coverage/lcov-report/index.jsx.html +417 -129
- package/coverage/lcov-report/lib/Chevron.jsx.html +181 -0
- package/coverage/lcov-report/lib/SvgComponents.jsx.html +1702 -0
- package/coverage/lcov-report/lib/index.html +131 -0
- package/coverage/lcov-report/react/components/Accordion/index.html +21 -21
- package/coverage/lcov-report/react/components/Accordion/index.jsx.html +29 -29
- package/coverage/lcov-report/react/components/Button/index.html +19 -19
- package/coverage/lcov-report/react/components/Button/index.js.html +45 -36
- package/coverage/lcov-report/react/components/Error/Collapsible.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Error/ErrorUI.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Error/error.js.html +1 -1
- package/coverage/lcov-report/react/components/Error/index.html +1 -1
- package/coverage/lcov-report/react/components/Footer/FooterUI.jsx.html +3 -3
- package/coverage/lcov-report/react/components/Footer/LegacyFooterUI.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Footer/footer.js.html +1 -1
- package/coverage/lcov-report/react/components/Footer/index.html +1 -1
- package/coverage/lcov-report/react/components/Infotip/Infotip.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Infotip/InfotipIcon.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Infotip/index.html +1 -1
- package/coverage/lcov-report/react/components/Infotip/index.js.html +1 -1
- package/coverage/lcov-report/react/components/InputLabel/index.html +5 -5
- package/coverage/lcov-report/react/components/InputLabel/index.jsx.html +8 -8
- package/coverage/lcov-report/react/components/MadieAlert/index.html +3 -18
- package/coverage/lcov-report/react/components/MadieAlert/index.jsx.html +76 -43
- package/coverage/lcov-report/react/components/MadieDeleteDialog/index.html +116 -0
- package/coverage/lcov-report/react/components/MadieDeleteDialog/index.jsx.html +244 -0
- package/coverage/lcov-report/react/components/MadieDialog/Index.jsx.html +9 -9
- package/coverage/lcov-report/react/components/MadieDialog/index.html +1 -1
- package/coverage/lcov-report/react/components/MadieDiscardDialog/index.html +1 -1
- package/coverage/lcov-report/react/components/MadieDiscardDialog/index.jsx.html +1 -1
- package/coverage/lcov-report/react/components/MadieSpinner/index.html +1 -1
- package/coverage/lcov-report/react/components/MadieSpinner/index.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Modal/LegacyModal.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Modal/Modal.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Modal/index.html +18 -33
- package/coverage/lcov-report/react/components/Modal/index.jsx.html +9 -21
- package/coverage/lcov-report/react/components/Pagination/index.html +5 -5
- package/coverage/lcov-report/react/components/Pagination/index.jsx.html +62 -23
- package/coverage/lcov-report/react/components/Popover/index.html +116 -0
- package/coverage/lcov-report/react/components/Popover/index.js.html +472 -0
- package/coverage/lcov-report/react/components/ReadOnlyTextField/index.html +1 -1
- package/coverage/lcov-report/react/components/ReadOnlyTextField/index.jsx.html +1 -1
- package/coverage/lcov-report/react/components/SanitizedContent/index.html +1 -1
- package/coverage/lcov-report/react/components/SanitizedContent/index.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Select/index.html +3 -3
- package/coverage/lcov-report/react/components/Select/index.jsx.html +206 -23
- package/coverage/lcov-report/react/components/SessionDialog/index.html +1 -1
- package/coverage/lcov-report/react/components/SessionDialog/sessionDialog.js.html +1 -1
- package/coverage/lcov-report/react/components/SessionDialogUI.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Textfield/index.html +3 -3
- package/coverage/lcov-report/react/components/Textfield/index.jsx.html +198 -9
- package/coverage/lcov-report/react/components/Toast/index.html +9 -9
- package/coverage/lcov-report/react/components/Toast/index.jsx.html +80 -119
- package/coverage/lcov-report/react/components/Tooltip/Tooltip.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Tooltip/index.html +1 -1
- package/coverage/lcov-report/react/components/Tooltip/index.js.html +1 -1
- package/coverage/lcov-report/react/components/Tooltip/position.js.html +1 -1
- package/coverage/lcov-report/react/components/index.html +1 -1
- package/coverage/lcov-report/react/index.html +13 -13
- package/coverage/lcov-report/react/index.js.html +7 -19
- package/coverage/lcov-report/react/lib/Chevron.jsx.html +2 -2
- package/coverage/lcov-report/react/lib/SvgComponents.jsx.html +158 -158
- package/coverage/lcov-report/react/lib/index.html +17 -17
- package/coverage/lcov-report/react/session/index.html +1 -1
- package/coverage/lcov-report/react/session/index.js.html +1 -1
- package/coverage/lcov-report/react/session/logout.js.html +1 -1
- package/coverage/lcov-report/react/session/refresh.js.html +1 -1
- package/coverage/lcov-report/react/session/ttl.js.html +1 -1
- package/coverage/lcov.info +377 -735
- package/dist/browser.js +1 -1
- package/dist/index.js +1 -1
- package/dist/react/index.js +12 -12
- package/dist/react/index.js.map +1 -1
- package/index.js +0 -4
- package/lib/SvgComponents.jsx +1 -1
- package/package.json +1 -1
- package/test/components/Accordion.test.js +21 -4
- package/test/components/Button.test.js +72 -0
- package/test/components/MadieAlert.test.js +1 -2
- package/test/components/MadieDeleteDialog.test.js +3 -1
- package/test/components/MadiePopover.test.js +9 -0
- package/test/components/Pagination.test.js +4 -0
- package/test/components/Select.test.js +37 -0
- package/test/components/TextField.test.js +36 -0
- package/test/lib/SvgComponents.test.js +212 -0
- package/components/Modal/LegacyModal.jsx +0 -74
- package/components/SessionDialog/sessionDialog.js +0 -26
- package/components/SessionDialogUI.jsx +0 -273
- package/session/index.js +0 -5
- package/session/logout.js +0 -65
- package/session/refresh.js +0 -49
- package/session/ttl.js +0 -37
- package/test/components/SessionDialogUI.test.js +0 -347
- package/test/session/session.test.js +0 -221
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import ReactDOM from "react-dom";
|
|
3
|
-
import ReactTestUtils from "react-dom/test-utils";
|
|
4
|
-
import { expect } from "chai";
|
|
5
|
-
import sinon from "sinon";
|
|
6
|
-
import SessionDialogUI from "../../components/SessionDialogUI";
|
|
7
|
-
import * as Modal from "react-modal";
|
|
8
|
-
|
|
9
|
-
// Dependencies to stub out
|
|
10
|
-
import * as refreshModule from "../../session/refresh";
|
|
11
|
-
import * as logoutModule from "../../session/logout";
|
|
12
|
-
|
|
13
|
-
describe("SessionDialogUI", () => {
|
|
14
|
-
// Sample token via: https://github.com/auth0/jwt-decode/blob/master/test/tests.js
|
|
15
|
-
var token =
|
|
16
|
-
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJleHAiOjEzOTMyODY4OTMsImlhdCI6MTM5MzI2ODg5M30.4-iaDojEVl0pJQMjrbM1EzUIfAZgsbK_kgnVyVxFSVo";
|
|
17
|
-
var clock = null;
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
let container = document.querySelector(
|
|
21
|
-
"#qpp-style-session-dialog-container"
|
|
22
|
-
);
|
|
23
|
-
let modal = document.querySelector(".ReactModalPortal");
|
|
24
|
-
clock = sinon.useFakeTimers();
|
|
25
|
-
document.cookie = `qpp_auth_token=${token}`;
|
|
26
|
-
|
|
27
|
-
if (container) {
|
|
28
|
-
container.remove();
|
|
29
|
-
}
|
|
30
|
-
if (modal) {
|
|
31
|
-
modal.remove();
|
|
32
|
-
}
|
|
33
|
-
Modal.setAppElement = jest.fn(() => null);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
afterEach(() => {
|
|
37
|
-
clock.restore();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("closes the dialog when Refresh button is clicked", () => {
|
|
41
|
-
const refreshSpy = sinon.spy(
|
|
42
|
-
SessionDialogUI.prototype,
|
|
43
|
-
"refreshSession"
|
|
44
|
-
);
|
|
45
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
46
|
-
<SessionDialogUI
|
|
47
|
-
showImmediate={true}
|
|
48
|
-
startTimer={sinon.spy()}
|
|
49
|
-
appElement="body"
|
|
50
|
-
/>
|
|
51
|
-
);
|
|
52
|
-
const refresh = sinon
|
|
53
|
-
.stub(refreshModule, "default")
|
|
54
|
-
.yieldsTo("onSuccess");
|
|
55
|
-
|
|
56
|
-
sinon.spy(dialog, "startTimer");
|
|
57
|
-
sinon.spy(dialog, "handleCloseModal");
|
|
58
|
-
|
|
59
|
-
const button = document.querySelector(
|
|
60
|
-
"[data-testid='modal-primary-btn']"
|
|
61
|
-
);
|
|
62
|
-
ReactTestUtils.Simulate.click(button);
|
|
63
|
-
|
|
64
|
-
expect(refreshSpy.calledOnce).to.be.true;
|
|
65
|
-
expect(refresh.calledOnce).to.be.true;
|
|
66
|
-
expect(dialog.handleCloseModal.calledOnce).to.be.true;
|
|
67
|
-
expect(dialog.startTimer.calledOnce).to.be.true;
|
|
68
|
-
|
|
69
|
-
refreshSpy.restore();
|
|
70
|
-
dialog.startTimer.restore();
|
|
71
|
-
dialog.handleCloseModal.restore();
|
|
72
|
-
refresh.restore();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("closes the dialog when Sign Out button is clicked", () => {
|
|
76
|
-
const signOutSpy = sinon.spy(SessionDialogUI.prototype, "signOut");
|
|
77
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
78
|
-
<SessionDialogUI
|
|
79
|
-
showImmediate={true}
|
|
80
|
-
startTimer={sinon.spy()}
|
|
81
|
-
appElement="body"
|
|
82
|
-
/>
|
|
83
|
-
);
|
|
84
|
-
const logout = sinon.stub(logoutModule, "default");
|
|
85
|
-
|
|
86
|
-
sinon.spy(dialog, "handleCloseModal");
|
|
87
|
-
|
|
88
|
-
const button = document.querySelector(
|
|
89
|
-
"[data-testid='modal-secondary-btn']"
|
|
90
|
-
);
|
|
91
|
-
ReactTestUtils.Simulate.click(button);
|
|
92
|
-
|
|
93
|
-
expect(signOutSpy.calledOnce).to.be.true;
|
|
94
|
-
expect(dialog.handleCloseModal.calledOnce).to.be.true;
|
|
95
|
-
expect(logout.calledOnce).to.be.true;
|
|
96
|
-
|
|
97
|
-
signOutSpy.restore();
|
|
98
|
-
dialog.handleCloseModal.restore();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("renders the dialog HTML", () => {
|
|
102
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
103
|
-
<SessionDialogUI
|
|
104
|
-
showImmediate={true}
|
|
105
|
-
startTimer={sinon.spy()}
|
|
106
|
-
appElement="body"
|
|
107
|
-
/>
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
dialog.handleOpenModal();
|
|
111
|
-
|
|
112
|
-
// The dialog gets rendered as a sibling of the composite
|
|
113
|
-
// component, so check for it in the document instead
|
|
114
|
-
const node = document.querySelector(".ReactModal__Overlay");
|
|
115
|
-
|
|
116
|
-
expect(node).to.exist;
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("has a default warningTimeout of 2 minutes", () => {
|
|
120
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
121
|
-
<SessionDialogUI appElement="body" />
|
|
122
|
-
);
|
|
123
|
-
expect(dialog.props).to.have.property("warningTimeout", 2);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("warningTimeout can be set to a different number", () => {
|
|
127
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
128
|
-
<SessionDialogUI warningTimeout={666} appElement="body" />
|
|
129
|
-
);
|
|
130
|
-
expect(dialog.props).to.have.property("warningTimeout", 666);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("calls #startTimer by default", () => {
|
|
134
|
-
const spy = sinon.spy(SessionDialogUI.prototype, "startTimer");
|
|
135
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
136
|
-
<SessionDialogUI appElement="body" />
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
expect(spy.calledOnce).to.be.true;
|
|
140
|
-
expect(dialog.state.showModal).to.be.false;
|
|
141
|
-
spy.restore();
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("bypasses #startTimer if showImmediate is true", () => {
|
|
145
|
-
const spy = sinon.spy(SessionDialogUI.prototype, "startTimer");
|
|
146
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
147
|
-
<SessionDialogUI showImmediate={true} appElement="body" />
|
|
148
|
-
);
|
|
149
|
-
expect(spy.called).to.be.false;
|
|
150
|
-
expect(dialog.state.showModal).to.be.true;
|
|
151
|
-
spy.restore();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
describe("#shouldShowDialog", () => {
|
|
155
|
-
it("time_remaining returns true within warning timeout", () => {
|
|
156
|
-
let expiry = 1800; // 30 minutes reminaing
|
|
157
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
158
|
-
<SessionDialogUI appElement="body" />
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
expect(dialog.shouldShowDialog(expiry)).to.be.false;
|
|
162
|
-
|
|
163
|
-
// 2 minutes remaining
|
|
164
|
-
expiry = 120;
|
|
165
|
-
|
|
166
|
-
expect(dialog.shouldShowDialog(expiry)).to.be.true;
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("ttl returns true within warning timeout", () => {
|
|
170
|
-
const now = new Date().getTime();
|
|
171
|
-
// Set session expiration 30 minutes from now
|
|
172
|
-
const expiry = new Date(now + 30 * 60000);
|
|
173
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
174
|
-
<SessionDialogUI appElement="body" />
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
expect(dialog.shouldShowDialog(expiry)).to.be.false;
|
|
178
|
-
|
|
179
|
-
// Advance clock 28 minutes
|
|
180
|
-
clock.tick(28 * 60000);
|
|
181
|
-
|
|
182
|
-
expect(dialog.shouldShowDialog(expiry)).to.be.true;
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it("time_remaining works with custom warningTimeout", () => {
|
|
186
|
-
let expiry = 1800; // 30 minutes remaining
|
|
187
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
188
|
-
<SessionDialogUI warningTimeout={0.25} appElement="body" /> // 15 seconds warning
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
expect(dialog.shouldShowDialog(expiry)).to.be.false;
|
|
192
|
-
|
|
193
|
-
// At 2 minutes remaining, should still be false
|
|
194
|
-
expiry = 120;
|
|
195
|
-
expect(dialog.shouldShowDialog(expiry)).to.be.false;
|
|
196
|
-
|
|
197
|
-
// At 15 seconds left
|
|
198
|
-
expiry = 15;
|
|
199
|
-
expect(dialog.shouldShowDialog(expiry)).to.be.true;
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it("ttl works with custom warningTimeout", () => {
|
|
203
|
-
const now = new Date().getTime();
|
|
204
|
-
// Set session expiration 4 minutes from now
|
|
205
|
-
const expiry = new Date(now + 4 * 60000);
|
|
206
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
207
|
-
<SessionDialogUI warningTimeout={0.25} appElement="body" />
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
expect(dialog.shouldShowDialog(expiry)).to.be.false;
|
|
211
|
-
|
|
212
|
-
// Advance clock 2 minutes, should still be false
|
|
213
|
-
clock.tick(120000);
|
|
214
|
-
expect(dialog.shouldShowDialog(expiry)).to.be.false;
|
|
215
|
-
|
|
216
|
-
// Advance clock another 00:01:45, to have 15 seconds left
|
|
217
|
-
clock.tick(105000);
|
|
218
|
-
expect(dialog.shouldShowDialog(expiry)).to.be.true;
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
describe("#shouldSignOut", () => {
|
|
223
|
-
it("returns true when time_remaining expiration is up", () => {
|
|
224
|
-
let expiry = 1800; // 30 minutes remaining
|
|
225
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
226
|
-
<SessionDialogUI appElement="body" />
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
// 1 minute remaining
|
|
230
|
-
expiry = 60;
|
|
231
|
-
expect(dialog.shouldSignOut(expiry)).to.be.false;
|
|
232
|
-
|
|
233
|
-
// 0 minutes remaining
|
|
234
|
-
expiry = 0;
|
|
235
|
-
expect(dialog.shouldSignOut(expiry)).to.be.true;
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it("returns true when time_remaining within threshold", () => {
|
|
239
|
-
let expiry = 1800; // 30 minutes remaining
|
|
240
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
241
|
-
<SessionDialogUI appElement="body" />
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
// 1 minute remaining
|
|
245
|
-
expiry = 60;
|
|
246
|
-
expect(dialog.shouldSignOut(expiry)).to.be.false;
|
|
247
|
-
|
|
248
|
-
// 1 second remaining
|
|
249
|
-
expiry = 1;
|
|
250
|
-
expect(dialog.shouldSignOut(expiry)).to.be.true;
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it("returns true when ttl expiration is up", () => {
|
|
254
|
-
const now = new Date().getTime();
|
|
255
|
-
// Set session expiration 30 minutes from now
|
|
256
|
-
const expiry = new Date(now + 30 * 60000);
|
|
257
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
258
|
-
<SessionDialogUI appElement="body" />
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
// Advance clock 29 minutes
|
|
262
|
-
clock.tick(29 * 60000);
|
|
263
|
-
expect(dialog.shouldSignOut(expiry)).to.be.false;
|
|
264
|
-
|
|
265
|
-
// Advance clock 1 more minute
|
|
266
|
-
clock.tick(60000);
|
|
267
|
-
expect(dialog.shouldSignOut(expiry)).to.be.true;
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
describe("#minutesUntil", () => {
|
|
272
|
-
it("#minutesUntil returns minutes until the time provided", () => {
|
|
273
|
-
const now = new Date().getTime();
|
|
274
|
-
// Set session expiration 30 minutes from now
|
|
275
|
-
const expiry = new Date(now + 30 * 60000);
|
|
276
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
277
|
-
<SessionDialogUI appElement="body" />
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
// Advance clock 15 minutes
|
|
281
|
-
clock.tick(15 * 60000);
|
|
282
|
-
|
|
283
|
-
expect(dialog.minutesUntil(expiry)).to.equal(15);
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
describe("#getTokenExpiry", () => {
|
|
288
|
-
it("extracts exp from token cookie and returns a date", () => {
|
|
289
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
290
|
-
<SessionDialogUI showImmediate={true} appElement="body" />
|
|
291
|
-
);
|
|
292
|
-
const cookies = {
|
|
293
|
-
qpp_auth_token: token,
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
const expected = 1393286893 * 1000;
|
|
297
|
-
const actual = dialog.getTokenExpiry(cookies);
|
|
298
|
-
|
|
299
|
-
expect(actual.getTime()).to.equal(expected);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it("returns null when the cookie is nonexistent", () => {
|
|
303
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
304
|
-
<SessionDialogUI showImmediate={true} appElement="body" />
|
|
305
|
-
);
|
|
306
|
-
const cookies = {};
|
|
307
|
-
|
|
308
|
-
const actual = dialog.getTokenExpiry(cookies);
|
|
309
|
-
|
|
310
|
-
expect(actual).to.be.null;
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
describe("#startTimer", () => {
|
|
315
|
-
it("interval will be cleared if expiry is falsy", () => {
|
|
316
|
-
const spy = sinon.spy(SessionDialogUI.prototype, "startTimer");
|
|
317
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
318
|
-
<SessionDialogUI showImmediate={true} appElement="body" />
|
|
319
|
-
);
|
|
320
|
-
|
|
321
|
-
document.cookie =
|
|
322
|
-
"qpp_auth_token=; expires=Thu, 1 Jan 1970 00:00:01 GMT";
|
|
323
|
-
|
|
324
|
-
dialog.startTimer();
|
|
325
|
-
|
|
326
|
-
clock.tick(120000);
|
|
327
|
-
|
|
328
|
-
expect(spy.calledOnce).to.be.true;
|
|
329
|
-
expect(spy.calledTwice).to.be.false;
|
|
330
|
-
spy.restore();
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it("sets a warningInterval if given an expiration date", () => {
|
|
334
|
-
const dialog = ReactTestUtils.renderIntoDocument(
|
|
335
|
-
<SessionDialogUI showImmediate={true} appElement="body" />
|
|
336
|
-
);
|
|
337
|
-
const expiry = new Date(1393286893 * 1000);
|
|
338
|
-
|
|
339
|
-
dialog.startTimer(expiry);
|
|
340
|
-
|
|
341
|
-
// Sinon's fake timer seems to return an object from setInterval
|
|
342
|
-
// instead of a number. This may break if that bug gets fixed.
|
|
343
|
-
// expect(dialog.warningInterval).to.be.a('number');
|
|
344
|
-
expect(dialog.warningInterval).to.be.a("number");
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
});
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import moxios from "moxios";
|
|
2
|
-
import sinon from "sinon";
|
|
3
|
-
import { fetchTtl, RefreshSession, LogoutSession } from "../../session";
|
|
4
|
-
|
|
5
|
-
describe("Session management", () => {
|
|
6
|
-
describe("Fetch TTL", () => {
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
moxios.install();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
moxios.uninstall();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test("handles a successful fetch for time_remaining", (done) => {
|
|
16
|
-
const exp = 1393286893;
|
|
17
|
-
const date = new Date(exp * 1000);
|
|
18
|
-
const remaining = 240000;
|
|
19
|
-
|
|
20
|
-
moxios.stubRequest("/api/auth/sessions/ttl", {
|
|
21
|
-
status: 200,
|
|
22
|
-
responseText: JSON.stringify({
|
|
23
|
-
data: {
|
|
24
|
-
ttl: exp,
|
|
25
|
-
time_remaining: remaining,
|
|
26
|
-
},
|
|
27
|
-
}),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
fetchTtl("fakeToken").then((expiry) => {
|
|
31
|
-
expect(expiry).toBe(remaining);
|
|
32
|
-
done();
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test("handles backward-compat fetch for TTL", (done) => {
|
|
37
|
-
const exp = 1393286893;
|
|
38
|
-
const date = new Date(exp * 1000);
|
|
39
|
-
|
|
40
|
-
moxios.stubRequest("/api/auth/sessions/ttl", {
|
|
41
|
-
status: 200,
|
|
42
|
-
responseText: JSON.stringify({
|
|
43
|
-
data: {
|
|
44
|
-
ttl: exp,
|
|
45
|
-
},
|
|
46
|
-
}),
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
fetchTtl("fakeToken").then((expiry) => {
|
|
50
|
-
expect(expiry.getTime()).toBe(date.getTime());
|
|
51
|
-
done();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("throws an error on 400", (done) => {
|
|
56
|
-
moxios.stubRequest("/api/auth/sessions/ttl", {
|
|
57
|
-
status: 400,
|
|
58
|
-
responseText: JSON.stringify({
|
|
59
|
-
error: "error text",
|
|
60
|
-
}),
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
fetchTtl("fakeToken").catch((error) => {
|
|
64
|
-
expect(error.response.status).toBe(400);
|
|
65
|
-
done();
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe("Logout session", () => {
|
|
71
|
-
beforeEach(() => {
|
|
72
|
-
moxios.install();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
afterEach(() => {
|
|
76
|
-
moxios.uninstall();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("Handles a successful logout", (done) => {
|
|
80
|
-
window.document.cookie = "qpp_auth_token=testing";
|
|
81
|
-
|
|
82
|
-
moxios.stubRequest("/user/session-logout", {
|
|
83
|
-
status: 200,
|
|
84
|
-
responseText: "Hello",
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
let onFulfilled = sinon.spy();
|
|
88
|
-
let onFailed = sinon.spy();
|
|
89
|
-
|
|
90
|
-
Promise.resolve(LogoutSession(window))
|
|
91
|
-
.then(() => {
|
|
92
|
-
expect(onFulfilled.called).toBe(true);
|
|
93
|
-
expect(onFailed.called).toBe(false);
|
|
94
|
-
})
|
|
95
|
-
.catch((error) => {
|
|
96
|
-
done();
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("Handles a 400 Response on logout", (done) => {
|
|
101
|
-
window.document.cookie = "qpp_auth_token=testing";
|
|
102
|
-
|
|
103
|
-
moxios.stubRequest("/user/session-logout", {
|
|
104
|
-
status: 400,
|
|
105
|
-
responseText: "Hello",
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
let onFulfilled = sinon.spy();
|
|
109
|
-
let onFailed = sinon.spy();
|
|
110
|
-
|
|
111
|
-
Promise.resolve(LogoutSession(window))
|
|
112
|
-
.then(() => {
|
|
113
|
-
expect(onFulfilled.called).toBe(false);
|
|
114
|
-
expect(onFailed.called).toBe(true);
|
|
115
|
-
})
|
|
116
|
-
.catch((error) => {
|
|
117
|
-
done();
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("Handles a 401 Response on logout", (done) => {
|
|
122
|
-
window.document.cookie = "qpp_auth_token=testing";
|
|
123
|
-
|
|
124
|
-
moxios.stubRequest("/user/session-logout", {
|
|
125
|
-
status: 401,
|
|
126
|
-
responseText: "Hello",
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
let onFulfilled = sinon.spy();
|
|
130
|
-
let onFailed = sinon.spy();
|
|
131
|
-
|
|
132
|
-
Promise.resolve(LogoutSession(window))
|
|
133
|
-
.then(() => {
|
|
134
|
-
expect(onFulfilled.called).toBe(false);
|
|
135
|
-
expect(onFailed.called).toBe(true);
|
|
136
|
-
})
|
|
137
|
-
.catch((error) => {
|
|
138
|
-
done();
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe("Refresh session", () => {
|
|
144
|
-
beforeEach(() => {
|
|
145
|
-
moxios.install();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
afterEach(() => {
|
|
149
|
-
moxios.uninstall();
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test("Handles a successful refresh", () => {
|
|
153
|
-
window.document.cookie = "qpp_auth_token=testing";
|
|
154
|
-
|
|
155
|
-
moxios.stubRequest("/api/auth/sessions/refresh", {
|
|
156
|
-
status: 200,
|
|
157
|
-
responseText: "Hello",
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
let onFulfilled = sinon.spy();
|
|
161
|
-
let onFailed = sinon.spy();
|
|
162
|
-
|
|
163
|
-
Promise.resolve(
|
|
164
|
-
RefreshSession({
|
|
165
|
-
onSuccess: onFulfilled,
|
|
166
|
-
onError: onFailed,
|
|
167
|
-
window: window,
|
|
168
|
-
})
|
|
169
|
-
).then(() => {
|
|
170
|
-
expect(onFulfilled.called).toBe(true);
|
|
171
|
-
expect(onFailed.called).toBe(false);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
test("Handles a 400 response on refresh", () => {
|
|
176
|
-
window.document.cookie = "qpp_auth_token=testing";
|
|
177
|
-
|
|
178
|
-
moxios.stubRequest("/api/auth/sessions/refresh", {
|
|
179
|
-
status: 400,
|
|
180
|
-
responseText: "Hello",
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
let onFulfilled = sinon.spy();
|
|
184
|
-
let onFailed = sinon.spy();
|
|
185
|
-
|
|
186
|
-
Promise.resolve(
|
|
187
|
-
RefreshSession({
|
|
188
|
-
onSuccess: onFulfilled,
|
|
189
|
-
onError: onFailed,
|
|
190
|
-
window,
|
|
191
|
-
})
|
|
192
|
-
).then(() => {
|
|
193
|
-
expect(onFulfilled.called).toBe(false);
|
|
194
|
-
expect(onFailed.called).toBe(true);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test("Handles a 401 response on refresh", () => {
|
|
199
|
-
window.document.cookie = "qpp_auth_token=testing";
|
|
200
|
-
|
|
201
|
-
moxios.stubRequest("/api/auth/sessions/refresh", {
|
|
202
|
-
status: 401,
|
|
203
|
-
responseText: "Hello",
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
let onFulfilled = sinon.spy();
|
|
207
|
-
let onFailed = sinon.spy();
|
|
208
|
-
|
|
209
|
-
Promise.resolve(
|
|
210
|
-
RefreshSession({
|
|
211
|
-
onSuccess: onFulfilled,
|
|
212
|
-
onError: onFailed,
|
|
213
|
-
window,
|
|
214
|
-
})
|
|
215
|
-
).then(() => {
|
|
216
|
-
expect(onFulfilled.called).toBe(false);
|
|
217
|
-
expect(onFailed.called).toBe(true);
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
});
|