Skip to content

Commit 8d2097d

Browse files
committed
test: update tests, update tour tests
1 parent 04a01de commit 8d2097d

24 files changed

+144
-85
lines changed

public/app/config/channels.js

+1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ module.exports = {
7676
COMPLETE_TOUR_CHANNEL: 'tour:complete',
7777
GET_APP_UPGRADE_CHANNEL: 'app:upgrade:get',
7878
INSTALL_APP_UPGRADE_CHANNEL: 'app:upgrade:install',
79+
GET_TOURS_ENABLED_CHANNEL: 'tour:enabled:get',
7980
};

public/app/config/config.js

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const ACTIONS_VERBS = {
9696
LOGOUT: 'logout',
9797
};
9898

99+
const DEFAULT_TOURS_ENABLED = true;
100+
99101
const buildFilePath = ({ userId, spaceId, name }) => {
100102
// add generated id to handle duplicate files
101103
const generatedId = ObjectId().str;
@@ -131,4 +133,5 @@ module.exports = {
131133
buildFilePath,
132134
PREPACKAGED_APPS_FOLDER_NAME,
133135
APPS_FOLDER,
136+
DEFAULT_TOURS_ENABLED,
134137
};
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { DEFAULT_TOURS_ENABLED } = require('../config/config');
2+
const { GET_TOURS_ENABLED_CHANNEL } = require('../config/channels');
3+
const logger = require('../logger');
4+
const { ERROR_GENERAL } = require('../config/errors');
5+
6+
const getToursEnabled = (mainWindow) => async () => {
7+
try {
8+
const enabled =
9+
'SHOW_TOURS' in process.env
10+
? process.env.SHOW_TOURS === 'true'
11+
: DEFAULT_TOURS_ENABLED;
12+
mainWindow.webContents.send(GET_TOURS_ENABLED_CHANNEL, enabled);
13+
} catch (e) {
14+
logger.error(e);
15+
mainWindow.webContents.send(GET_TOURS_ENABLED_CHANNEL, ERROR_GENERAL);
16+
}
17+
};
18+
19+
module.exports = getToursEnabled;

public/app/listeners/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const postFile = require('./postFile');
5656
const deleteFile = require('./deleteFile');
5757
const installAppUpgrade = require('./installAppUpgrade');
5858
const getAppUpgrade = require('./getAppUpgrade');
59+
const getToursEnabled = require('./getToursEnabled');
5960

6061
module.exports = {
6162
loadSpace,
@@ -115,4 +116,5 @@ module.exports = {
115116
deleteFile,
116117
installAppUpgrade,
117118
getAppUpgrade,
119+
getToursEnabled,
118120
};

public/electron.js

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const {
8484
DELETE_FILE_CHANNEL,
8585
GET_APP_UPGRADE_CHANNEL,
8686
INSTALL_APP_UPGRADE_CHANNEL,
87+
GET_TOURS_ENABLED_CHANNEL,
8788
} = require('./app/config/channels');
8889
const env = require('./env.json');
8990
const {
@@ -143,6 +144,7 @@ const {
143144
deleteFile,
144145
installAppUpgrade,
145146
getAppUpgrade,
147+
getToursEnabled,
146148
} = require('./app/listeners');
147149
const isMac = require('./app/utils/isMac');
148150

@@ -600,6 +602,9 @@ app.on('ready', async () => {
600602
getSpaceInClassroom(mainWindow, db)
601603
);
602604

605+
// called when getting tours enabled
606+
ipcMain.on(GET_TOURS_ENABLED_CHANNEL, getToursEnabled(mainWindow, db));
607+
603608
// called when getting the database
604609
ipcMain.on(GET_DATABASE_CHANNEL, async () => {
605610
try {

src/actions/tour.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { COMPLETE_TOUR_CHANNEL } from '../config/channels';
1+
import {
2+
COMPLETE_TOUR_CHANNEL,
3+
GET_TOURS_ENABLED_CHANNEL,
4+
} from '../config/channels';
25
import { ERROR_GENERAL } from '../config/errors';
36
import {
47
INITIALIZE_TOUR,
@@ -9,6 +12,7 @@ import {
912
RESTART_TOUR,
1013
START_TOUR,
1114
STOP_TOUR,
15+
GET_TOURS_ENABLED_SUCCESS,
1216
} from '../types/tour';
1317

1418
const goToNextStep = (payload) => (dispatch) =>
@@ -63,10 +67,35 @@ const completeTour = async (tourName) => (dispatch) => {
6367
window.ipcRenderer.send(COMPLETE_TOUR_CHANNEL, { tourName });
6468
window.ipcRenderer.once(COMPLETE_TOUR_CHANNEL, async (event, error) => {
6569
if (error === ERROR_GENERAL) {
70+
// eslint-disable-next-line no-console
6671
console.error(error);
6772
}
6873
});
6974
} catch (e) {
75+
// eslint-disable-next-line no-console
76+
console.error(e);
77+
}
78+
};
79+
80+
const getToursEnabled = async (tourName) => (dispatch) => {
81+
try {
82+
window.ipcRenderer.send(GET_TOURS_ENABLED_CHANNEL, { tourName });
83+
window.ipcRenderer.once(
84+
GET_TOURS_ENABLED_CHANNEL,
85+
async (event, payload) => {
86+
if (payload === ERROR_GENERAL) {
87+
// eslint-disable-next-line no-console
88+
console.error(payload);
89+
} else {
90+
dispatch({
91+
type: GET_TOURS_ENABLED_SUCCESS,
92+
payload,
93+
});
94+
}
95+
}
96+
);
97+
} catch (e) {
98+
// eslint-disable-next-line no-console
7099
console.error(e);
71100
}
72101
};
@@ -81,4 +110,5 @@ export {
81110
resetTour,
82111
completeTour,
83112
initializeTour,
113+
getToursEnabled,
84114
};

src/components/common/Tour.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
goToNextStep,
1414
resetTour,
1515
startTour,
16+
getToursEnabled,
1617
} from '../../actions';
1718
import { HOME_PATH, SETTINGS_PATH, VISIT_PATH } from '../../config/paths';
1819
import {
@@ -50,7 +51,8 @@ export class Tour extends Component {
5051
dispatchCompleteTour: PropTypes.func.isRequired,
5152
dispatchResetTour: PropTypes.func.isRequired,
5253
dispatchInitializeTour: PropTypes.func.isRequired,
53-
tourKey: PropTypes.string.isRequired,
54+
tourKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
55+
.isRequired,
5456
currentTour: PropTypes.oneOf(Object.values(tours)).isRequired,
5557
run: PropTypes.bool.isRequired,
5658
continuous: PropTypes.bool.isRequired,
@@ -75,8 +77,15 @@ export class Tour extends Component {
7577
push: PropTypes.func.isRequired,
7678
}).isRequired,
7779
t: PropTypes.func.isRequired,
80+
showTours: PropTypes.bool.isRequired,
81+
dispatchGetToursEnabled: PropTypes.func.isRequired,
7882
};
7983

84+
componentDidMount() {
85+
const { dispatchGetToursEnabled } = this.props;
86+
dispatchGetToursEnabled();
87+
}
88+
8089
componentDidUpdate(prevProps) {
8190
const {
8291
signInActivity,
@@ -145,7 +154,13 @@ export class Tour extends Component {
145154
dispatchCompleteTour,
146155
currentTour,
147156
t,
157+
showTours,
148158
} = this.props;
159+
160+
if (!showTours) {
161+
return null;
162+
}
163+
149164
const callback = async (data) => {
150165
const { action, index, type, status } = data;
151166
if (
@@ -255,6 +270,7 @@ export class Tour extends Component {
255270
}
256271

257272
const mapStateToProps = ({ tour, authentication }) => ({
273+
showTours: tour.getIn(['enabled']),
258274
tourKey: tour.getIn(['key']),
259275
currentTour: tour.getIn(['tour']),
260276
run: tour.getIn(['run']),
@@ -275,6 +291,7 @@ const mapDispatchToProps = {
275291
dispatchCompleteTour: completeTour,
276292
dispatchResetTour: resetTour,
277293
dispatchInitializeTour: initializeTour,
294+
dispatchGetToursEnabled: getToursEnabled,
278295
};
279296

280297
const ConnectedComponent = connect(mapStateToProps, mapDispatchToProps)(Tour);

src/config/channels.js

+1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ module.exports = {
7676
DELETE_FILE_CHANNEL: 'file:delete',
7777
GET_APP_UPGRADE_CHANNEL: 'app:upgrade:get',
7878
INSTALL_APP_UPGRADE_CHANNEL: 'app:upgrade:install',
79+
GET_TOURS_ENABLED_CHANNEL: 'tour:enabled:get',
7980
};

src/config/constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,5 @@ export const TOUR_DELAY_500 = 500;
135135
export const TOUR_Z_INDEX = 10000;
136136
export const TOUR_SPACE = 'owozgj';
137137
export const EXAMPLE_VISIT_SPACE_LINK = `/space/${TOUR_SPACE}`;
138+
139+
export const DEFAULT_TOURS_ENABLED = true;

src/reducers/tour.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import {
88
RESTART_TOUR,
99
START_TOUR,
1010
STOP_TOUR,
11+
GET_TOURS_ENABLED_SUCCESS,
1112
} from '../types/tour';
1213
import { tours, VISIT_SPACE_TOUR_STEPS } from '../config/tours';
14+
import { DEFAULT_TOURS_ENABLED } from '../config/constants';
1315

1416
const INITIAL_STATE = Map({
1517
key: 0, // This field makes the tour to re-render when we restart the tour
@@ -18,6 +20,7 @@ const INITIAL_STATE = Map({
1820
stepIndex: 0, // Make the component controlled
1921
tour: tours.VISIT_SPACE_TOUR,
2022
steps: VISIT_SPACE_TOUR_STEPS,
23+
enabled: DEFAULT_TOURS_ENABLED,
2124
});
2225

2326
export default (state = INITIAL_STATE, { type, payload }) => {
@@ -48,7 +51,8 @@ export default (state = INITIAL_STATE, { type, payload }) => {
4851
.setIn(['tour'], payload.tour)
4952
.setIn(['steps'], payload.steps)
5053
.setIn(['key'], new Date().toISOString());
51-
54+
case GET_TOURS_ENABLED_SUCCESS:
55+
return state.setIn(['enabled'], payload);
5256
default:
5357
return state;
5458
}

src/types/tour.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export const RESTART_TOUR = 'RESTART_TOUR';
66
export const START_TOUR = 'START_TOUR';
77
export const RESET_TOUR = 'RESET_TOUR';
88
export const INITIALIZE_TOUR = 'INITIALIZE_TOUR';
9+
export const GET_TOURS_ENABLED_SUCCESS = 'GET_TOURS_ENABLED_SUCCESS';

test/application.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const createApplication = async (
77
showMessageDialogResponse,
88
showSaveDialogResponse,
99
showOpenDialogResponse,
10+
showTours,
1011
} = {
1112
showMessageDialogResponse: undefined,
1213
showSaveDialogResponse: undefined,
1314
showOpenDialogResponse: undefined,
15+
showTours: 0,
1416
}
1517
) => {
16-
const env = { NODE_ENV: 'test', ELECTRON_IS_DEV: 0 };
18+
const env = { NODE_ENV: 'test', ELECTRON_IS_DEV: 0, SHOW_TOURS: showTours };
1719

1820
if (showMessageDialogResponse !== undefined) {
1921
env.SHOW_MESSAGE_DIALOG_RESPONSE = showMessageDialogResponse;
@@ -52,7 +54,7 @@ const createApplication = async (
5254

5355
await app.start();
5456

55-
app.client.addCommand('getUserDataPath', function () {
57+
app.client.addCommand('getUserDataPath', () => {
5658
return path.join(app.client.capabilities.chrome.userDataDir, 'var');
5759
});
5860

test/classrooms.test.js

-13
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ import {
6666
OPEN_CLASSROOM_PAUSE,
6767
TOOLTIP_FADE_OUT_PAUSE,
6868
LOAD_SELECTION_SPACE_PAUSE,
69-
SELECT_OPEN_PAUSE,
70-
OPEN_IMPORT_DATA_IN_CLASSROOM_PAUSE,
7169
} from './constants';
7270
import { USER_GRAASP, USER_ALICE } from './fixtures/users';
7371
import {
@@ -92,7 +90,6 @@ const openClassroom = async (client, name) => {
9290
const addClassroom = async (client, name) => {
9391
const addButton = await client.$(`#${ADD_CLASSROOM_BUTTON_ID}`);
9492
await addButton.click();
95-
await client.pause(MODAL_OPEN_PAUSE);
9693
const inputSelector = `#${CLASSROOM_NAME_INPUT_ID}`;
9794
const input = await client.$(inputSelector);
9895
await clearInput(client, inputSelector);
@@ -130,7 +127,6 @@ const editClassroom = async (
130127
`#${EDIT_CLASSROOM_VALIDATE_BUTTON_ID}`
131128
);
132129
await validateButton.click();
133-
await client.pause(MODAL_CLOSE_PAUSE);
134130
};
135131

136132
const deleteClassroom = async (client, name) => {
@@ -146,7 +142,6 @@ const deleteClassroom = async (client, name) => {
146142

147143
const addUserInClassroom = async (client, username) => {
148144
await (await client.$(`#${ADD_USER_IN_CLASSROOM_BUTTON_ID}`)).click();
149-
await client.pause(MODAL_OPEN_PAUSE);
150145
const usernameInput = `#${ADD_USER_IN_CLASSROOM_NAME_INPUT_ID}`;
151146
await clearInput(client, usernameInput);
152147
await (await client.$(usernameInput)).setValue(username);
@@ -194,7 +189,6 @@ const editUserInClassroom = async (
194189
await (
195190
await client.$(`${userRowSelector} .${EDIT_USER_IN_CLASSROOM_BUTTON_CLASS}`)
196191
).click();
197-
await client.pause(MODAL_OPEN_PAUSE);
198192

199193
// edit username
200194
const editInput = `#${EDIT_USER_IN_CLASSROOM_USERNAME_INPUT_ID}`;
@@ -313,7 +307,6 @@ const importDataInClassroom = async (
313307
// submit filepath
314308
const absolutePath = path.resolve(__dirname, './fixtures/spaces', filepath);
315309
await (await client.$(`#${IMPORT_DATA_IN_CLASSROOM_BUTTON_ID}`)).click();
316-
await client.pause(OPEN_IMPORT_DATA_IN_CLASSROOM_PAUSE);
317310
await (await client.$(`#${IMPORT_FILEPATH_IN_CLASSROOM_INPUT_ID}`)).setValue(
318311
absolutePath
319312
);
@@ -345,7 +338,6 @@ const importDataInClassroom = async (
345338

346339
if (userExists) {
347340
// click on option
348-
await client.pause(SELECT_OPEN_PAUSE);
349341
await (await client.$(`${optionSelector}:nth-child(${index + 1})`)).click();
350342
await client.pause(2000);
351343
} else {
@@ -365,11 +357,9 @@ const importDataInClassroom = async (
365357
await (
366358
await client.$(`#${IMPORT_DATA_CLASSROOM_VALIDATE_BUTTON_ID}`)
367359
).click();
368-
await client.pause(LOAD_SELECTION_SPACE_PAUSE);
369360

370361
// return to classroom
371362
await (await client.$(`#${IMPORT_DATA_IN_CLASSROOM_BACK_BUTTON_ID}`)).click();
372-
await client.pause(OPEN_CLASSROOM_PAUSE);
373363
};
374364

375365
describe('Classrooms Scenarios', function () {
@@ -421,11 +411,9 @@ describe('Classrooms Scenarios', function () {
421411

422412
// open and cancel modal
423413
await (await client.$(`#${ADD_CLASSROOM_BUTTON_ID}`)).click();
424-
await client.pause(MODAL_OPEN_PAUSE);
425414
await (await client.$(`#${CLASSROOM_NAME_INPUT_ID}`)).setValue(name);
426415
await client.pause(INPUT_TYPE_PAUSE);
427416
await (await client.$(`#${ADD_CLASSROOM_CANCEL_BUTTON_ID}`)).click();
428-
await client.pause(MODAL_CLOSE_PAUSE);
429417
await expectElementToExist(client, `#${NO_CLASSROOM_AVAILABLE_ID}`);
430418

431419
// add classroom
@@ -752,7 +740,6 @@ describe('Classrooms Scenarios', function () {
752740
`.${CLASSROOM_CARD_CLASS}[data-name='${classroomName}']`
753741
)
754742
).click();
755-
await client.pause(OPEN_CLASSROOM_PAUSE);
756743

757744
const username = 'bob';
758745

test/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const EXPORT_FILEPATH = path.join(__dirname, './tmp/exportSpace');
44
export const APPS_FOLDER = 'apps';
55

66
export const DEFAULT_GLOBAL_TIMEOUT = 270000;
7+
export const SAVE_USER_INPUT_TIMEOUT = 370000;
78
export const TOOLTIP_FADE_OUT_PAUSE = 10000;
89
export const INPUT_TYPE_PAUSE = 2000;
910
export const VISIT_SPACE_PAUSE = 5000;

test/spaces/clearUserInput.test.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ import {
2020
SPACE_ATOMIC_STRUCTURE_PATH,
2121
} from '../fixtures/spaces';
2222
import { loadSpaceById } from './loadSpace.test';
23-
import {
24-
DEFAULT_GLOBAL_TIMEOUT,
25-
TOOLTIP_FADE_OUT_PAUSE,
26-
OPEN_SAVED_SPACE_PAUSE,
27-
} from '../constants';
23+
import { DEFAULT_GLOBAL_TIMEOUT, TOOLTIP_FADE_OUT_PAUSE } from '../constants';
2824
import { USER_GRAASP, USER_BOB, USER_ALICE } from '../fixtures/users';
2925
import {
3026
typeInTextInputApp,
@@ -130,7 +126,6 @@ describe('Clear User Input in a space', function () {
130126
`#${buildSpaceCardId(id)} .${SPACE_CARD_LINK_CLASS}`
131127
);
132128
await spaceCard.click();
133-
await client.pause(OPEN_SAVED_SPACE_PAUSE);
134129
await menuGoToPhase(client, 0);
135130
await checkTextInputAppContainsText(client, textInputAppId0, '');
136131
await menuGoToPhase(client, 1);

0 commit comments

Comments
 (0)