Skip to content

Commit 38e8dc2

Browse files
authored
fix jest tests (#645)
* fix jest tests * fix logout test
1 parent 8ecfa76 commit 38e8dc2

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

test/localStorage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import storage from './storage.json';
22

33
export default class LocalStorage {
44
constructor() {
5-
this.store = storage;
5+
this.store = JSON.parse(JSON.stringify(storage));
66
}
77

88
clear() {

test/messages/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import messageSyncBody from 'ringcentral-integration/integration-test/mock/data/
22
import subscriptionBody from 'ringcentral-integration/integration-test/mock/data/subscription.json';
33
import pubnubMsg from 'ringcentral-integration/integration-test/mock/data/pubnub.json';
44
import * as mock from 'ringcentral-integration/integration-test/mock';
5-
import { getWrapper, timeout } from '../shared';
5+
import { timeout } from '../shared';
66
import * as MockedPubNub from '../__mocks__/pubnub.js';
77

88
export async function mockPubnub() {

test/navigation/DynamicNavigations.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('dynamic navigationb bar', () => {
2626
hasComposeTextPermission: { value: true },
2727
permissions: {
2828
value: {
29-
...phone.rolesAndPermissions,
29+
...phone.rolesAndPermissions.permissions,
3030
ReadCallLog: true,
3131
OrganizeConference: true,
3232
Meetings: true
@@ -48,7 +48,7 @@ describe('dynamic navigationb bar', () => {
4848
callingEnabled: { value: false },
4949
hasReadMessagesPermission: { value: false },
5050
hasComposeTextPermission: { value: false },
51-
})
51+
});
5252
wrapper.setProps({ phone });
5353
wrapper.update();
5454
const navigationBar = wrapper.find(NavigationBar).first();
@@ -118,7 +118,7 @@ describe('dynamic navigationb bar', () => {
118118
hasComposeTextPermission: { value: false },
119119
permissions: {
120120
value: {
121-
...phone.rolesAndPermissions,
121+
...phone.rolesAndPermissions.permissions,
122122
ReadCallLog: false,
123123
OrganizeConference: true,
124124
Meetings: false
@@ -139,7 +139,7 @@ describe('dynamic navigationb bar', () => {
139139
hasComposeTextPermission: { value: false },
140140
permissions: {
141141
value: {
142-
...phone.rolesAndPermissions,
142+
...phone.rolesAndPermissions.permissions,
143143
ReadCallLog: false,
144144
OrganizeConference: false,
145145
Meetings: false

test/settings/Settings.spec.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as mock from 'ringcentral-integration/integration-test/mock';
2-
import presenceBody from 'ringcentral-integration/integration-test/mock/data/presence';
32
import { getWrapper, timeout } from '../shared';
43
import SettingsPanel from '../../src/components/SettingsPanel';
54
import LinkLine from '../../src/components/LinkLine';
@@ -9,21 +8,19 @@ import PresenceItem from '../../src/components/PresenceItem';
98
import Eula from '../../src/components/Eula';
109
import NavigationBar from '../../src/components/NavigationBar';
1110

12-
let wrapper = null;
13-
let store = null;
14-
let panel = null;
15-
beforeEach(async () => {
11+
const setupWrapper = async () => {
1612
jasmine.DEFAULT_TIMEOUT_INTERVAL = 64000;
17-
wrapper = await getWrapper();
18-
store = wrapper.props().phone.store;
13+
const wrapper = await getWrapper();
1914
const navigationBar = wrapper.find(NavigationBar).first();
2015
await navigationBar.props().goTo('/settings');
2116
wrapper.update();
22-
panel = wrapper.find(SettingsPanel).first();
23-
});
17+
return wrapper;
18+
};
2419

2520
describe('settings panel', () => {
26-
test('initial state', () => {
21+
test('initial state', async () => {
22+
const wrapper = await setupWrapper();
23+
let panel = wrapper.find(SettingsPanel).first();
2724
const linkLines = panel.find(LinkLine);
2825
expect(linkLines.length).toBe(5);
2926
expect(linkLines.at(0).props().children).toEqual('Calling');
@@ -36,21 +33,25 @@ describe('settings panel', () => {
3633
});
3734

3835
test('logout', async () => {
36+
const storage = JSON.parse(JSON.stringify(localStorage.store));
37+
const wrapper = await setupWrapper();
38+
let panel = wrapper.find(SettingsPanel).first();
3939
const logoutIcon = panel.find('span.logout').first();
4040
const logoutLines = logoutIcon.closest(IconLine);
4141
expect(logoutLines.length).toBe(1);
4242
const logoutLine = logoutLines.at(0);
43+
const store = wrapper.props().phone.store;
4344
expect(store.getState().auth.loginStatus).toMatch(/-loggedIn$/);
4445
await logoutLine.props().onClick();
4546
expect(store.getState().auth.loginStatus).toMatch(/-loggingOut$/);
46-
47-
// need to login again, otherwise other tests will fail
48-
window.authData = null; // set it to null will trigger login
47+
localStorage.store = JSON.parse(JSON.stringify(storage));
4948
});
5049

5150
test('change presence status', async () => {
51+
const wrapper = await setupWrapper();
52+
let panel = wrapper.find(SettingsPanel).first();
5253
let presenceSettingSection = panel.find(PresenceSettingSection).first();
53-
54+
const store = wrapper.props().phone.store;
5455
const presenceItems = presenceSettingSection.find('.presenceList').first().find(PresenceItem);
5556
expect(presenceItems.length).toBe(4);
5657
const availableItem = presenceItems.at(0);

test/shared.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const getPhone = async () => {
3737
password: 'testPassword'
3838
});
3939
state.storage.status = 'module-initializing';
40-
const store = createStore(phone.reducer, state);
40+
const store = createStore(phone.reducer, JSON.parse(JSON.stringify(state)));
4141
phone.setStore(store);
4242
phone.dateTimeFormat._defaultFormatter = getIntlDateTimeFormatter();
4343
return phone;

0 commit comments

Comments
 (0)