Skip to content

Commit

Permalink
test: update tests, update tour tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Nov 20, 2020
1 parent 04a01de commit 8d2097d
Show file tree
Hide file tree
Showing 24 changed files with 144 additions and 85 deletions.
1 change: 1 addition & 0 deletions public/app/config/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ module.exports = {
COMPLETE_TOUR_CHANNEL: 'tour:complete',
GET_APP_UPGRADE_CHANNEL: 'app:upgrade:get',
INSTALL_APP_UPGRADE_CHANNEL: 'app:upgrade:install',
GET_TOURS_ENABLED_CHANNEL: 'tour:enabled:get',
};
3 changes: 3 additions & 0 deletions public/app/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ const ACTIONS_VERBS = {
LOGOUT: 'logout',
};

const DEFAULT_TOURS_ENABLED = true;

const buildFilePath = ({ userId, spaceId, name }) => {
// add generated id to handle duplicate files
const generatedId = ObjectId().str;
Expand Down Expand Up @@ -131,4 +133,5 @@ module.exports = {
buildFilePath,
PREPACKAGED_APPS_FOLDER_NAME,
APPS_FOLDER,
DEFAULT_TOURS_ENABLED,
};
19 changes: 19 additions & 0 deletions public/app/listeners/getToursEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { DEFAULT_TOURS_ENABLED } = require('../config/config');
const { GET_TOURS_ENABLED_CHANNEL } = require('../config/channels');
const logger = require('../logger');
const { ERROR_GENERAL } = require('../config/errors');

const getToursEnabled = (mainWindow) => async () => {
try {
const enabled =
'SHOW_TOURS' in process.env
? process.env.SHOW_TOURS === 'true'
: DEFAULT_TOURS_ENABLED;
mainWindow.webContents.send(GET_TOURS_ENABLED_CHANNEL, enabled);
} catch (e) {
logger.error(e);
mainWindow.webContents.send(GET_TOURS_ENABLED_CHANNEL, ERROR_GENERAL);
}
};

module.exports = getToursEnabled;
2 changes: 2 additions & 0 deletions public/app/listeners/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const postFile = require('./postFile');
const deleteFile = require('./deleteFile');
const installAppUpgrade = require('./installAppUpgrade');
const getAppUpgrade = require('./getAppUpgrade');
const getToursEnabled = require('./getToursEnabled');

module.exports = {
loadSpace,
Expand Down Expand Up @@ -115,4 +116,5 @@ module.exports = {
deleteFile,
installAppUpgrade,
getAppUpgrade,
getToursEnabled,
};
5 changes: 5 additions & 0 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const {
DELETE_FILE_CHANNEL,
GET_APP_UPGRADE_CHANNEL,
INSTALL_APP_UPGRADE_CHANNEL,
GET_TOURS_ENABLED_CHANNEL,
} = require('./app/config/channels');
const env = require('./env.json');
const {
Expand Down Expand Up @@ -143,6 +144,7 @@ const {
deleteFile,
installAppUpgrade,
getAppUpgrade,
getToursEnabled,
} = require('./app/listeners');
const isMac = require('./app/utils/isMac');

Expand Down Expand Up @@ -600,6 +602,9 @@ app.on('ready', async () => {
getSpaceInClassroom(mainWindow, db)
);

// called when getting tours enabled
ipcMain.on(GET_TOURS_ENABLED_CHANNEL, getToursEnabled(mainWindow, db));

// called when getting the database
ipcMain.on(GET_DATABASE_CHANNEL, async () => {
try {
Expand Down
32 changes: 31 additions & 1 deletion src/actions/tour.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { COMPLETE_TOUR_CHANNEL } from '../config/channels';
import {
COMPLETE_TOUR_CHANNEL,
GET_TOURS_ENABLED_CHANNEL,
} from '../config/channels';
import { ERROR_GENERAL } from '../config/errors';
import {
INITIALIZE_TOUR,
Expand All @@ -9,6 +12,7 @@ import {
RESTART_TOUR,
START_TOUR,
STOP_TOUR,
GET_TOURS_ENABLED_SUCCESS,
} from '../types/tour';

const goToNextStep = (payload) => (dispatch) =>
Expand Down Expand Up @@ -63,10 +67,35 @@ const completeTour = async (tourName) => (dispatch) => {
window.ipcRenderer.send(COMPLETE_TOUR_CHANNEL, { tourName });
window.ipcRenderer.once(COMPLETE_TOUR_CHANNEL, async (event, error) => {
if (error === ERROR_GENERAL) {
// eslint-disable-next-line no-console
console.error(error);
}
});
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
};

const getToursEnabled = async (tourName) => (dispatch) => {
try {
window.ipcRenderer.send(GET_TOURS_ENABLED_CHANNEL, { tourName });
window.ipcRenderer.once(
GET_TOURS_ENABLED_CHANNEL,
async (event, payload) => {
if (payload === ERROR_GENERAL) {
// eslint-disable-next-line no-console
console.error(payload);
} else {
dispatch({
type: GET_TOURS_ENABLED_SUCCESS,
payload,
});
}
}
);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
};
Expand All @@ -81,4 +110,5 @@ export {
resetTour,
completeTour,
initializeTour,
getToursEnabled,
};
19 changes: 18 additions & 1 deletion src/components/common/Tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
goToNextStep,
resetTour,
startTour,
getToursEnabled,
} from '../../actions';
import { HOME_PATH, SETTINGS_PATH, VISIT_PATH } from '../../config/paths';
import {
Expand Down Expand Up @@ -50,7 +51,8 @@ export class Tour extends Component {
dispatchCompleteTour: PropTypes.func.isRequired,
dispatchResetTour: PropTypes.func.isRequired,
dispatchInitializeTour: PropTypes.func.isRequired,
tourKey: PropTypes.string.isRequired,
tourKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
.isRequired,
currentTour: PropTypes.oneOf(Object.values(tours)).isRequired,
run: PropTypes.bool.isRequired,
continuous: PropTypes.bool.isRequired,
Expand All @@ -75,8 +77,15 @@ export class Tour extends Component {
push: PropTypes.func.isRequired,
}).isRequired,
t: PropTypes.func.isRequired,
showTours: PropTypes.bool.isRequired,
dispatchGetToursEnabled: PropTypes.func.isRequired,
};

componentDidMount() {
const { dispatchGetToursEnabled } = this.props;
dispatchGetToursEnabled();
}

componentDidUpdate(prevProps) {
const {
signInActivity,
Expand Down Expand Up @@ -145,7 +154,13 @@ export class Tour extends Component {
dispatchCompleteTour,
currentTour,
t,
showTours,
} = this.props;

if (!showTours) {
return null;
}

const callback = async (data) => {
const { action, index, type, status } = data;
if (
Expand Down Expand Up @@ -255,6 +270,7 @@ export class Tour extends Component {
}

const mapStateToProps = ({ tour, authentication }) => ({
showTours: tour.getIn(['enabled']),
tourKey: tour.getIn(['key']),
currentTour: tour.getIn(['tour']),
run: tour.getIn(['run']),
Expand All @@ -275,6 +291,7 @@ const mapDispatchToProps = {
dispatchCompleteTour: completeTour,
dispatchResetTour: resetTour,
dispatchInitializeTour: initializeTour,
dispatchGetToursEnabled: getToursEnabled,
};

const ConnectedComponent = connect(mapStateToProps, mapDispatchToProps)(Tour);
Expand Down
1 change: 1 addition & 0 deletions src/config/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ module.exports = {
DELETE_FILE_CHANNEL: 'file:delete',
GET_APP_UPGRADE_CHANNEL: 'app:upgrade:get',
INSTALL_APP_UPGRADE_CHANNEL: 'app:upgrade:install',
GET_TOURS_ENABLED_CHANNEL: 'tour:enabled:get',
};
2 changes: 2 additions & 0 deletions src/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,5 @@ export const TOUR_DELAY_500 = 500;
export const TOUR_Z_INDEX = 10000;
export const TOUR_SPACE = 'owozgj';
export const EXAMPLE_VISIT_SPACE_LINK = `/space/${TOUR_SPACE}`;

export const DEFAULT_TOURS_ENABLED = true;
6 changes: 5 additions & 1 deletion src/reducers/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
RESTART_TOUR,
START_TOUR,
STOP_TOUR,
GET_TOURS_ENABLED_SUCCESS,
} from '../types/tour';
import { tours, VISIT_SPACE_TOUR_STEPS } from '../config/tours';
import { DEFAULT_TOURS_ENABLED } from '../config/constants';

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

export default (state = INITIAL_STATE, { type, payload }) => {
Expand Down Expand Up @@ -48,7 +51,8 @@ export default (state = INITIAL_STATE, { type, payload }) => {
.setIn(['tour'], payload.tour)
.setIn(['steps'], payload.steps)
.setIn(['key'], new Date().toISOString());

case GET_TOURS_ENABLED_SUCCESS:
return state.setIn(['enabled'], payload);
default:
return state;
}
Expand Down
1 change: 1 addition & 0 deletions src/types/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export const RESTART_TOUR = 'RESTART_TOUR';
export const START_TOUR = 'START_TOUR';
export const RESET_TOUR = 'RESET_TOUR';
export const INITIALIZE_TOUR = 'INITIALIZE_TOUR';
export const GET_TOURS_ENABLED_SUCCESS = 'GET_TOURS_ENABLED_SUCCESS';
6 changes: 4 additions & 2 deletions test/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const createApplication = async (
showMessageDialogResponse,
showSaveDialogResponse,
showOpenDialogResponse,
showTours,
} = {
showMessageDialogResponse: undefined,
showSaveDialogResponse: undefined,
showOpenDialogResponse: undefined,
showTours: 0,
}
) => {
const env = { NODE_ENV: 'test', ELECTRON_IS_DEV: 0 };
const env = { NODE_ENV: 'test', ELECTRON_IS_DEV: 0, SHOW_TOURS: showTours };

if (showMessageDialogResponse !== undefined) {
env.SHOW_MESSAGE_DIALOG_RESPONSE = showMessageDialogResponse;
Expand Down Expand Up @@ -52,7 +54,7 @@ const createApplication = async (

await app.start();

app.client.addCommand('getUserDataPath', function () {
app.client.addCommand('getUserDataPath', () => {
return path.join(app.client.capabilities.chrome.userDataDir, 'var');
});

Expand Down
13 changes: 0 additions & 13 deletions test/classrooms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ import {
OPEN_CLASSROOM_PAUSE,
TOOLTIP_FADE_OUT_PAUSE,
LOAD_SELECTION_SPACE_PAUSE,
SELECT_OPEN_PAUSE,
OPEN_IMPORT_DATA_IN_CLASSROOM_PAUSE,
} from './constants';
import { USER_GRAASP, USER_ALICE } from './fixtures/users';
import {
Expand All @@ -92,7 +90,6 @@ const openClassroom = async (client, name) => {
const addClassroom = async (client, name) => {
const addButton = await client.$(`#${ADD_CLASSROOM_BUTTON_ID}`);
await addButton.click();
await client.pause(MODAL_OPEN_PAUSE);
const inputSelector = `#${CLASSROOM_NAME_INPUT_ID}`;
const input = await client.$(inputSelector);
await clearInput(client, inputSelector);
Expand Down Expand Up @@ -130,7 +127,6 @@ const editClassroom = async (
`#${EDIT_CLASSROOM_VALIDATE_BUTTON_ID}`
);
await validateButton.click();
await client.pause(MODAL_CLOSE_PAUSE);
};

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

const addUserInClassroom = async (client, username) => {
await (await client.$(`#${ADD_USER_IN_CLASSROOM_BUTTON_ID}`)).click();
await client.pause(MODAL_OPEN_PAUSE);
const usernameInput = `#${ADD_USER_IN_CLASSROOM_NAME_INPUT_ID}`;
await clearInput(client, usernameInput);
await (await client.$(usernameInput)).setValue(username);
Expand Down Expand Up @@ -194,7 +189,6 @@ const editUserInClassroom = async (
await (
await client.$(`${userRowSelector} .${EDIT_USER_IN_CLASSROOM_BUTTON_CLASS}`)
).click();
await client.pause(MODAL_OPEN_PAUSE);

// edit username
const editInput = `#${EDIT_USER_IN_CLASSROOM_USERNAME_INPUT_ID}`;
Expand Down Expand Up @@ -313,7 +307,6 @@ const importDataInClassroom = async (
// submit filepath
const absolutePath = path.resolve(__dirname, './fixtures/spaces', filepath);
await (await client.$(`#${IMPORT_DATA_IN_CLASSROOM_BUTTON_ID}`)).click();
await client.pause(OPEN_IMPORT_DATA_IN_CLASSROOM_PAUSE);
await (await client.$(`#${IMPORT_FILEPATH_IN_CLASSROOM_INPUT_ID}`)).setValue(
absolutePath
);
Expand Down Expand Up @@ -345,7 +338,6 @@ const importDataInClassroom = async (

if (userExists) {
// click on option
await client.pause(SELECT_OPEN_PAUSE);
await (await client.$(`${optionSelector}:nth-child(${index + 1})`)).click();
await client.pause(2000);
} else {
Expand All @@ -365,11 +357,9 @@ const importDataInClassroom = async (
await (
await client.$(`#${IMPORT_DATA_CLASSROOM_VALIDATE_BUTTON_ID}`)
).click();
await client.pause(LOAD_SELECTION_SPACE_PAUSE);

// return to classroom
await (await client.$(`#${IMPORT_DATA_IN_CLASSROOM_BACK_BUTTON_ID}`)).click();
await client.pause(OPEN_CLASSROOM_PAUSE);
};

describe('Classrooms Scenarios', function () {
Expand Down Expand Up @@ -421,11 +411,9 @@ describe('Classrooms Scenarios', function () {

// open and cancel modal
await (await client.$(`#${ADD_CLASSROOM_BUTTON_ID}`)).click();
await client.pause(MODAL_OPEN_PAUSE);
await (await client.$(`#${CLASSROOM_NAME_INPUT_ID}`)).setValue(name);
await client.pause(INPUT_TYPE_PAUSE);
await (await client.$(`#${ADD_CLASSROOM_CANCEL_BUTTON_ID}`)).click();
await client.pause(MODAL_CLOSE_PAUSE);
await expectElementToExist(client, `#${NO_CLASSROOM_AVAILABLE_ID}`);

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

const username = 'bob';

Expand Down
1 change: 1 addition & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const EXPORT_FILEPATH = path.join(__dirname, './tmp/exportSpace');
export const APPS_FOLDER = 'apps';

export const DEFAULT_GLOBAL_TIMEOUT = 270000;
export const SAVE_USER_INPUT_TIMEOUT = 370000;
export const TOOLTIP_FADE_OUT_PAUSE = 10000;
export const INPUT_TYPE_PAUSE = 2000;
export const VISIT_SPACE_PAUSE = 5000;
Expand Down
7 changes: 1 addition & 6 deletions test/spaces/clearUserInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ import {
SPACE_ATOMIC_STRUCTURE_PATH,
} from '../fixtures/spaces';
import { loadSpaceById } from './loadSpace.test';
import {
DEFAULT_GLOBAL_TIMEOUT,
TOOLTIP_FADE_OUT_PAUSE,
OPEN_SAVED_SPACE_PAUSE,
} from '../constants';
import { DEFAULT_GLOBAL_TIMEOUT, TOOLTIP_FADE_OUT_PAUSE } from '../constants';
import { USER_GRAASP, USER_BOB, USER_ALICE } from '../fixtures/users';
import {
typeInTextInputApp,
Expand Down Expand Up @@ -130,7 +126,6 @@ describe('Clear User Input in a space', function () {
`#${buildSpaceCardId(id)} .${SPACE_CARD_LINK_CLASS}`
);
await spaceCard.click();
await client.pause(OPEN_SAVED_SPACE_PAUSE);
await menuGoToPhase(client, 0);
await checkTextInputAppContainsText(client, textInputAppId0, '');
await menuGoToPhase(client, 1);
Expand Down
Loading

0 comments on commit 8d2097d

Please sign in to comment.