From 5f19a1f5a79f5630aa2b5dd0147dfc2082f1c243 Mon Sep 17 00:00:00 2001 From: pyphilia Date: Tue, 24 Nov 2020 14:16:43 +0100 Subject: [PATCH] test: use initial db --- .eslintignore | 1 + package.json | 3 +- public/app/listeners/loadSpace.js | 13 +- src/components/common/MainMenu.js | 7 +- .../__snapshots__/MainMenu.test.js.snap | 8 +- .../space/export/ExportSelectionScreen.js | 13 +- src/config/selectors.js | 1 + test/application.js | 85 ++++++++- test/classrooms.test.js | 165 +++++++++-------- test/constants.js | 36 ++++ test/fixtures/searchSpaces.js | 14 +- test/fixtures/settings.js | 6 +- test/fixtures/spaces/airPollution.js | 3 +- test/fixtures/spaces/amphibians.js | 3 +- test/fixtures/spaces/apollo11.js | 5 +- test/fixtures/spaces/atomicStructure.js | 7 +- .../atomicStructureWithActionsAndResources.js | 11 +- test/fixtures/spaces/index.js | 37 +--- test/fixtures/spaces/lightColor.js | 3 +- test/fixtures/spaces/moon.js | 3 +- test/fixtures/spaces/spaceWithFileDrop.js | 7 +- .../spaces/spaceWithMultipleChanges.js | 7 +- test/fixtures/spaces/spaceWithToolsChanged.js | 3 +- test/fixtures/syncSpace.js | 19 +- test/fixtures/users.js | 30 ++- test/menu.test.js | 3 - test/settings.test.js | 63 ++++--- test/spaceSearch.test.js | 36 ++-- test/spaces/clearUserInput.test.js | 66 ++++--- test/spaces/deleteSpace.test.js | 50 +++-- test/spaces/exportSpace.test.js | 113 ++++++----- test/spaces/favoriteSpace.test.js | 29 ++- test/spaces/loadSpace.test.js | 94 ++++------ test/spaces/recentSpace.test.js | 12 +- test/spaces/saveSpace.test.js | 19 +- test/spaces/saveUserInput.test.js | 73 +++----- test/spaces/syncSpace.test.js | 175 ++++++++---------- test/spaces/visitSpace.test.js | 28 ++- test/tours.test.js | 15 +- test/utils.js | 43 +++-- 40 files changed, 703 insertions(+), 606 deletions(-) diff --git a/.eslintignore b/.eslintignore index 10b2c6ab..db1a052b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,3 +3,4 @@ dist coverage src/registerServiceWorker.js cypress/integration/examples +test/tmp diff --git a/package.json b/package.json index b8a45cf7..53227013 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,8 @@ "report": "cat ./coverage/lcov.info | env-cmd -f ./.env.test codacy-coverage", "report:ci": "cat ./coverage/lcov.info | codacy-coverage", "version": "git add CHANGELOG.md && standard-version -a", - "mocha": "mkdirp test/tmp && concurrently \"env-cmd -f ./.env.test react-scripts start\" \"wait-on http://localhost:3000 && mocha --require @babel/register \"test/**/*.test.js\"\"" + "mocha:run": "mocha --require @babel/register --retries 3 'test/**/*.test.js'", + "mocha": "mkdirp test/tmp && concurrently \"env-cmd -f ./.env.test react-scripts start\" \"wait-on http://localhost:3000 && yarn mocha:run\"" }, "dependencies": { "@material-ui/core": "4.11.0", diff --git a/public/app/listeners/loadSpace.js b/public/app/listeners/loadSpace.js index 2c237b1d..1edb1c97 100644 --- a/public/app/listeners/loadSpace.js +++ b/public/app/listeners/loadSpace.js @@ -172,18 +172,23 @@ const loadSpace = (mainWindow, db) => async ( return mainWindow.webContents.send(LOADED_SPACE_CHANNEL, ERROR_GENERAL); } - const savedResources = db.get(APP_INSTANCE_RESOURCES_COLLECTION); + // remove already existing resources + db.get(APP_INSTANCE_RESOURCES_COLLECTION) + .remove(({ id }) => + appInstanceResources.find(({ id: thisId }) => thisId === id) + ) + .write(); const newResources = appInstanceResources - // keep only non-duplicate resources - .filter(({ id }) => !savedResources.find({ id }).value()) // change user id by current user id .map((resource) => ({ ...resource, user: userId, })); - savedResources.push(...newResources).write(); + db.get(APP_INSTANCE_RESOURCES_COLLECTION) + .push(...newResources) + .write(); } // write actions to database if selected diff --git a/src/components/common/MainMenu.js b/src/components/common/MainMenu.js index e4af2417..092b4529 100644 --- a/src/components/common/MainMenu.js +++ b/src/components/common/MainMenu.js @@ -44,6 +44,7 @@ import { SIGN_OUT_MENU_ITEM_ID, SAVED_SPACES_MENU_ITEM_ID, CLASSROOMS_MENU_ITEM_ID, + MAINMENU_ID, } from '../../config/selectors'; import { signOut } from '../../actions/authentication'; import { AUTHENTICATED, USER_MODES } from '../../config/constants'; @@ -66,7 +67,7 @@ export class MainMenu extends Component { user: Map(), }; - handleClick = path => { + handleClick = (path) => { const { history: { push }, } = this.props; @@ -145,7 +146,7 @@ export class MainMenu extends Component { return null; } - renderOfflineMenuItem = child => { + renderOfflineMenuItem = (child) => { const { t } = this.props; return ( @@ -325,7 +326,7 @@ export class MainMenu extends Component { t, } = this.props; return ( - + {this.renderAuthenticatedMenu()} with developerMode = false renders correctly 1`] = ` - + with developerMode = false renders correctly `; exports[` with developerMode = true renders correctly 1`] = ` - + ({ +const styles = (theme) => ({ ...Styles(theme), buttonGroup: { textAlign: 'center', @@ -95,6 +96,7 @@ class ExportSelectionScreen extends Component { }).isRequired, space: PropTypes.instanceOf(Map).isRequired, status: PropTypes.oneOf(Object.values(EXPORT_SPACE_STATUS)).isRequired, + isTeacher: PropTypes.bool.isRequired, }; state = { @@ -137,7 +139,7 @@ class ExportSelectionScreen extends Component { } }; - handleChange = event => { + handleChange = (event) => { this.setState({ [event.target.name]: event.target.checked }); }; @@ -168,12 +170,12 @@ class ExportSelectionScreen extends Component { }; renderCheckbox(collectionName, label, isChecked, emptyHelperText) { - const { database, space, userId } = this.props; + const { database, space, userId, isTeacher } = this.props; const id = space.get('id'); const content = database ? database[collectionName] : []; const hasContent = content.filter( - ({ user, spaceId }) => user === userId && spaceId === id + ({ user, spaceId }) => (isTeacher || user === userId) && spaceId === id ).length; const checkbox = ( @@ -313,6 +315,9 @@ const mapStateToProps = ({ Developer, }) => ({ userId: authentication.getIn(['user', 'id']), + isTeacher: + authentication.getIn(['user', 'settings', 'userMode']) === + USER_MODES.TEACHER, database: Developer.get('database'), activity: Boolean(exportSpaceReducer.getIn(['activity']).size), space: exportSpaceReducer.getIn(['space']), diff --git a/src/config/selectors.js b/src/config/selectors.js index 79ef2640..6cce13f9 100644 --- a/src/config/selectors.js +++ b/src/config/selectors.js @@ -3,6 +3,7 @@ export const DRAWER_BUTTON_ID = 'drawerButton'; export const FAVORITE_SPACES_WRAPPER_ID = 'favoriteSpacesWrapper'; export const RECENT_SPACES_WRAPPER_ID = 'recentSpacesWrapper'; +export const MAINMENU_ID = 'mainMenu'; export const CLASSROOMS_MENU_ITEM_ID = 'classroomsMenuItem'; export const CLASSROOMS_MAIN_ID = 'classroomsMain'; export const SAVED_SPACES_MENU_ITEM_ID = 'savedSpacesMenuItem'; diff --git a/test/application.js b/test/application.js index dfd8559f..771fb3c6 100644 --- a/test/application.js +++ b/test/application.js @@ -1,20 +1,83 @@ import { Application } from 'spectron'; import electronPath from 'electron'; // Require Electron from the binaries included in node_modules. import path from 'path'; +import fse from 'fs-extra'; +import extract from 'extract-zip'; +import { buildSignedUserForDatabase } from './constants'; -const createApplication = async ( - { - showMessageDialogResponse, - showSaveDialogResponse, - showOpenDialogResponse, - showTours, - } = { +const getFormattedTime = () => { + const today = new Date(); + const y = today.getFullYear(); + // JavaScript months are 0-based. + const m = today.getMonth() + 1; + const d = today.getDate(); + const h = today.getHours(); + const mi = today.getMinutes(); + const s = today.getSeconds(); + return `${y}${m}${d}_${h}-${mi}-${s}`; +}; + +const setUpDatabase = async (database = buildSignedUserForDatabase()) => { + const tmpDatabasePath = path.join(__dirname, 'tmp', getFormattedTime()); + const varFolder = path.join(tmpDatabasePath, 'var'); + fse.ensureDirSync(varFolder); + + const db = { + ...database, + spaces: [], + appInstanceResources: [], + actions: [], + }; + + if (database) { + // add paths data in var + const spaces = database?.spaces || []; + // eslint-disable-next-line no-restricted-syntax + for (const { + path: spacePath, + space, + appInstanceResources, + actions, + } of spaces) { + // eslint-disable-next-line no-await-in-loop + await extract(path.join(__dirname, './fixtures/spaces', spacePath), { + dir: `${varFolder}/${space.id}`, + }); + db.spaces.push(space); + db.appInstanceResources = db.appInstanceResources.concat( + appInstanceResources + ); + db.actions = db.actions.concat(actions); + } + + const classrooms = database?.classrooms || []; + // eslint-disable-next-line no-restricted-syntax + for (const { id } of classrooms) { + fse.ensureDirSync(path.join(varFolder, id)); + } + + // set db + fse.writeFileSync(`${varFolder}/db.json`, JSON.stringify(db)); + } + + return tmpDatabasePath; +}; + +const createApplication = async ({ + database = buildSignedUserForDatabase(), + responses = { showMessageDialogResponse: undefined, showSaveDialogResponse: undefined, showOpenDialogResponse: undefined, showTours: 0, - } -) => { + }, +} = {}) => { + const { + showMessageDialogResponse, + showSaveDialogResponse, + showOpenDialogResponse, + showTours, + } = responses; const env = { NODE_ENV: 'test', ELECTRON_IS_DEV: 0, SHOW_TOURS: showTours }; if (showMessageDialogResponse !== undefined) { @@ -29,6 +92,9 @@ const createApplication = async ( env.SHOW_OPEN_DIALOG_RESPONSE = showOpenDialogResponse; } + // set up database + const tmpDatabasePath = await setUpDatabase(database); + const app = new Application({ // Your electron path can be any binary // i.e for OSX an example path could be '/Applications/MyApp.app/Contents/MacOS/MyApp' @@ -49,6 +115,7 @@ const createApplication = async ( // The following line tells spectron to look and use the main.js file // and the package.json located 1 level above. args: [path.join(__dirname, '../public/electron.js')], + chromeDriverArgs: [`--user-data-dir=${tmpDatabasePath}`], env, }); diff --git a/test/classrooms.test.js b/test/classrooms.test.js index c74ea538..b2892ffe 100644 --- a/test/classrooms.test.js +++ b/test/classrooms.test.js @@ -4,14 +4,11 @@ /* eslint-disable func-names */ import { expect } from 'chai'; import path from 'path'; -import _ from 'lodash'; import { mochaAsync, expectElementToNotExist, expectElementToExist, - toggleStudentMode, clearInput, - menuGoToSettings, menuGoToClassrooms, menuGoToSignOut, userSignIn, @@ -55,6 +52,7 @@ import { EDIT_USER_IN_CLASSROOM_DELETE_DATA_BUTTON_CLASS, buildTableCellSpaceId, EDIT_CLASSROOM_DELETE_DATA_BUTTON_CLASS, + MAINMENU_ID, } from '../src/config/selectors'; import { DEFAULT_GLOBAL_TIMEOUT, @@ -66,16 +64,15 @@ import { OPEN_CLASSROOM_PAUSE, TOOLTIP_FADE_OUT_PAUSE, LOAD_SELECTION_SPACE_PAUSE, + buildSignedUserForDatabase, } from './constants'; -import { USER_GRAASP, USER_ALICE } from './fixtures/users'; +import { USER_GRAASP, USER_ALICE, USER_BOB } from './fixtures/users'; import { checkLoadSelectionLayout, setCheckboxesTo, } from './spaces/loadSpace.test'; import { - SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH, SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES, - SPACE_APOLLO_11_PATH, SPACE_APOLLO_11, } from './fixtures/spaces'; @@ -228,42 +225,37 @@ const editUserInClassroom = async ( const hasStudentsTableLayout = async (client, spaces = [], usernames = []) => { // no user should have no table row if (!usernames.length) { - await expectElementToNotExist( - client, - `#${CLASSROOM_TABLE_BODY_ID} tr[data-name]` - ); + const users = await ( + await client.$(`#${CLASSROOM_TABLE_BODY_ID}`) + ).getText(); + expect(users).to.equal(''); } // check space columns for (const spaceId of spaces) { const headCellSelector = `#${buildTableCellSpaceId(spaceId)}`; await expectElementToExist(client, headCellSelector); - } - - // check user rows - for (const { username, actions = {}, resources = {} } of usernames) { - const userRowSelector = `#${CLASSROOM_TABLE_BODY_ID} tr[data-name='${username}']`; - await expectElementToExist(client, userRowSelector); - - if (!_.isEmpty(actions)) { - for (const [spaceId, exists] of Object.entries(actions)) { - const actionsSelector = `${userRowSelector} *[data-head-cell-id='${spaceId}'] .${STUDENT_ROW_ACTIONS_CLASS}`; - if (exists) { - await expectElementToExist(client, actionsSelector); - } else { - await expectElementToNotExist(client, actionsSelector); - } + for (const { username, actions = {}, resources = {} } of usernames) { + const userRowSelector = `#${CLASSROOM_TABLE_BODY_ID} tr[data-name='${username}']`; + await expectElementToExist(client, userRowSelector); + const cellSelector = `${userRowSelector} *[data-head-cell-id='${spaceId}']`; + if (actions[spaceId]) { + await expectElementToExist(client, `.${STUDENT_ROW_ACTIONS_CLASS}`); + } else { + await expectElementToNotExist( + client, + cellSelector, + STUDENT_ROW_ACTIONS_CLASS + ); } - } - - if (!_.isEmpty(resources)) { - for (const [spaceId, exists] of Object.entries(resources)) { - const resourcesSelector = `${userRowSelector} *[data-head-cell-id='${spaceId}'] .${STUDENT_ROW_RESOURCES_CLASS}`; - if (exists) { - await expectElementToExist(client, resourcesSelector); - } else { - await expectElementToNotExist(client, resourcesSelector); - } + if (resources[spaceId]) { + await expectElementToExist(client, `.${STUDENT_ROW_RESOURCES_CLASS}`); + } else { + await expectElementToNotExist( + client, + cellSelector, + STUDENT_ROW_RESOURCES_CLASS + ); } } } @@ -373,11 +365,9 @@ describe('Classrooms Scenarios', function () { describe('Student', function () { beforeEach( mochaAsync(async () => { - app = await createApplication(); + app = await createApplication({ database: {} }); const { client } = app; - await userSignIn(client, USER_GRAASP); - await menuGoToSettings(client); - await toggleStudentMode(client, true); + await userSignIn(client, USER_BOB); }) ); @@ -387,7 +377,11 @@ describe('Classrooms Scenarios', function () { const { client } = app; await openDrawer(client); - await expectElementToNotExist(client, `#${CLASSROOMS_MENU_ITEM_ID}`); + await expectElementToNotExist( + client, + `#${MAINMENU_ID}`, + CLASSROOMS_MENU_ITEM_ID + ); }) ); }); @@ -396,12 +390,12 @@ describe('Classrooms Scenarios', function () { it( 'manage a classroom (add, edit, remove)', mochaAsync(async () => { - app = await createApplication({ showMessageDialogResponse: 1 }); + app = await createApplication({ + responses: { showMessageDialogResponse: 1 }, + }); const { client } = app; - await userSignIn(client, USER_GRAASP); - await menuGoToClassrooms(client); // default content empty @@ -442,7 +436,7 @@ describe('Classrooms Scenarios', function () { it( 'classrooms are saved for a given teacher', mochaAsync(async () => { - app = await createApplication({}); + app = await createApplication({ database: {} }); const { client } = app; @@ -487,21 +481,33 @@ describe('Classrooms Scenarios', function () { it( 'manage a student in a classroom (add, remove, edit)', mochaAsync(async () => { - app = await createApplication({ showMessageDialogResponse: 1 }); + const name = 'classroomname'; + const id = 'classroomId'; - const { client } = app; + app = await createApplication({ + database: { + classrooms: [ + { + spaces: [], + appInstanceResources: [], + actions: [], + users: [], + id, + name, + createdAt: Date.now(), + updatedAt: Date.now(), + teacherId: USER_GRAASP.id, + }, + ], + ...buildSignedUserForDatabase(), + }, + responses: { showMessageDialogResponse: 1 }, + }); - await userSignIn(client, USER_GRAASP); + const { client } = app; await menuGoToClassrooms(client); - // default content empty - await expectElementToExist(client, `#${NO_CLASSROOM_AVAILABLE_ID}`); - - const name = 'classroomname'; - - // add classroom - await addClassroom(client, name); await openClassroom(client, name); // add user @@ -565,14 +571,32 @@ describe('Classrooms Scenarios', function () { ); describe('manage space data in classroom', function () { + const classroomName = 'classroomname'; + const user = USER_ALICE; + beforeEach( mochaAsync(async () => { - app = await createApplication(); + app = await createApplication({ + database: { + classrooms: [ + { + spaces: [], + appInstanceResources: [], + actions: [], + users: [], + id: 'someid', + name: classroomName, + createdAt: Date.now(), + updatedAt: Date.now(), + teacherId: USER_GRAASP.id, + }, + ], + ...buildSignedUserForDatabase(), + }, + }); const { client } = app; - await userSignIn(client, USER_GRAASP); - await menuGoToClassrooms(client); }) ); @@ -582,12 +606,9 @@ describe('Classrooms Scenarios', function () { mochaAsync(async () => { const { client } = app; - const filepath = SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH; - - const classroomName = 'classroomname'; + const filepath = + SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES.path; - // add classroom - await addClassroom(client, classroomName); await ( await client.$( `.${CLASSROOM_CARD_CLASS}[data-name='${classroomName}']` @@ -595,9 +616,7 @@ describe('Classrooms Scenarios', function () { ).click(); await client.pause(OPEN_CLASSROOM_PAUSE); - // add user - const username = 'anna'; - await addUserInClassroom(client, username); + const { username } = user; // import data await importDataInClassroom( @@ -656,12 +675,9 @@ describe('Classrooms Scenarios', function () { mochaAsync(async () => { const { client } = app; - const filepath = SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH; + const filepath = + SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES.path; - const classroomName = 'classroomname'; - - // add classroom - await addClassroom(client, classroomName); await ( await client.$( `.${CLASSROOM_CARD_CLASS}[data-name='${classroomName}']` @@ -698,7 +714,7 @@ describe('Classrooms Scenarios', function () { const username1 = 'cedric'; await importDataInClassroom( client, - SPACE_APOLLO_11_PATH, + SPACE_APOLLO_11.path, username1, { space: true, actions: false, resources: false }, { space: true, actions: false, resources: false } @@ -729,12 +745,9 @@ describe('Classrooms Scenarios', function () { mochaAsync(async () => { const { client } = app; - const filepath = SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH; - - const classroomName = 'classroomname'; + const filepath = + SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES.path; - // add classroom - await addClassroom(client, classroomName); await ( await client.$( `.${CLASSROOM_CARD_CLASS}[data-name='${classroomName}']` diff --git a/test/constants.js b/test/constants.js index b559c12b..40af83ef 100644 --- a/test/constants.js +++ b/test/constants.js @@ -1,8 +1,44 @@ import path from 'path'; +import { + AUTHENTICATED, + DEFAULT_SYNC_MODE, + DEFAULT_USER_MODE, +} from '../src/config/constants'; +import { USER_GRAASP } from './fixtures/users'; export const EXPORT_FILEPATH = path.join(__dirname, './tmp/exportSpace'); export const APPS_FOLDER = 'apps'; +export const buildSignedUserForDatabase = ({ + syncMode = DEFAULT_SYNC_MODE, +} = {}) => ({ + users: [USER_GRAASP], + user: { + id: USER_GRAASP.id, + username: USER_GRAASP.username, + createdAt: '2020-11-23T14:54:49.092Z', + anonymous: false, + geolocation: null, + settings: { + lang: 'en', + developerMode: false, + geolocationEnabled: false, + syncMode, + userMode: USER_GRAASP?.settings?.userMode || DEFAULT_USER_MODE, + actionAccessibility: false, + actionsEnabled: true, + }, + favoriteSpaces: [], + recentSpaces: [], + tour: { + visitSpace: true, + settings: true, + }, + lastSignIn: '2020-11-23T14:54:49.092Z', + authenticated: AUTHENTICATED, + }, +}); + export const DEFAULT_GLOBAL_TIMEOUT = 270000; export const SAVE_USER_INPUT_TIMEOUT = 370000; export const TOOLTIP_FADE_OUT_PAUSE = 10000; diff --git a/test/fixtures/searchSpaces.js b/test/fixtures/searchSpaces.js index e6d89772..d8b9f4a4 100644 --- a/test/fixtures/searchSpaces.js +++ b/test/fixtures/searchSpaces.js @@ -1,32 +1,24 @@ -import { SPACE_ATOMIC_STRUCTURE_PATH, SPACE_ATOMIC_STRUCTURE } from './spaces'; -import { SPACE_APOLLO_11_PATH, SPACE_APOLLO_11 } from './spaces/apollo11'; +import { SPACE_ATOMIC_STRUCTURE, SPACE_APOLLO_11 } from './spaces'; import { buildSpaceCardId } from '../../src/config/selectors'; // eslint-disable-next-line import/prefer-default-export export const searchSpacesFixtures = [ [ - [SPACE_ATOMIC_STRUCTURE_PATH, SPACE_APOLLO_11_PATH], '', [SPACE_ATOMIC_STRUCTURE.space.id, SPACE_APOLLO_11.space.id].map((id) => buildSpaceCardId(id) ), ], [ - [SPACE_ATOMIC_STRUCTURE_PATH, SPACE_APOLLO_11_PATH], 'a', [SPACE_ATOMIC_STRUCTURE.space.id, SPACE_APOLLO_11.space.id].map((id) => buildSpaceCardId(id) ), ], [ - [SPACE_ATOMIC_STRUCTURE_PATH, SPACE_APOLLO_11_PATH], 'atomic', [SPACE_ATOMIC_STRUCTURE.space.id].map((id) => buildSpaceCardId(id)), ], - [ - [SPACE_ATOMIC_STRUCTURE_PATH, SPACE_APOLLO_11_PATH], - 'apollo', - [SPACE_APOLLO_11.space.id].map((id) => buildSpaceCardId(id)), - ], - [[SPACE_ATOMIC_STRUCTURE_PATH, SPACE_APOLLO_11_PATH], 'unknown', []], + ['apollo', [SPACE_APOLLO_11.space.id].map((id) => buildSpaceCardId(id))], + ['unknown', []], ]; diff --git a/test/fixtures/settings.js b/test/fixtures/settings.js index 59814bed..3331e1fd 100644 --- a/test/fixtures/settings.js +++ b/test/fixtures/settings.js @@ -9,19 +9,19 @@ import { USER_ALICE, USER_GRAASP, USER_CEDRIC } from './users'; /* eslint-disable-next-line import/prefer-default-export */ export const settingsPerUser = { - [USER_GRAASP.name]: { + [USER_GRAASP.username]: { lang: DEFAULT_LANGUAGE, developerMode: DEFAULT_DEVELOPER_MODE, geolocationEnabled: DEFAULT_GEOLOCATION_ENABLED, syncMode: DEFAULT_SYNC_MODE, }, - [USER_ALICE.name]: { + [USER_ALICE.username]: { lang: 'fr', developerMode: DEFAULT_DEVELOPER_MODE, geolocationEnabled: true, syncMode: SYNC_MODES.ADVANCED, }, - [USER_CEDRIC.name]: { + [USER_CEDRIC.username]: { lang: 'ja', developerMode: true, geolocationEnabled: DEFAULT_GEOLOCATION_ENABLED, diff --git a/test/fixtures/spaces/airPollution.js b/test/fixtures/spaces/airPollution.js index 7e6af994..69ddddcb 100644 --- a/test/fixtures/spaces/airPollution.js +++ b/test/fixtures/spaces/airPollution.js @@ -1,5 +1,4 @@ -// eslint-disable-next-line import/prefer-default-export -export const SPACE_AIR_POLLUTION = { +export default { space: { id: '5e53bc759bdb29152a00b6e4', }, diff --git a/test/fixtures/spaces/amphibians.js b/test/fixtures/spaces/amphibians.js index d23eeac7..87ffe98d 100644 --- a/test/fixtures/spaces/amphibians.js +++ b/test/fixtures/spaces/amphibians.js @@ -1,5 +1,4 @@ -// eslint-disable-next-line import/prefer-default-export -export const SPACE_AMPHIBIANS = { +export default { space: { id: '5eb55005c474e8163ac9804d', }, diff --git a/test/fixtures/spaces/apollo11.js b/test/fixtures/spaces/apollo11.js index b00c6207..edff6582 100644 --- a/test/fixtures/spaces/apollo11.js +++ b/test/fixtures/spaces/apollo11.js @@ -1,4 +1,5 @@ -export const SPACE_APOLLO_11 = { +export default { + path: 'apollo11.zip', space: { id: '5d2db762fcb4d60e33ad32fe', name: 'Apollo 11', @@ -206,5 +207,3 @@ export const SPACE_APOLLO_11 = { actions: [], appInstanceResources: [], }; - -export const SPACE_APOLLO_11_PATH = 'apollo11.zip'; diff --git a/test/fixtures/spaces/atomicStructure.js b/test/fixtures/spaces/atomicStructure.js index 492a94f2..36cde56f 100644 --- a/test/fixtures/spaces/atomicStructure.js +++ b/test/fixtures/spaces/atomicStructure.js @@ -1,4 +1,5 @@ -const SPACE_ATOMIC_STRUCTURE = { +export default { + path: 'atomicStructure.zip', space: { id: '5d3f0cb5fd555f7e3fbe7ee2', name: 'Atomic structure', @@ -1821,7 +1822,3 @@ const SPACE_ATOMIC_STRUCTURE = { appInstanceResources: [], actions: [], }; - -const SPACE_ATOMIC_STRUCTURE_PATH = 'atomicStructure.zip'; - -export { SPACE_ATOMIC_STRUCTURE, SPACE_ATOMIC_STRUCTURE_PATH }; diff --git a/test/fixtures/spaces/atomicStructureWithActionsAndResources.js b/test/fixtures/spaces/atomicStructureWithActionsAndResources.js index c1be9cd5..a62e1fd3 100644 --- a/test/fixtures/spaces/atomicStructureWithActionsAndResources.js +++ b/test/fixtures/spaces/atomicStructureWithActionsAndResources.js @@ -1,4 +1,5 @@ -const SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES = { +export default { + path: 'atomicStructureWithActionsAndResources.zip', space: { id: '5d3f0cb5fd555f7e3fbe7ee2', name: 'Atomic structure', @@ -1849,11 +1850,3 @@ const SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES = { }, ], }; - -const SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH = - 'atomicStructureWithActionsAndResources.zip'; - -export { - SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES, - SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH, -}; diff --git a/test/fixtures/spaces/index.js b/test/fixtures/spaces/index.js index 6b10bdcf..c0c7e602 100644 --- a/test/fixtures/spaces/index.js +++ b/test/fixtures/spaces/index.js @@ -1,40 +1,23 @@ -import { - SPACE_ATOMIC_STRUCTURE, - SPACE_ATOMIC_STRUCTURE_PATH, -} from './atomicStructure'; -import { - SPACE_WITH_MULTIPLE_CHANGES, - SPACE_WITH_MULTIPLE_CHANGES_PATH, -} from './spaceWithMultipleChanges'; -import { - SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES, - SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH, -} from './atomicStructureWithActionsAndResources'; -import { SPACE_APOLLO_11, SPACE_APOLLO_11_PATH } from './apollo11'; -import { SPACE_AIR_POLLUTION } from './airPollution'; -import { SPACE_LIGHT_COLOR } from './lightColor'; -import { SPACE_WITH_TOOLS_CHANGED } from './spaceWithToolsChanged'; -import { SPACE_AMPHIBIANS } from './amphibians'; -import { SPACE_MOON } from './moon'; -import { - SPACE_WITH_FILE_DROP, - SPACE_WITH_FILE_DROP_PATH, -} from './spaceWithFileDrop'; +import SPACE_ATOMIC_STRUCTURE from './atomicStructure'; +import SPACE_WITH_MULTIPLE_CHANGES from './spaceWithMultipleChanges'; +import SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES from './atomicStructureWithActionsAndResources'; +import SPACE_APOLLO_11 from './apollo11'; +import SPACE_AIR_POLLUTION from './airPollution'; +import SPACE_LIGHT_COLOR from './lightColor'; +import SPACE_WITH_TOOLS_CHANGED from './spaceWithToolsChanged'; +import SPACE_AMPHIBIANS from './amphibians'; +import SPACE_MOON from './moon'; +import SPACE_WITH_FILE_DROP from './spaceWithFileDrop'; export { SPACE_ATOMIC_STRUCTURE, - SPACE_ATOMIC_STRUCTURE_PATH, SPACE_WITH_MULTIPLE_CHANGES, - SPACE_WITH_MULTIPLE_CHANGES_PATH, SPACE_APOLLO_11, - SPACE_APOLLO_11_PATH, SPACE_AIR_POLLUTION, SPACE_LIGHT_COLOR, SPACE_WITH_TOOLS_CHANGED, SPACE_AMPHIBIANS, SPACE_MOON, SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES, - SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH, SPACE_WITH_FILE_DROP, - SPACE_WITH_FILE_DROP_PATH, }; diff --git a/test/fixtures/spaces/lightColor.js b/test/fixtures/spaces/lightColor.js index ec928a1a..dea799ec 100644 --- a/test/fixtures/spaces/lightColor.js +++ b/test/fixtures/spaces/lightColor.js @@ -1,5 +1,4 @@ -// eslint-disable-next-line import/prefer-default-export -export const SPACE_LIGHT_COLOR = { +export default { space: { id: '5e53ec9f5ab00314bf99b42a', }, diff --git a/test/fixtures/spaces/moon.js b/test/fixtures/spaces/moon.js index 23f5659a..853c4a86 100644 --- a/test/fixtures/spaces/moon.js +++ b/test/fixtures/spaces/moon.js @@ -1,5 +1,4 @@ -// eslint-disable-next-line import/prefer-default-export -export const SPACE_MOON = { +export default { space: { id: '5eb54d96c474e8163ac97f81', }, diff --git a/test/fixtures/spaces/spaceWithFileDrop.js b/test/fixtures/spaces/spaceWithFileDrop.js index ce949377..f9bf71b6 100644 --- a/test/fixtures/spaces/spaceWithFileDrop.js +++ b/test/fixtures/spaces/spaceWithFileDrop.js @@ -1,4 +1,5 @@ -const SPACE_WITH_FILE_DROP = { +export default { + path: 'spaceWithFileDrop.zip', space: { id: '5fad26da467d165d53ef784b', name: 'Space with File Drop', @@ -44,7 +45,3 @@ const SPACE_WITH_FILE_DROP = { appInstanceResources: [], actions: [], }; - -const SPACE_WITH_FILE_DROP_PATH = 'spaceWithFileDrop.zip'; - -export { SPACE_WITH_FILE_DROP, SPACE_WITH_FILE_DROP_PATH }; diff --git a/test/fixtures/spaces/spaceWithMultipleChanges.js b/test/fixtures/spaces/spaceWithMultipleChanges.js index 2a220092..1e337b10 100644 --- a/test/fixtures/spaces/spaceWithMultipleChanges.js +++ b/test/fixtures/spaces/spaceWithMultipleChanges.js @@ -1,4 +1,5 @@ -const SPACE_WITH_MULTIPLE_CHANGES = { +export default { + path: 'spaceWithMultipleChanges.zip', space: { id: '5ea029f5f851e7716e3722fe', name: 'Sync Space with Multiple Changes', @@ -148,7 +149,3 @@ const SPACE_WITH_MULTIPLE_CHANGES = { appInstanceResources: [], actions: [], }; - -const SPACE_WITH_MULTIPLE_CHANGES_PATH = 'spaceWithMultipleChanges.zip'; - -export { SPACE_WITH_MULTIPLE_CHANGES, SPACE_WITH_MULTIPLE_CHANGES_PATH }; diff --git a/test/fixtures/spaces/spaceWithToolsChanged.js b/test/fixtures/spaces/spaceWithToolsChanged.js index a183adc4..9c2c8277 100644 --- a/test/fixtures/spaces/spaceWithToolsChanged.js +++ b/test/fixtures/spaces/spaceWithToolsChanged.js @@ -1,5 +1,4 @@ -// eslint-disable-next-line import/prefer-default-export -export const SPACE_WITH_TOOLS_CHANGED = { +export default { space: { id: '5ea00ac4e1540856e519dfe8', }, diff --git a/test/fixtures/syncSpace.js b/test/fixtures/syncSpace.js index 8990ec75..2debee4a 100644 --- a/test/fixtures/syncSpace.js +++ b/test/fixtures/syncSpace.js @@ -5,10 +5,9 @@ import { SYNC_CHANGES } from '../../src/config/constants'; const { ADDED, REMOVED, UPDATED, MOVED } = SYNC_CHANGES; - -export const SPACE_WITH_ADDITION_PATH = './spaceWithAddition.zip'; export const SPACE_WITH_ADDITION = { space: { id: '5e9edef4dbea5955c7f5bbea', name: 'Space with addition' }, + path: './spaceWithAddition.zip', }; export const SPACE_WITH_ADDITION_CHANGES = { @@ -29,9 +28,9 @@ export const SPACE_WITH_ADDITION_CHANGES = { ], }; -export const SPACE_WITH_REMOVAL_PATH = './spaceWithRemoval.zip'; export const SPACE_WITH_REMOVAL = { space: { id: '5e9efe77f130f510ae709466', name: 'Space with removal' }, + path: './spaceWithRemoval.zip', }; export const SPACE_WITH_REMOVAL_CHANGES = { @@ -60,9 +59,9 @@ export const SPACE_WITH_REMOVAL_CHANGES = { ], }; -export const SPACE_WITH_UPDATE_PATH = './spaceWithUpdate.zip'; export const SPACE_WITH_UPDATE = { space: { id: '5e9f0ccde272c3572ddf0524', name: 'Space with update' }, + path: './spaceWithUpdate.zip', }; export const SPACE_WITH_UPDATE_CHANGES = { @@ -86,9 +85,9 @@ export const SPACE_WITH_UPDATE_CHANGES = { ], }; -export const SPACE_WITH_MOVE_PATH = './spaceWithMove.zip'; export const SPACE_WITH_MOVE = { space: { id: '5ea003b2e1540856e519cc3e', name: 'Space with move' }, + path: './spaceWithMove.zip', }; export const SPACE_WITH_MOVE_CHANGES = { @@ -135,9 +134,9 @@ export const SPACE_WITH_MOVE_CHANGES = { ], }; -export const SPACE_WITH_TOOLS_UPDATE_PATH = './spaceWithToolsUpdate.zip'; export const SPACE_WITH_TOOLS_UPDATE = { space: { id: '5ea00ac4e1540856e519dfe8', name: 'Space with tools updated' }, + path: './spaceWithToolsUpdate.zip', }; export const SPACE_WITH_TOOLS_UPDATE_CHANGES = { @@ -160,9 +159,8 @@ export const SPACE_WITH_TOOLS_UPDATE_CHANGES = { ], }; -export const SPACE_WITH_MULTIPLE_CHANGES_PATH = - './spaceWithMultipleChanges.zip'; export const SPACE_WITH_MULTIPLE_CHANGES = { + path: './spaceWithMultipleChanges.zip', space: { id: '5ea029f5f851e7716e3722fe', name: 'Sync Space with Multiple Changes', @@ -321,6 +319,7 @@ export const SPACE_WITH_MULTIPLE_CHANGES_CHANGES = { }, phases: [ { + id: '5ea029f9f851e7716e372302', name: 'Orientation', change: UPDATED, items: [ @@ -332,6 +331,7 @@ export const SPACE_WITH_MULTIPLE_CHANGES_CHANGES = { }, { name: 'Investigation', + id: '5ea029faf851e7716e372308', change: ADDED, items: [ { @@ -342,6 +342,7 @@ export const SPACE_WITH_MULTIPLE_CHANGES_CHANGES = { }, { name: 'Conceptualisation', + id: '5ea029faf851e7716e372305', change: UPDATED, items: [ { @@ -352,6 +353,7 @@ export const SPACE_WITH_MULTIPLE_CHANGES_CHANGES = { }, { name: 'Investigation', + id: '5ea029faf851e7716e372308', change: REMOVED, items: [ { @@ -362,6 +364,7 @@ export const SPACE_WITH_MULTIPLE_CHANGES_CHANGES = { }, { name: 'Conclusion', + id: '5ea029fbf851e7716e37230b', change: UPDATED, items: [ { diff --git a/test/fixtures/users.js b/test/fixtures/users.js index 24b87bed..e88becba 100644 --- a/test/fixtures/users.js +++ b/test/fixtures/users.js @@ -1,31 +1,41 @@ import { USER_MODES } from '../../src/config/constants'; export const USER_GRAASP = { - name: 'graasp', + username: 'graasp', id: 'graasp-id', - mode: USER_MODES.TEACHER, + settings: { + userMode: USER_MODES.TEACHER, + }, }; export const USER_ALICE = { - name: 'alice', + username: 'alice', id: 'alice-id', - mode: USER_MODES.TEACHER, + settings: { + userMode: USER_MODES.TEACHER, + }, }; export const USER_BOB = { - name: 'bob', + username: 'bob', id: 'bob-id', - mode: USER_MODES.STUDENT, + settings: { + userMode: USER_MODES.STUDENT, + }, }; export const USER_SAM = { - name: 'sam', + username: 'sam', id: 'sam-id', - mode: USER_MODES.STUDENT, + settings: { + userMode: USER_MODES.STUDENT, + }, }; export const USER_CEDRIC = { - name: 'cedric', + username: 'cedric', id: 'cedric-id', - mode: USER_MODES.TEACHER, + settings: { + userMode: USER_MODES.TEACHER, + }, }; diff --git a/test/menu.test.js b/test/menu.test.js index 5e0819be..2ef636df 100644 --- a/test/menu.test.js +++ b/test/menu.test.js @@ -3,7 +3,6 @@ /* eslint-disable func-names */ import { mochaAsync, - userSignIn, menuGoToSpacesNearby, menuGoToVisitSpace, menuGoToLoadSpace, @@ -13,7 +12,6 @@ import { } from './utils'; import { createApplication, closeApplication } from './application'; import { DEFAULT_GLOBAL_TIMEOUT } from './constants'; -import { USER_GRAASP } from './fixtures/users'; describe('Menu Scenarios', function () { this.timeout(DEFAULT_GLOBAL_TIMEOUT); @@ -21,7 +19,6 @@ describe('Menu Scenarios', function () { before( mochaAsync(async () => { app = await createApplication(); - await userSignIn(app.client, USER_GRAASP); }) ); diff --git a/test/settings.test.js b/test/settings.test.js index a45494dc..006e7612 100644 --- a/test/settings.test.js +++ b/test/settings.test.js @@ -36,6 +36,8 @@ import { SYNC_ADVANCED_MAIN_ID, SYNC_CANCEL_BUTTON_ID, SETTINGS_TITLE_ID, + MAINMENU_ID, + SPACES_NEARBY_MAIN_ID, } from '../src/config/selectors'; import { DEFAULT_GLOBAL_TIMEOUT, @@ -53,40 +55,33 @@ import { import { USER_GRAASP, USER_ALICE, USER_CEDRIC } from './fixtures/users'; import { settingsPerUser } from './fixtures/settings'; import { loadSpaceById } from './spaces/loadSpace.test'; -import { - SPACE_WITH_REMOVAL, - SPACE_WITH_REMOVAL_PATH, -} from './fixtures/syncSpace'; +import { SPACE_WITH_REMOVAL } from './fixtures/syncSpace'; const isLanguageSetTo = async (client, value) => { - const lang = await client.getAttribute( - `#${LANGUAGE_SELECT_ID} input`, - 'value' - ); + const lang = await ( + await client.$(`#${LANGUAGE_SELECT_ID} input`) + ).getAttribute('value'); expect(lang).to.equal(value); }; const isGeolocationEnabledSetTo = async (client, value) => { - const geolocationEnabled = await client.getAttribute( - `#${GEOLOCATION_CONTROL_ID} input`, - 'value' - ); + const geolocationEnabled = await ( + await client.$(`#${GEOLOCATION_CONTROL_ID} input`) + ).getAttribute('value'); expect(JSON.parse(geolocationEnabled)).to.equal(value); }; const isDeveloperModeSetTo = async (client, value) => { - const developer = await client.getAttribute( - `#${DEVELOPER_SWITCH_ID} input`, - 'value' - ); + const developer = await ( + await client.$(`#${DEVELOPER_SWITCH_ID} input`) + ).getAttribute('value'); expect(JSON.parse(developer)).to.equal(value); }; const isSyncAdvancedModeSetTo = async (client, value) => { - const mode = await client.getAttribute( - `#${SYNC_MODE_SWITCH_ID} input`, - 'value' - ); + const mode = await ( + await client.$(`#${SYNC_MODE_SWITCH_ID} input`) + ).getAttribute('value'); const booleanToMode = JSON.parse(mode) ? SYNC_MODES.ADVANCED : SYNC_MODES.VISUAL; @@ -105,7 +100,6 @@ describe('Settings Scenarios', function () { beforeEach( mochaAsync(async () => { app = await createApplication(); - await userSignIn(app.client, USER_GRAASP); }) ); @@ -133,7 +127,11 @@ describe('Settings Scenarios', function () { // check developer mode tab doesn't exist await openDrawer(client); - await expectElementToNotExist(client, `#${DEVELOPER_MENU_ITEM_ID}`); + await expectElementToNotExist( + client, + `#${MAINMENU_ID}`, + DEVELOPER_MENU_ITEM_ID + ); // enable developer mode, check tab exist await menuGoToSettings(client); @@ -162,12 +160,16 @@ describe('Settings Scenarios', function () { await client.pause(LOAD_SPACE_PAUSE); // geolocation button should not exist - await expectElementToNotExist(client, `#${GEOLOCATION_CONTROL_ID}`); + await expectElementToNotExist( + client, + `#${SPACES_NEARBY_MAIN_ID}`, + GEOLOCATION_CONTROL_ID + ); // spaces should be displayed - await expectAnyElementToExist(client, [ - `.${SPACE_CARD_CLASS}`, - `#${SPACE_NOT_AVAILABLE_TEXT_ID}`, + await expectAnyElementToExist(client, `#${SPACES_NEARBY_MAIN_ID}`, [ + SPACE_CARD_CLASS, + SPACE_NOT_AVAILABLE_TEXT_ID, ]); }) ); @@ -232,10 +234,11 @@ describe('Settings Scenarios', function () { const { client } = app; const { space: { id }, + path: spacePath, } = SPACE_WITH_REMOVAL; // init with a modified space - await loadSpaceById(client, SPACE_WITH_REMOVAL_PATH); + await loadSpaceById(client, spacePath); const syncButton = await client.$( `#${buildSpaceCardId(id)} .${SPACE_SYNC_BUTTON_CLASS}` @@ -265,7 +268,7 @@ describe('Settings Scenarios', function () { describe('Use multiple users', function () { beforeEach( mochaAsync(async () => { - app = await createApplication(); + app = await createApplication({ database: {} }); }) ); @@ -280,7 +283,7 @@ describe('Settings Scenarios', function () { developerMode, geolocationEnabled, syncMode, - } = settingsPerUser[user.name]; + } = settingsPerUser[user.username]; await userSignIn(client, user); @@ -311,7 +314,7 @@ describe('Settings Scenarios', function () { developerMode, geolocationEnabled, syncMode, - } = settingsPerUser[user.name]; + } = settingsPerUser[user.username]; await userSignIn(client, user); diff --git a/test/spaceSearch.test.js b/test/spaceSearch.test.js index 912021fc..3a15efd1 100644 --- a/test/spaceSearch.test.js +++ b/test/spaceSearch.test.js @@ -3,60 +3,62 @@ /* eslint-disable no-restricted-syntax */ /* eslint-disable func-names */ import { expect } from 'chai'; -import { mochaAsync, userSignIn } from './utils'; +import { menuGoToSavedSpaces, mochaAsync, clearInput } from './utils'; import { createApplication, closeApplication } from './application'; import { SPACE_SEARCH_INPUT_ID, SPACE_MEDIA_CARD_CLASS, + SPACE_NOT_AVAILABLE_TEXT_ID, } from '../src/config/selectors'; import { + buildSignedUserForDatabase, DEFAULT_GLOBAL_TIMEOUT, SPACE_SEARCH_PAUSE, - TOOLTIP_FADE_OUT_PAUSE, } from './constants'; -import { USER_GRAASP } from './fixtures/users'; -import { loadSpaceById } from './spaces/loadSpace.test'; import { searchSpacesFixtures } from './fixtures/searchSpaces'; +import { SPACE_ATOMIC_STRUCTURE, SPACE_APOLLO_11 } from './fixtures/spaces'; const searchQuery = async (client, query) => { - await (await client.$(`#${SPACE_SEARCH_INPUT_ID}`)).setValue(query); + await clearInput(client, `#${SPACE_SEARCH_INPUT_ID}`); + const input = await client.$(`#${SPACE_SEARCH_INPUT_ID}`); + await input.setValue(query); await client.pause(SPACE_SEARCH_PAUSE); }; describe('Space Search Scenarios', function () { this.timeout(DEFAULT_GLOBAL_TIMEOUT); let app; - beforeEach( + before( mochaAsync(async () => { - app = await createApplication(); - await userSignIn(app.client, USER_GRAASP); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE, SPACE_APOLLO_11], + ...buildSignedUserForDatabase(), + }, + }); }) ); - afterEach(function () { + after(function () { return closeApplication(app); }); - searchSpacesFixtures.forEach(([spaceFilepaths, query, resultSpaceIds]) => { + searchSpacesFixtures.forEach(([query, resultSpaceIds]) => { it( `Search query "${query}" displays correct spaces`, mochaAsync(async () => { const { client } = app; - for (const filepath of spaceFilepaths) { - await loadSpaceById(client, filepath); - } - - await client.pause(TOOLTIP_FADE_OUT_PAUSE); + await menuGoToSavedSpaces(client); await searchQuery(client, query); // if expect no matching space if (resultSpaceIds.length === 0) { const isCardExisting = await ( - await client.$(`.${SPACE_MEDIA_CARD_CLASS}`) + await client.$(`#${SPACE_NOT_AVAILABLE_TEXT_ID}`) ).isExisting(); - expect(isCardExisting).to.be.false; + expect(isCardExisting).to.be.true; } else { // check displayed cards are result space ids const cardIds = []; diff --git a/test/spaces/clearUserInput.test.js b/test/spaces/clearUserInput.test.js index be2ebf91..f2be8587 100644 --- a/test/spaces/clearUserInput.test.js +++ b/test/spaces/clearUserInput.test.js @@ -8,6 +8,7 @@ import { menuGoToSavedSpaces, menuGoToPhase, menuGoToSignOut, + clickOnSpaceCard, } from '../utils'; import { createApplication, closeApplication } from '../application'; import { @@ -15,13 +16,13 @@ import { SPACE_CLEAR_BUTTON_CLASS, SPACE_CARD_LINK_CLASS, } from '../../src/config/selectors'; +import { SPACE_ATOMIC_STRUCTURE } from '../fixtures/spaces'; import { - SPACE_ATOMIC_STRUCTURE, - SPACE_ATOMIC_STRUCTURE_PATH, -} from '../fixtures/spaces'; -import { loadSpaceById } from './loadSpace.test'; -import { DEFAULT_GLOBAL_TIMEOUT, TOOLTIP_FADE_OUT_PAUSE } from '../constants'; -import { USER_GRAASP, USER_BOB, USER_ALICE } from '../fixtures/users'; + buildSignedUserForDatabase, + DEFAULT_GLOBAL_TIMEOUT, + TOOLTIP_FADE_OUT_PAUSE, +} from '../constants'; +import { USER_BOB, USER_ALICE } from '../fixtures/users'; import { typeInTextInputApp, checkTextInputAppContainsText, @@ -40,8 +41,13 @@ describe('Clear User Input in a space', function () { describe('Mock positive response for dialog', function () { beforeEach( mochaAsync(async () => { - app = await createApplication({ showMessageDialogResponse: 1 }); - await userSignIn(app.client, USER_GRAASP); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE], + ...buildSignedUserForDatabase(), + }, + responses: { showMessageDialogResponse: 1 }, + }); }) ); @@ -57,8 +63,8 @@ describe('Clear User Input in a space', function () { const text0 = 'some user input orientation'; const text1 = 'some user input conceptualisation'; - // load space with user input - await loadSpaceById(client, SPACE_ATOMIC_STRUCTURE_PATH, spaceId); + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, spaceId); // add user input await menuGoToPhase(client, 0); @@ -97,8 +103,8 @@ describe('Clear User Input in a space', function () { const text0 = 'some user input orientation'; const text1 = 'some user input conceptualisation'; - // load space with user input - await loadSpaceById(client, SPACE_ATOMIC_STRUCTURE_PATH, id); + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, id); // add user input await menuGoToPhase(client, 0); @@ -119,7 +125,6 @@ describe('Clear User Input in a space', function () { `#${buildSpaceCardId(id)} .${SPACE_CLEAR_BUTTON_CLASS}` ); await clearButton.click(); - await client.pause(TOOLTIP_FADE_OUT_PAUSE); // check app doesn't contain user input const spaceCard = await client.$( @@ -137,8 +142,13 @@ describe('Clear User Input in a space', function () { describe('Mock negative response for dialog', function () { beforeEach( mochaAsync(async () => { - app = await createApplication({ showMessageDialogResponse: 0 }); - await userSignIn(app.client, USER_GRAASP); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE], + ...buildSignedUserForDatabase(), + }, + responses: { showMessageDialogResponse: 0 }, + }); }) ); @@ -154,8 +164,8 @@ describe('Clear User Input in a space', function () { const text0 = 'some user input orientation'; const text1 = 'some user input conceptualisation'; - // load space with user input - await loadSpaceById(client, SPACE_ATOMIC_STRUCTURE_PATH, spaceId); + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, spaceId); // add user input await menuGoToPhase(client, 0); @@ -179,7 +189,12 @@ describe('Clear User Input in a space', function () { describe('Use graasp user', function () { beforeEach( mochaAsync(async () => { - app = await createApplication({ showMessageDialogResponse: 1 }); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE], + }, + responses: { showMessageDialogResponse: 1 }, + }); }) ); @@ -200,8 +215,8 @@ describe('Clear User Input in a space', function () { // login as Alice, save user input await userSignIn(client, USER_ALICE); - // load space with user input - await loadSpaceById(client, SPACE_ATOMIC_STRUCTURE_PATH, id); + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, id); // add user input await menuGoToPhase(client, 0); @@ -213,10 +228,7 @@ describe('Clear User Input in a space', function () { // login as bob, save user input await userSignIn(client, USER_BOB); await menuGoToSavedSpaces(client); - const spaceCard = await client.$( - `#${buildSpaceCardId(id)} .${SPACE_CARD_LINK_CLASS}` - ); - await spaceCard.click(); + await clickOnSpaceCard(client, id); await menuGoToPhase(client, 0); await typeInTextInputApp(client, textInputAppId0, textBob0); await menuGoToPhase(client, 1); @@ -226,7 +238,7 @@ describe('Clear User Input in a space', function () { // login as Alice, clear user input await userSignIn(client, USER_ALICE); await menuGoToSavedSpaces(client); - await spaceCard.click(); + await clickOnSpaceCard(client, id); await menuGoToPhase(client, 0); await checkTextInputAppContainsText( client, @@ -245,9 +257,7 @@ describe('Clear User Input in a space', function () { // login as Bob, check user input are still saved await userSignIn(client, USER_BOB); await menuGoToSavedSpaces(client); - await ( - await client.$(`#${buildSpaceCardId(id)} .${SPACE_CARD_LINK_CLASS}`) - ).click(); + await clickOnSpaceCard(client, id); await menuGoToPhase(client, 0); await checkTextInputAppContainsText(client, textInputAppId0, textBob0); await menuGoToPhase(client, 1); diff --git a/test/spaces/deleteSpace.test.js b/test/spaces/deleteSpace.test.js index 16a4f367..ec4ae962 100644 --- a/test/spaces/deleteSpace.test.js +++ b/test/spaces/deleteSpace.test.js @@ -5,9 +5,9 @@ import { expect } from 'chai'; import { mochaAsync, - userSignIn, menuGoToSavedSpaces, expectElementToExist, + clickOnSpaceCard, } from '../utils'; import { createApplication, closeApplication } from '../application'; import { @@ -15,9 +15,10 @@ import { SPACE_DELETE_BUTTON_CLASS, } from '../../src/config/selectors'; import { SPACE_ATOMIC_STRUCTURE } from '../fixtures/spaces'; -import { visitAndSaveSpaceById } from './visitSpace.test'; -import { DEFAULT_GLOBAL_TIMEOUT } from '../constants'; -import { USER_GRAASP } from '../fixtures/users'; +import { + buildSignedUserForDatabase, + DEFAULT_GLOBAL_TIMEOUT, +} from '../constants'; describe('Delete a space', function () { this.timeout(DEFAULT_GLOBAL_TIMEOUT); @@ -34,14 +35,16 @@ describe('Delete a space', function () { space: { id }, } = SPACE_ATOMIC_STRUCTURE; - app = await createApplication({ showMessageDialogResponse: 1 }); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE], + ...buildSignedUserForDatabase(), + }, + responses: { showMessageDialogResponse: 1 }, + }); const { client } = app; - await userSignIn(client, USER_GRAASP); - - await visitAndSaveSpaceById(client, id); - await menuGoToSavedSpaces(client); const deleteButton = await client.$( @@ -62,13 +65,18 @@ describe('Delete a space', function () { space: { id }, } = SPACE_ATOMIC_STRUCTURE; - app = await createApplication({ showMessageDialogResponse: 1 }); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE], + ...buildSignedUserForDatabase(), + }, + responses: { showMessageDialogResponse: 1 }, + }); const { client } = app; - await userSignIn(client, USER_GRAASP); - - await visitAndSaveSpaceById(client, id); + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, id); const deleteButton = await client.$(`.${SPACE_DELETE_BUTTON_CLASS}`); await deleteButton.click(); @@ -86,15 +94,21 @@ describe('Delete a space', function () { space: { id }, } = SPACE_ATOMIC_STRUCTURE; - app = await createApplication({ showMessageDialogResponse: 0 }); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE], + ...buildSignedUserForDatabase(), + }, + responses: { showMessageDialogResponse: 0 }, + }); const { client } = app; - await userSignIn(client, USER_GRAASP); - - await visitAndSaveSpaceById(client, id); + await menuGoToSavedSpaces(client); - const deleteButton = await client.$(`.${SPACE_DELETE_BUTTON_CLASS}`); + const deleteButton = await client.$( + `#${buildSpaceCardId(id)} .${SPACE_DELETE_BUTTON_CLASS}` + ); await deleteButton.click(); await menuGoToSavedSpaces(client); diff --git a/test/spaces/exportSpace.test.js b/test/spaces/exportSpace.test.js index 29f03c4a..a53ceb34 100644 --- a/test/spaces/exportSpace.test.js +++ b/test/spaces/exportSpace.test.js @@ -9,8 +9,7 @@ import { createRandomString, expectElementToExist, menuGoToSavedSpaces, - menuGoToPhase, - userSignIn, + clickOnSpaceCard, } from '../utils'; import { createApplication, closeApplication } from '../application'; import { @@ -22,19 +21,17 @@ import { } from '../../src/config/selectors'; import { SPACE_ATOMIC_STRUCTURE, + SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES, SPACE_WITH_FILE_DROP, } from '../fixtures/spaces'; -import { hasSavedSpaceLayout, visitAndSaveSpaceById } from './visitSpace.test'; +import { hasSavedSpaceLayout } from './visitSpace.test'; import { - EXPORT_SPACE_PAUSE, EXPORT_FILEPATH, DEFAULT_GLOBAL_TIMEOUT, - EXPORT_SELECTION_SPACE_PAUSE, TOOLTIP_FADE_OUT_PAUSE, OPEN_SAVED_SPACE_PAUSE, + buildSignedUserForDatabase, } from '../constants'; -import { USER_GRAASP } from '../fixtures/users'; -import { typeInTextInputApp } from '../apps/textInputApp'; // eslint-disable-next-line import/prefer-default-export export const exportSpaceWithSelected = async ( @@ -97,23 +94,22 @@ describe('Export a space', function () { it( 'Exporting from toolbar saves space in local computer', mochaAsync(async () => { - const { - space: { id }, - } = SPACE_ATOMIC_STRUCTURE; - const filepath = `${EXPORT_FILEPATH}_${createRandomString()}`; - app = await createApplication({ showSaveDialogResponse: filepath }); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE], + ...buildSignedUserForDatabase(), + }, + responses: { showSaveDialogResponse: filepath }, + }); const { client } = app; - await userSignIn(client, USER_GRAASP); - - await visitAndSaveSpaceById(client, id); - + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, SPACE_ATOMIC_STRUCTURE.space.id); const exportButton = await client.$(`.${SPACE_EXPORT_BUTTON_CLASS}`); await exportButton.click(); - await client.pause(EXPORT_SELECTION_SPACE_PAUSE); await exportSpaceWithSelected(client); @@ -130,27 +126,27 @@ describe('Export a space', function () { } = SPACE_ATOMIC_STRUCTURE; const filepath = `${EXPORT_FILEPATH}_${createRandomString()}`; - app = await createApplication({ showSaveDialogResponse: filepath }); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE], + ...buildSignedUserForDatabase(), + }, + responses: { showSaveDialogResponse: filepath }, + }); const { client } = app; - await userSignIn(client, USER_GRAASP); - - await visitAndSaveSpaceById(client, id); - await menuGoToSavedSpaces(client); const exportButton = await client.$( `#${buildSpaceCardId(id)} .${SPACE_EXPORT_BUTTON_CLASS}` ); await exportButton.click(); - await client.pause(EXPORT_SELECTION_SPACE_PAUSE); // back and export again const backButton = await client.$(`#${EXPORT_SPACE_BACK_BUTTON_ID}`); await backButton.click(); await exportButton.click(); - await client.pause(EXPORT_SELECTION_SPACE_PAUSE); await exportSpaceWithSelected(client); @@ -166,21 +162,22 @@ describe('Export a space', function () { const { id } = space; const filepath = `${EXPORT_FILEPATH}_${createRandomString()}`; - app = await createApplication({ showSaveDialogResponse: filepath }); + app = await createApplication({ + database: { + spaces: [SPACE_WITH_FILE_DROP], + ...buildSignedUserForDatabase(), + }, + responses: { showSaveDialogResponse: filepath }, + }); const { client } = app; - await userSignIn(client, USER_GRAASP); - - await visitAndSaveSpaceById(client, id); - await menuGoToSavedSpaces(client); const exportButton = await client.$( `#${buildSpaceCardId(id)} .${SPACE_EXPORT_BUTTON_CLASS}` ); await exportButton.click(); - await client.pause(EXPORT_SELECTION_SPACE_PAUSE); await exportSpaceWithSelected(client); @@ -201,23 +198,26 @@ describe('Export a space', function () { it( 'space only', mochaAsync(async () => { - const { - space: { id }, - } = SPACE_ATOMIC_STRUCTURE; - const filepath = `${EXPORT_FILEPATH}_${createRandomString()}`; - app = await createApplication({ showSaveDialogResponse: filepath }); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE], + ...buildSignedUserForDatabase(), + }, + responses: { showSaveDialogResponse: filepath }, + }); const { client } = app; - await userSignIn(client, USER_GRAASP); - - // visit and save space - await visitAndSaveSpaceById(client, id); + await menuGoToSavedSpaces(client); // export from card - await (await client.$(`.${SPACE_EXPORT_BUTTON_CLASS}`)).click(); - await client.pause(EXPORT_SPACE_PAUSE); + const exportButton = await client.$( + `#${buildSpaceCardId( + SPACE_ATOMIC_STRUCTURE.space.id + )} .${SPACE_EXPORT_BUTTON_CLASS}` + ); + await exportButton.click(); await checkExportSelectionLayout(client); @@ -230,29 +230,26 @@ describe('Export a space', function () { it( 'space with actions and resources', mochaAsync(async () => { - const { - space: { id, phases }, - } = SPACE_ATOMIC_STRUCTURE; - const { id: textInputAppId0 } = phases[0].items[1]; - const text = 'some user input orientation'; - const filepath = `${EXPORT_FILEPATH}_${createRandomString()}`; - app = await createApplication({ showSaveDialogResponse: filepath }); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES], + ...buildSignedUserForDatabase(), + }, + responses: { showSaveDialogResponse: filepath }, + }); const { client } = app; - await userSignIn(client, USER_GRAASP); - - // visit and save space - await visitAndSaveSpaceById(client, id); - - // write in text input - await menuGoToPhase(client, 0); - await typeInTextInputApp(client, textInputAppId0, text); + await menuGoToSavedSpaces(client); // export from card - await (await client.$(`.${SPACE_EXPORT_BUTTON_CLASS}`)).click(); - await client.pause(EXPORT_SPACE_PAUSE); + const exportButton = await client.$( + `#${buildSpaceCardId( + SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES.space.id + )} .${SPACE_EXPORT_BUTTON_CLASS}` + ); + await exportButton.click(); await checkExportSelectionLayout(client, { actions: true, diff --git a/test/spaces/favoriteSpace.test.js b/test/spaces/favoriteSpace.test.js index df461422..9cfec2c9 100644 --- a/test/spaces/favoriteSpace.test.js +++ b/test/spaces/favoriteSpace.test.js @@ -17,12 +17,14 @@ import { SPACE_FAVORITE_BUTTON_CLASS, SPACE_CARD_LINK_CLASS, FAVORITE_SPACES_WRAPPER_ID, + HOME_MAIN_ID, } from '../../src/config/selectors'; import { SPACE_ATOMIC_STRUCTURE } from '../fixtures/spaces'; import { visitAndSaveSpaceById } from './visitSpace.test'; import { SET_SPACE_AS_FAVORITE_PAUSE, DEFAULT_GLOBAL_TIMEOUT, + buildSignedUserForDatabase, } from '../constants'; import { USER_GRAASP, USER_ALICE, USER_BOB } from '../fixtures/users'; @@ -37,8 +39,12 @@ describe('Set space as favorite', function () { describe('Buttons', function () { beforeEach( mochaAsync(async () => { - app = await createApplication(); - await userSignIn(app.client, USER_GRAASP); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE], + ...buildSignedUserForDatabase(USER_GRAASP), + }, + }); }) ); @@ -51,8 +57,6 @@ describe('Set space as favorite', function () { const { client } = app; - await visitAndSaveSpaceById(client, id); - await menuGoToSavedSpaces(client); const favoriteButton = await client.$( @@ -74,7 +78,8 @@ describe('Set space as favorite', function () { // space should not be in favorite spaces await expectElementToNotExist( client, - `#${FAVORITE_SPACES_WRAPPER_ID} #${buildSpaceCardId(id)}` + `#${HOME_MAIN_ID}`, + buildSpaceCardId(id) ); }) ); @@ -88,7 +93,7 @@ describe('Set space as favorite', function () { const { client } = app; - await visitAndSaveSpaceById(client, id); + await menuGoToSavedSpaces(client); const favoriteButton = await client.$( `.${SPACE_FAVORITE_BUTTON_CLASS}` @@ -112,9 +117,11 @@ describe('Set space as favorite', function () { // space should not be in home await menuGoToHome(client); + // no favorite spaces at all await expectElementToNotExist( client, - `#${FAVORITE_SPACES_WRAPPER_ID} #${buildSpaceCardId(id)}` + `#${HOME_MAIN_ID}`, + FAVORITE_SPACES_WRAPPER_ID ); }) ); @@ -124,7 +131,7 @@ describe('Set space as favorite', function () { it( 'Set a space as favorite is different per user', mochaAsync(async () => { - app = await createApplication(); + app = await createApplication({ database: {} }); const { space: { id }, @@ -143,7 +150,11 @@ describe('Set space as favorite', function () { // sign in with bob, no favorite await userSignIn(app.client, USER_BOB); - await expectElementToNotExist(client, `#${buildSpaceCardId(id)}`); + await expectElementToNotExist( + client, + `#${HOME_MAIN_ID}`, + buildSpaceCardId(id) + ); await menuGoToSignOut(client); // sign in with alice, still favorite diff --git a/test/spaces/loadSpace.test.js b/test/spaces/loadSpace.test.js index 7f104759..b56ced28 100644 --- a/test/spaces/loadSpace.test.js +++ b/test/spaces/loadSpace.test.js @@ -8,11 +8,9 @@ import { mochaAsync, createRandomString, expectElementToExist, - toggleStudentMode, menuGoToLoadSpace, menuGoToHome, menuGoToSavedSpaces, - menuGoToSettings, userSignIn, } from '../utils'; import { createApplication, closeApplication } from '../application'; @@ -32,12 +30,8 @@ import { } from '../../src/config/selectors'; import { SPACE_ATOMIC_STRUCTURE, - SPACE_ATOMIC_STRUCTURE_PATH, SPACE_WITH_MULTIPLE_CHANGES, - SPACE_WITH_MULTIPLE_CHANGES_PATH, SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES, - SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH, - SPACE_WITH_FILE_DROP_PATH, SPACE_WITH_FILE_DROP, } from '../fixtures/spaces'; import { hasSavedSpaceLayout, visitAndSaveSpaceById } from './visitSpace.test'; @@ -181,8 +175,6 @@ describe('Load Space Scenarios', function () { beforeEach( mochaAsync(async () => { app = await createApplication(); - globalUser = USER_GRAASP; - await userSignIn(app.client, globalUser); }) ); @@ -216,7 +208,7 @@ describe('Load Space Scenarios', function () { const absolutePath = path.resolve( __dirname, '../fixtures/spaces', - SPACE_ATOMIC_STRUCTURE_PATH + SPACE_ATOMIC_STRUCTURE.path ); const loadInput = await client.$(`#${LOAD_INPUT_ID}`); await loadInput.setValue(absolutePath); @@ -228,12 +220,12 @@ describe('Load Space Scenarios', function () { await loadSpaceById( client, - SPACE_ATOMIC_STRUCTURE_PATH, + SPACE_ATOMIC_STRUCTURE.path, SPACE_ATOMIC_STRUCTURE.space.id ); await hasSavedSpaceLayout(client, SPACE_ATOMIC_STRUCTURE, { - user: globalUser, + user: USER_GRAASP, }); }) ); @@ -245,12 +237,12 @@ describe('Load Space Scenarios', function () { await loadSpaceById( client, - SPACE_WITH_FILE_DROP_PATH, + SPACE_WITH_FILE_DROP.path, SPACE_WITH_FILE_DROP.space.id ); await hasSavedSpaceLayout(client, SPACE_WITH_FILE_DROP, { - user: globalUser, + user: USER_GRAASP, }); }) ); @@ -269,11 +261,11 @@ describe('Load Space Scenarios', function () { await visitAndSaveSpaceById(client, id); // load space - await loadSpaceById(client, SPACE_WITH_MULTIPLE_CHANGES_PATH, id); + await loadSpaceById(client, SPACE_WITH_MULTIPLE_CHANGES.path, id); // check content has changed await hasSavedSpaceLayout(client, SPACE_WITH_MULTIPLE_CHANGES, { - user: globalUser, + user: USER_GRAASP, }); }) ); @@ -292,7 +284,7 @@ describe('Load Space Scenarios', function () { // load space await loadSpaceById( client, - SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH, + SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES.path, undefined, { space: false, actions: true, resources: true }, { actions: true, resources: true } @@ -306,7 +298,7 @@ describe('Load Space Scenarios', function () { await hasSavedSpaceLayout( client, SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES, - { resources: appInstanceResources, user: globalUser } + { resources: appInstanceResources, user: USER_GRAASP } ); }) ); @@ -321,7 +313,7 @@ describe('Load Space Scenarios', function () { // load space without actions and resources await loadSpaceById( client, - SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH, + SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES.path, undefined, { space: true, actions: true, resources: true }, { actions: false, resources: false } @@ -335,7 +327,7 @@ describe('Load Space Scenarios', function () { await hasSavedSpaceLayout( client, SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES, - { user: globalUser } + { user: USER_GRAASP } ); }) ); @@ -343,17 +335,12 @@ describe('Load Space Scenarios', function () { }); describe('Predefined Export Spaces for Student', function () { - beforeEach( - mochaAsync(async () => { - app = await createApplication(); - globalUser = USER_BOB; - await userSignIn(app.client, USER_BOB); - }) - ); - it( `Cannot load non-existing space ${SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES.space.name}`, mochaAsync(async () => { + app = await createApplication({ database: {} }); + await userSignIn(app.client, USER_BOB); + const { client } = app; // load space without actions and resources @@ -363,7 +350,7 @@ describe('Load Space Scenarios', function () { const absolutePath = path.resolve( __dirname, '../fixtures/spaces', - SPACE_ATOMIC_STRUCTURE_PATH + SPACE_ATOMIC_STRUCTURE.path ); const loadInput = await client.$(`#${LOAD_INPUT_ID}`); await loadInput.setValue(absolutePath); @@ -380,27 +367,25 @@ describe('Load Space Scenarios', function () { it( `Can only load actions and resources of ${SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES.space.name}`, mochaAsync(async () => { + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES], + }, + }); + globalUser = USER_BOB; + await userSignIn(app.client, USER_BOB); + const { client } = app; const { space: { id }, + path: spacePath, appInstanceResources, } = SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES; - // set teacher mode - await menuGoToSettings(client); - await toggleStudentMode(client, false); - - // get space - await visitAndSaveSpaceById(client, id); - - // set student mode - await menuGoToSettings(client); - await toggleStudentMode(client, true); - // load space without actions and resources await loadSpaceById( client, - SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES_PATH, + spacePath, id, { space: false, actions: true, resources: true }, { actions: true, resources: true } @@ -410,31 +395,29 @@ describe('Load Space Scenarios', function () { await hasSavedSpaceLayout( client, SPACE_ATOMIC_STRUCTURE_WITH_ACTIONS_AND_RESOURCES, - { resources: appInstanceResources, user: globalUser } + { resources: appInstanceResources, user: USER_BOB } ); }) ); }); describe('Load from app created export files', function () { - this.retries(2); - it( `Load exported space of ${SPACE_ATOMIC_STRUCTURE.space.name}`, mochaAsync(async () => { - globalUser = USER_GRAASP; const { space: { id }, } = SPACE_ATOMIC_STRUCTURE; const filepath = `${EXPORT_FILEPATH}_${createRandomString()}.zip`; app = await createApplication({ - showSaveDialogResponse: filepath, - showMessageDialogResponse: 1, + responses: { + showSaveDialogResponse: filepath, + showMessageDialogResponse: 1, + }, }); const { client } = app; - await userSignIn(client, globalUser); // get space await visitAndSaveSpaceById(client, id); @@ -460,7 +443,7 @@ describe('Load Space Scenarios', function () { // check content await hasSavedSpaceLayout(client, SPACE_ATOMIC_STRUCTURE, { - user: globalUser, + user: USER_GRAASP, }); }) ); @@ -475,12 +458,13 @@ describe('Load Space Scenarios', function () { const filepath = `${EXPORT_FILEPATH}_${createRandomString()}.zip`; app = await createApplication({ - showSaveDialogResponse: filepath, - showMessageDialogResponse: 1, + responses: { + showSaveDialogResponse: filepath, + showMessageDialogResponse: 1, + }, }); const { client } = app; - await userSignIn(client, globalUser); // get space await visitAndSaveSpaceById(client, id); @@ -550,14 +534,14 @@ describe('Load Space Scenarios', function () { const filepath = `${EXPORT_FILEPATH}_${createRandomString()}.zip`; app = await createApplication({ - showSaveDialogResponse: filepath, - showMessageDialogResponse: 1, + responses: { + showSaveDialogResponse: filepath, + showMessageDialogResponse: 1, + }, }); const { client } = app; - await userSignIn(client, globalUser); - // get space await visitAndSaveSpaceById(client, id); diff --git a/test/spaces/recentSpace.test.js b/test/spaces/recentSpace.test.js index 5c9704ac..dd2ac87c 100644 --- a/test/spaces/recentSpace.test.js +++ b/test/spaces/recentSpace.test.js @@ -16,10 +16,10 @@ import { buildSpaceCardId, SPACE_MEDIA_CARD_CLASS, RECENT_SPACES_WRAPPER_ID, + HOME_MAIN_ID, } from '../../src/config/selectors'; import { SPACE_ATOMIC_STRUCTURE, - SPACE_ATOMIC_STRUCTURE_PATH, SPACE_APOLLO_11, SPACE_AIR_POLLUTION, SPACE_LIGHT_COLOR, @@ -43,7 +43,6 @@ describe('Recent Spaces', function () { beforeEach( mochaAsync(async () => { app = await createApplication(); - await userSignIn(app.client, USER_GRAASP); }) ); @@ -53,11 +52,12 @@ describe('Recent Spaces', function () { mochaAsync(async () => { const { space: { id }, + path, } = SPACE_ATOMIC_STRUCTURE; const { client } = app; - await loadSpaceById(client, SPACE_ATOMIC_STRUCTURE_PATH); + await loadSpaceById(client, path); // check space is in home await menuGoToHome(client); @@ -153,7 +153,11 @@ describe('Recent Spaces', function () { // sign in as Bob, no recent spaces await userSignIn(client, USER_BOB); - await expectElementToNotExist(client, `#${buildSpaceCardId(id)}`); + await expectElementToNotExist( + client, + `#${HOME_MAIN_ID}`, + buildSpaceCardId(id) + ); await menuGoToSignOut(client); // sign in as graasp, recent spaces still saved diff --git a/test/spaces/saveSpace.test.js b/test/spaces/saveSpace.test.js index 3086f8e9..d37d39c0 100644 --- a/test/spaces/saveSpace.test.js +++ b/test/spaces/saveSpace.test.js @@ -2,12 +2,8 @@ /* eslint-disable no-await-in-loop */ /* eslint-disable no-restricted-syntax */ /* eslint-disable func-names */ -import { mochaAsync, userSignIn, menuGoToSavedSpaces } from '../utils'; +import { mochaAsync, menuGoToSavedSpaces, clickOnSpaceCard } from '../utils'; import { createApplication, closeApplication } from '../application'; -import { - buildSpaceCardId, - SPACE_CARD_LINK_CLASS, -} from '../../src/config/selectors'; import { SPACE_ATOMIC_STRUCTURE } from '../fixtures/spaces'; import { checkSpaceCardLayout, @@ -15,13 +11,12 @@ import { hasSavedSpaceHomeLayout, visitAndSaveSpaceById, } from './visitSpace.test'; -import { OPEN_SAVED_SPACE_PAUSE, DEFAULT_GLOBAL_TIMEOUT } from '../constants'; +import { DEFAULT_GLOBAL_TIMEOUT } from '../constants'; import { USER_GRAASP } from '../fixtures/users'; describe('Save a space', function () { this.timeout(DEFAULT_GLOBAL_TIMEOUT); let app; - let globalUser; afterEach(function () { return closeApplication(app); @@ -30,8 +25,6 @@ describe('Save a space', function () { beforeEach( mochaAsync(async () => { app = await createApplication(); - globalUser = USER_GRAASP; - await userSignIn(app.client, globalUser); }) ); it( @@ -45,7 +38,7 @@ describe('Save a space', function () { await visitAndSaveSpaceById(client, id); await hasSavedSpaceLayout(client, SPACE_ATOMIC_STRUCTURE, { - user: globalUser, + user: USER_GRAASP, }); // check space is referenced in saved spaces @@ -54,11 +47,7 @@ describe('Save a space', function () { await checkSpaceCardLayout(client, SPACE_ATOMIC_STRUCTURE); // go to space - const spaceCardLink = await client.$( - `#${buildSpaceCardId(id)} .${SPACE_CARD_LINK_CLASS}` - ); - await spaceCardLink.click(); - await client.pause(OPEN_SAVED_SPACE_PAUSE); + await clickOnSpaceCard(client, id); await hasSavedSpaceHomeLayout(client, { name, description }); }) diff --git a/test/spaces/saveUserInput.test.js b/test/spaces/saveUserInput.test.js index ffb6ef5c..932332a4 100644 --- a/test/spaces/saveUserInput.test.js +++ b/test/spaces/saveUserInput.test.js @@ -8,18 +8,14 @@ import { menuGoToSavedSpaces, menuGoToSignOut, menuGoToPhase, + clickOnSpaceCard, } from '../utils'; import { createApplication, closeApplication } from '../application'; +import { SPACE_ATOMIC_STRUCTURE } from '../fixtures/spaces'; import { - buildSpaceCardId, - SPACE_CARD_LINK_CLASS, -} from '../../src/config/selectors'; -import { - SPACE_ATOMIC_STRUCTURE, - SPACE_ATOMIC_STRUCTURE_PATH, -} from '../fixtures/spaces'; -import { loadSpaceById } from './loadSpace.test'; -import { SAVE_USER_INPUT_TIMEOUT, OPEN_SAVED_SPACE_PAUSE } from '../constants'; + SAVE_USER_INPUT_TIMEOUT, + buildSignedUserForDatabase, +} from '../constants'; import { USER_GRAASP, USER_BOB, USER_ALICE } from '../fixtures/users'; import { typeInTextInputApp, @@ -41,8 +37,13 @@ describe('Save User Input in a space', function () { describe('Use graasp user', function () { beforeEach( mochaAsync(async () => { - app = await createApplication({ showMessageDialogResponse: 1 }); - await userSignIn(app.client, USER_GRAASP); + app = await createApplication({ + database: { + spaces: [SPACE_ATOMIC_STRUCTURE], + ...buildSignedUserForDatabase(), + }, + responses: { showMessageDialogResponse: 1 }, + }); }) ); @@ -56,8 +57,8 @@ describe('Save User Input in a space', function () { } = SPACE_ATOMIC_STRUCTURE; const { id: textInputAppId } = phases[0].items[1]; - // load space with user input - await loadSpaceById(client, SPACE_ATOMIC_STRUCTURE_PATH, id); + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, id); // go to orientation tab await menuGoToPhase(client, 0); @@ -69,11 +70,7 @@ describe('Save User Input in a space', function () { await menuGoToSavedSpaces(client); // check user input is saved - const spaceCardLink = await client.$( - `#${buildSpaceCardId(id)} .${SPACE_CARD_LINK_CLASS}` - ); - await spaceCardLink.click(); - await client.pause(OPEN_SAVED_SPACE_PAUSE); + await clickOnSpaceCard(client, id); await menuGoToPhase(client, 0); await checkTextInputAppContainsText(client, textInputAppId, text); @@ -84,7 +81,10 @@ describe('Save User Input in a space', function () { describe('Multiple users scenarios', function () { beforeEach( mochaAsync(async () => { - app = await createApplication({ showMessageDialogResponse: 1 }); + app = await createApplication({ + database: { spaces: [SPACE_ATOMIC_STRUCTURE] }, + responses: { showMessageDialogResponse: 1 }, + }); }) ); @@ -99,25 +99,14 @@ describe('Save User Input in a space', function () { } = SPACE_ATOMIC_STRUCTURE; const { id: textInputAppId } = phases[0].items[1]; - for (const [index, user] of users.entries()) { + for (const user of users) { await userSignIn(app.client, user); await menuGoToSavedSpaces(client); - const text = userInputTextForUser(user.name); - - // first user load space - if (index === 0) { - // load space with user input - await loadSpaceById(client, SPACE_ATOMIC_STRUCTURE_PATH, id); - } - // next users go to home - // this should change if users don't share spaces - else { - const spaceCard = await client.$( - `#${buildSpaceCardId(id)} .${SPACE_CARD_LINK_CLASS}` - ); - await spaceCard.click(); - await client.pause(OPEN_SAVED_SPACE_PAUSE); - } + const text = userInputTextForUser(user.username); + + // note: this should change if users don't share spaces + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, id); // go to orientation tab await menuGoToPhase(client, 0); @@ -129,10 +118,7 @@ describe('Save User Input in a space', function () { await menuGoToSavedSpaces(client); // check user input is saved - const spaceCard = await client.$( - `#${buildSpaceCardId(id)} .${SPACE_CARD_LINK_CLASS}` - ); - await spaceCard.click(); + await clickOnSpaceCard(client, id); await menuGoToPhase(client, 0); await checkTextInputAppContainsText(client, textInputAppId, text); @@ -144,12 +130,9 @@ describe('Save User Input in a space', function () { for (const user of users) { await userSignIn(client, user); await menuGoToSavedSpaces(client); - const text = userInputTextForUser(user.name); + const text = userInputTextForUser(user.username); - const spaceCard = await client.$( - `#${buildSpaceCardId(id)} .${SPACE_CARD_LINK_CLASS}` - ); - await spaceCard.click(); + await clickOnSpaceCard(client, id); await menuGoToPhase(client, 0); await checkTextInputAppContainsText(client, textInputAppId, text); diff --git a/test/spaces/syncSpace.test.js b/test/spaces/syncSpace.test.js index a7f4811b..3cffa828 100644 --- a/test/spaces/syncSpace.test.js +++ b/test/spaces/syncSpace.test.js @@ -7,9 +7,8 @@ import { mochaAsync, expectElementToNotExist, expectElementToExist, - toggleSyncAdvancedMode, - userSignIn, - menuGoToSettings, + menuGoToSavedSpaces, + clickOnSpaceCard, } from '../utils'; import { createApplication, closeApplication } from '../application'; import { @@ -23,26 +22,21 @@ import { SPACE_THUMBNAIL_IMAGE_CLASS, SYNC_CANCEL_BUTTON_ID, SYNC_ADVANCED_MAIN_ID, + TOOLS_CONTENT_PANE_ID, } from '../../src/config/selectors'; import { SPACE_WITH_ADDITION, - SPACE_WITH_ADDITION_PATH, SPACE_WITH_ADDITION_CHANGES, SPACE_WITH_REMOVAL, SPACE_WITH_REMOVAL_CHANGES, - SPACE_WITH_REMOVAL_PATH, SPACE_WITH_UPDATE, SPACE_WITH_UPDATE_CHANGES, - SPACE_WITH_UPDATE_PATH, SPACE_WITH_MOVE, SPACE_WITH_MOVE_CHANGES, - SPACE_WITH_MOVE_PATH, SPACE_WITH_TOOLS_UPDATE, SPACE_WITH_TOOLS_UPDATE_CHANGES, - SPACE_WITH_TOOLS_UPDATE_PATH, SPACE_WITH_MULTIPLE_CHANGES, SPACE_WITH_MULTIPLE_CHANGES_CHANGES, - SPACE_WITH_MULTIPLE_CHANGES_PATH, } from '../fixtures/syncSpace'; import { SYNC_SPACE_PAUSE, @@ -50,31 +44,15 @@ import { DEFAULT_GLOBAL_TIMEOUT, LOAD_PHASE_PAUSE, LOAD_TAB_PAUSE, + buildSignedUserForDatabase, } from '../constants'; +import { openTools, hasSavedSpaceLayout } from './visitSpace.test'; +import { SYNC_CHANGES, SYNC_MODES } from '../../src/config/constants'; import { USER_GRAASP } from '../fixtures/users'; import { loadSpaceById } from './loadSpace.test'; -import { openTools, hasSavedSpaceLayout } from './visitSpace.test'; -import { SYNC_CHANGES } from '../../src/config/constants'; const { ADDED, REMOVED, UPDATED, MOVED } = SYNC_CHANGES; -const spaces = [ - [SPACE_WITH_ADDITION, SPACE_WITH_ADDITION_CHANGES, SPACE_WITH_ADDITION_PATH], - [SPACE_WITH_REMOVAL, SPACE_WITH_REMOVAL_CHANGES, SPACE_WITH_REMOVAL_PATH], - [SPACE_WITH_UPDATE, SPACE_WITH_UPDATE_CHANGES, SPACE_WITH_UPDATE_PATH], - [SPACE_WITH_MOVE, SPACE_WITH_MOVE_CHANGES, SPACE_WITH_MOVE_PATH], - [ - SPACE_WITH_TOOLS_UPDATE, - SPACE_WITH_TOOLS_UPDATE_CHANGES, - SPACE_WITH_TOOLS_UPDATE_PATH, - ], - [ - SPACE_WITH_MULTIPLE_CHANGES, - SPACE_WITH_MULTIPLE_CHANGES_CHANGES, - SPACE_WITH_MULTIPLE_CHANGES_PATH, - ], -]; - const constructToolsPhase = (items) => ({ name: 'Tools', items, @@ -168,7 +146,7 @@ const hasSyncVisualScreenLayout = async ( } }; -const checkItemsAfterSync = async (client, items) => { +const checkItemsAfterSync = async (client, phaseSelector, items) => { for (const { id, change: itemChange } of items) { // check item change was applied const itemSelector = `[data-id='${id}']`; @@ -179,7 +157,7 @@ const checkItemsAfterSync = async (client, items) => { await expectElementToExist(client, itemSelector); break; case REMOVED: - await expectElementToNotExist(client, itemSelector); + await expectElementToNotExist(client, phaseSelector, id); break; default: // eslint-disable-next-line no-console @@ -191,6 +169,7 @@ const checkItemsAfterSync = async (client, items) => { const checkChangesInSpace = async (client, { phases, items: tools = [] }) => { let phaseIdx = 0; for (const { name, items, change: phaseChange } of phases) { + const phase = await client.$(`#${buildPhaseMenuItemId(phaseIdx)}`); switch (phaseChange) { case REMOVED: { const li = await client.$(`#${PHASE_MENU_LIST_ID} li`); @@ -205,7 +184,6 @@ const checkChangesInSpace = async (client, { phases, items: tools = [] }) => { case ADDED: case UPDATED: default: { - const phase = await client.$(`#${buildPhaseMenuItemId(phaseIdx)}`); const menuItemText = await phase.getText(); // check phase name change @@ -216,9 +194,8 @@ const checkChangesInSpace = async (client, { phases, items: tools = [] }) => { await client.pause(LOAD_PHASE_PAUSE); if (items) { - await checkItemsAfterSync(client, items); + await checkItemsAfterSync(client, `#${PHASE_MENU_LIST_ID}`, items); } - phaseIdx += 1; } } @@ -227,7 +204,7 @@ const checkChangesInSpace = async (client, { phases, items: tools = [] }) => { // check Tools if (tools.length) { await openTools(client); - await checkItemsAfterSync(client, tools); + await checkItemsAfterSync(client, `#${TOOLS_CONTENT_PANE_ID}`, tools); } }; @@ -247,67 +224,70 @@ const cancelSync = async (client) => { await client.pause(LOAD_TAB_PAUSE); }; +const spaces = [ + [SPACE_WITH_ADDITION, SPACE_WITH_ADDITION_CHANGES], + [SPACE_WITH_REMOVAL, SPACE_WITH_REMOVAL_CHANGES], + [SPACE_WITH_UPDATE, SPACE_WITH_UPDATE_CHANGES], + [SPACE_WITH_MOVE, SPACE_WITH_MOVE_CHANGES], + [SPACE_WITH_TOOLS_UPDATE, SPACE_WITH_TOOLS_UPDATE_CHANGES], + [SPACE_WITH_MULTIPLE_CHANGES, SPACE_WITH_MULTIPLE_CHANGES_CHANGES], +]; + describe('Sync a space', function () { this.timeout(DEFAULT_GLOBAL_TIMEOUT); let app; - let globalUser; afterEach(function () { return closeApplication(app); }); describe('with advanced mode disabled (default)', function () { - beforeEach( - mochaAsync(async () => { - app = await createApplication(); - const { client } = app; - globalUser = USER_GRAASP; - await userSignIn(client, globalUser); - }) - ); - - spaces.forEach( - ([ - { - space: { id, name }, - }, - changes, - spaceFilepath, - ]) => { - it( - `Syncing from card open Visual Syncing Space Screen for "${name}"`, - mochaAsync(async () => { - const { client } = app; - - await loadSpaceById(client, spaceFilepath); - - const syncButton = await client.$( - `#${buildSpaceCardId(id)} .${SPACE_SYNC_BUTTON_CLASS}` - ); - await syncButton.click(); - await client.pause(SYNC_OPEN_SCREEN_PAUSE); - - await hasSyncVisualScreenLayout(client, changes); - - await acceptSync(client); - - await checkChangesInSpace(client, changes); - }) - ); - } - ); + spaces.forEach(([space, changes]) => { + it( + `Syncing from card open Visual Syncing Space Screen for "${space.space.name}"`, + mochaAsync(async () => { + app = await createApplication({ + database: { + ...buildSignedUserForDatabase({ syncMode: SYNC_MODES.VISUAL }), + }, + }); + const { client } = app; + const { + space: { id }, + } = space; + + await loadSpaceById(client, space.path); + + const syncButton = await client.$( + `#${buildSpaceCardId(id)} .${SPACE_SYNC_BUTTON_CLASS}` + ); + await syncButton.click(); + await client.pause(SYNC_OPEN_SCREEN_PAUSE); + + await hasSyncVisualScreenLayout(client, changes); + + await acceptSync(client); + + await checkChangesInSpace(client, changes); + }) + ); + }); it( 'Syncing from toolbar open Visual Syncing Space Screen', mochaAsync(async () => { + app = await createApplication({ + database: { + spaces: [SPACE_WITH_MULTIPLE_CHANGES], + ...buildSignedUserForDatabase({ syncMode: SYNC_MODES.VISUAL }), + }, + }); const { client } = app; - const { - space: { id }, - } = SPACE_WITH_MULTIPLE_CHANGES; const changes = SPACE_WITH_MULTIPLE_CHANGES_CHANGES; - await loadSpaceById(client, SPACE_WITH_MULTIPLE_CHANGES_PATH, id); + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, SPACE_WITH_MULTIPLE_CHANGES.space.id); const syncButton = await client.$(`.${SPACE_SYNC_BUTTON_CLASS}`); await syncButton.click(); @@ -324,13 +304,17 @@ describe('Sync a space', function () { it( 'Cancel syncing keeps original space in Saved Spaces', mochaAsync(async () => { + app = await createApplication({ + database: { + spaces: [SPACE_WITH_MULTIPLE_CHANGES], + ...buildSignedUserForDatabase({ syncMode: SYNC_MODES.VISUAL }), + }, + }); const { client } = app; const space = SPACE_WITH_MULTIPLE_CHANGES; - const { - space: { id }, - } = space; - await loadSpaceById(client, SPACE_WITH_MULTIPLE_CHANGES_PATH, id); + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, SPACE_WITH_MULTIPLE_CHANGES.space.id); const syncButton = await client.$(`.${SPACE_SYNC_BUTTON_CLASS}`); await syncButton.click(); @@ -342,7 +326,7 @@ describe('Sync a space', function () { await client.pause(LOAD_TAB_PAUSE); // space still has local content - await hasSavedSpaceLayout(client, space, { user: globalUser }); + await hasSavedSpaceLayout(client, space, { user: USER_GRAASP }); }) ); }); @@ -350,16 +334,17 @@ describe('Sync a space', function () { describe('with advanced mode enabled (default)', function () { beforeEach( mochaAsync(async () => { - app = await createApplication(); - const { client } = app; - await userSignIn(client, USER_GRAASP); - await menuGoToSettings(client); - await toggleSyncAdvancedMode(client, true); + app = await createApplication({ + database: { + spaces: [SPACE_WITH_MULTIPLE_CHANGES], + ...buildSignedUserForDatabase({ syncMode: SYNC_MODES.ADVANCED }), + }, + }); }) ); it( - 'Syncing from card open Visual Syncing Space Screen', + 'Syncing from card open Advanced Syncing Space Screen', mochaAsync(async () => { const { client } = app; @@ -367,7 +352,7 @@ describe('Sync a space', function () { space: { id }, } = SPACE_WITH_MULTIPLE_CHANGES; - await loadSpaceById(client, SPACE_WITH_MULTIPLE_CHANGES_PATH); + await menuGoToSavedSpaces(client); const syncButton = await client.$( `#${buildSpaceCardId(id)} .${SPACE_SYNC_BUTTON_CLASS}` @@ -384,7 +369,7 @@ describe('Sync a space', function () { ); it( - 'Syncing from toolbar open Visual Syncing Space Screen', + 'Syncing from toolbar open Advanced Syncing Space Screen', mochaAsync(async () => { const { client } = app; @@ -393,7 +378,8 @@ describe('Sync a space', function () { } = SPACE_WITH_MULTIPLE_CHANGES; const changes = SPACE_WITH_MULTIPLE_CHANGES_CHANGES; - await loadSpaceById(client, SPACE_WITH_MULTIPLE_CHANGES_PATH, id); + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, id); const syncButton = await client.$(`.${SPACE_SYNC_BUTTON_CLASS}`); await syncButton.click(); @@ -416,7 +402,8 @@ describe('Sync a space', function () { space: { id }, } = space; - await loadSpaceById(client, SPACE_WITH_MULTIPLE_CHANGES_PATH, id); + await menuGoToSavedSpaces(client); + await clickOnSpaceCard(client, id); const syncButton = await client.$(`.${SPACE_SYNC_BUTTON_CLASS}`); await syncButton.click(); @@ -426,7 +413,7 @@ describe('Sync a space', function () { await cancelSync(client); // space still has local content - await hasSavedSpaceLayout(client, space, { user: globalUser }); + await hasSavedSpaceLayout(client, space, { user: USER_GRAASP }); }) ); }); diff --git a/test/spaces/visitSpace.test.js b/test/spaces/visitSpace.test.js index 4646633a..4cf7f390 100644 --- a/test/spaces/visitSpace.test.js +++ b/test/spaces/visitSpace.test.js @@ -9,7 +9,6 @@ import { removeSpace, removeTags, mochaAsync, - userSignIn, menuGoToVisitSpace, expectElementToExist, removePathSeparators, @@ -383,8 +382,11 @@ export const hasSavedSpaceLayout = async ( { space: { phases, description, name } }, { resources = [], user = {} } = {} ) => { - const { mode = DEFAULT_USER_MODE } = user; - await hasSavedSpaceHomeLayout(client, { description, name }, mode); + await hasSavedSpaceHomeLayout( + client, + { description, name }, + user?.settings?.userMode || DEFAULT_USER_MODE + ); await checkPhasesLayout(client, phases, SAVED, resources); }; @@ -392,9 +394,9 @@ export const hasSavedSpaceLayout = async ( export const hasPreviewSpaceLayout = async ( client, { space: { phases, description, name }, resources = [] }, - { mode } + { settings: { userMode } } ) => { - await hasPreviewSpaceHomeLayout(client, { description, name }, mode); + await hasPreviewSpaceHomeLayout(client, { description, name }, userMode); await checkPhasesLayout(client, phases, PREVIEW, resources); }; @@ -448,7 +450,6 @@ export const checkSpaceCardLayout = async ( describe('Visit Space Scenarios', function () { this.timeout(DEFAULT_GLOBAL_TIMEOUT); let app; - let globalUser; afterEach(function () { return closeApplication(app); @@ -458,26 +459,23 @@ describe('Visit Space Scenarios', function () { beforeEach( mochaAsync(async () => { app = await createApplication(); - globalUser = USER_GRAASP; - await userSignIn(app.client, globalUser); }) ); const spaces = [SPACE_APOLLO_11, SPACE_ATOMIC_STRUCTURE]; - spaces.forEach(function (space) { + spaces.forEach((space) => { const { space: { id, name }, } = space; it( `Visit space ${name} (${id})`, - mochaAsync(async function () { - this.retries(2); + mochaAsync(async () => { const { client } = app; await visitSpaceById(client, id); - await hasPreviewSpaceLayout(client, space, globalUser); + await hasPreviewSpaceLayout(client, space, USER_GRAASP); }) ); }); @@ -486,9 +484,9 @@ describe('Visit Space Scenarios', function () { describe('Visit a space just after delete', () => { beforeEach( mochaAsync(async () => { - app = await createApplication({ showMessageDialogResponse: 1 }); - globalUser = USER_GRAASP; - await userSignIn(app.client, globalUser); + app = await createApplication({ + responses: { showMessageDialogResponse: 1 }, + }); }) ); diff --git a/test/tours.test.js b/test/tours.test.js index 7b5d0a3f..d2a25d54 100644 --- a/test/tours.test.js +++ b/test/tours.test.js @@ -18,21 +18,20 @@ describe('Tour Scenarios', function () { beforeEach( mochaAsync(async () => { app = await createApplication({ - showOpenDialogResponse: 1, - showTours: true, + database: {}, + responses: { + showOpenDialogResponse: 1, + showTours: true, + }, }); }) ); - after(function () { + afterEach(function () { return closeApplication(app); }); describe('Display tour on sign in', function () { - afterEach(function () { - return closeApplication(app); - }); - it( `displays the tour after signing in`, mochaAsync(async () => { @@ -51,7 +50,7 @@ describe('Tour Scenarios', function () { await userSignIn(client, USER_BOB, true); await menuGoToSignOut(client); await userSignIn(client, USER_BOB, false); - await expectElementToNotExist(client, TOUR_END_SELECTOR); + await expectElementToNotExist(client, '#root', TOUR_END_SELECTOR); }) ); it( diff --git a/test/utils.js b/test/utils.js index 0ab9ce93..5176b3ff 100644 --- a/test/utils.js +++ b/test/utils.js @@ -23,6 +23,8 @@ import { DRAWER_BUTTON_ID, TOUR_END_SELECTOR, DRAWER_HEADER_STUDENT_ICON_ID, + buildSpaceCardId, + SPACE_CARD_LINK_CLASS, } from '../src/config/selectors'; import { SETTINGS_LOAD_PAUSE, @@ -31,6 +33,7 @@ import { INPUT_TYPE_PAUSE, LOGIN_PAUSE, LOAD_PHASE_PAUSE, + OPEN_SAVED_SPACE_PAUSE, } from './constants'; import { SYNC_MODES, @@ -138,17 +141,25 @@ export const createRandomString = () => { /** assertion util functions */ -export const expectElementToNotExist = async (client, elementSelector) => { - const found = await (await client.$(elementSelector)).isExisting(); - expect(found).to.be.false; +export const expectElementToNotExist = async ( + client, + containerSelector, + elementSelector +) => { + const found = await (await client.$(containerSelector)).getHTML(); + expect(found).to.not.contain(elementSelector); }; -export const expectAnyElementToExist = async (client, elementSelectors) => { +export const expectAnyElementToExist = async ( + client, + containerSelector, + elementSelectors +) => { const foundElements = []; - /* eslint-disable-next-line no-restricted-syntax */ + const content = await (await client.$(containerSelector)).getHTML(); + // eslint-disable-next-line no-restricted-syntax for (const selector of elementSelectors) { - /* eslint-disable-next-line no-await-in-loop */ - const found = await (await client.$(selector)).isExisting(); + const found = content.includes(selector); foundElements.push(found); } expect(foundElements).to.include(true); @@ -235,11 +246,11 @@ export const toggleSyncAdvancedMode = async (client, value) => { /** sign in util function */ export const userSignIn = async ( client, - { name, mode = DEFAULT_USER_MODE }, + { username, settings: { userMode = DEFAULT_USER_MODE } }, closeTour = false ) => { const input = await client.$(`#${LOGIN_USERNAME_INPUT_ID}`); - await input.setValue(name); + await input.setValue(username); await client.pause(INPUT_TYPE_PAUSE); const button = await client.$(`#${LOGIN_BUTTON_ID}`); await button.click(); @@ -251,8 +262,8 @@ export const userSignIn = async ( } } // change mode if it is not default mode - if (mode !== DEFAULT_USER_MODE) { - if (mode === USER_MODES.TEACHER) { + if (userMode !== DEFAULT_USER_MODE) { + if (userMode === USER_MODES.TEACHER) { // open drawer to detect teacher icon await openDrawer(client); const drawerStudentIcon = await client.$( @@ -261,8 +272,16 @@ export const userSignIn = async ( const isStudent = await drawerStudentIcon.isExisting(); if (isStudent) { await menuGoToSettings(client); - await toggleStudentMode(client, mode); + await toggleStudentMode(client, userMode); } } } }; + +export const clickOnSpaceCard = async (client, id) => { + const spaceCardLink = await client.$( + `#${buildSpaceCardId(id)} .${SPACE_CARD_LINK_CLASS}` + ); + await spaceCardLink.click(); + await client.pause(OPEN_SAVED_SPACE_PAUSE); +};