Skip to content

Commit 8555168

Browse files
authored
Merge pull request #360 from graasp/359/speedTests
359/speed tests
2 parents 04a01de + 16438b9 commit 8555168

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1698
-1407
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist
33
coverage
44
src/registerServiceWorker.js
55
cypress/integration/examples
6+
test/tmp

.eslintrc

+19-23
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
{
2-
"extends": [
3-
"airbnb",
4-
"prettier"
5-
],
6-
"plugins": [
7-
"import",
8-
"jsx-a11y",
9-
"react",
10-
"mocha"
11-
],
2+
"extends": ["airbnb", "prettier"],
3+
"plugins": ["import", "jsx-a11y", "react", "mocha"],
124
"env": {
135
"browser": true,
146
"node": true,
@@ -24,10 +16,7 @@
2416
"no-underscore-dangle": [
2517
"error",
2618
{
27-
"allow": [
28-
"_id",
29-
"__REDUX_DEVTOOLS_EXTENSION__"
30-
]
19+
"allow": ["_id", "__REDUX_DEVTOOLS_EXTENSION__"]
3120
}
3221
],
3322
"jsx-a11y/anchor-is-valid": [
@@ -45,13 +34,20 @@
4534
}
4635
],
4736
"import/no-named-as-default": 0,
48-
"react/static-property-placement": [
49-
"error",
50-
"static public field"
51-
],
52-
"react/state-in-constructor": [
53-
"error",
54-
"never"
55-
]
56-
}
37+
"react/static-property-placement": ["error", "static public field"],
38+
"react/state-in-constructor": ["error", "never"],
39+
"no-console": [2, { "allow": ["error"] }]
40+
},
41+
42+
"overrides": [
43+
{
44+
"files": ["test/**/*.js"],
45+
"rules": {
46+
"no-unused-expressions": "off",
47+
"func-names": "off",
48+
"no-restricted-syntax": "off",
49+
"no-await-in-loop": "off"
50+
}
51+
}
52+
]
5753
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"report": "cat ./coverage/lcov.info | env-cmd -f ./.env.test codacy-coverage",
6868
"report:ci": "cat ./coverage/lcov.info | codacy-coverage",
6969
"version": "git add CHANGELOG.md && standard-version -a",
70-
"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\"\""
70+
"mocha:run": "mocha --require @babel/register --retries 3 'test/**/*.test.js'",
71+
"mocha": "mkdirp test/tmp && concurrently \"env-cmd -f ./.env.test react-scripts start\" \"wait-on http://localhost:3000 && yarn mocha:run\""
7172
},
7273
"dependencies": {
7374
"@material-ui/core": "4.11.0",

public/app/config/channels.js

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

public/app/config/config.js

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

99+
const DEFAULT_TOURS_ENABLED = true;
100+
99101
const buildFilePath = ({ userId, spaceId, name }) => {
100102
// add generated id to handle duplicate files
101103
const generatedId = ObjectId().str;
102104
return `${VAR_FOLDER}/${spaceId}/files/${userId}/${generatedId}_${name}`;
103105
};
104106

107+
const SHOW_TOURS = 'SHOW_TOURS';
108+
105109
module.exports = {
106110
DEFAULT_LOGGING_LEVEL,
107111
DEFAULT_PROTOCOL,
@@ -131,4 +135,6 @@ module.exports = {
131135
buildFilePath,
132136
PREPACKAGED_APPS_FOLDER_NAME,
133137
APPS_FOLDER,
138+
DEFAULT_TOURS_ENABLED,
139+
SHOW_TOURS,
134140
};

public/app/download.js

-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ const downloadMultipleFilesApplication = async ({
127127
}
128128
}
129129
} catch (e) {
130-
// eslint-disable-next-line no-console
131130
console.error(e);
132131
return false;
133132
}

public/app/listeners/deleteAppInstanceResource.js

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const deleteAppInstanceResource = (mainWindow, db) => (event, payload = {}) => {
1111

1212
mainWindow.webContents.send(DELETE_APP_INSTANCE_RESOURCE_CHANNEL, payload);
1313
} catch (e) {
14-
// eslint-disable-next-line no-console
1514
console.error(e);
1615
mainWindow.webContents.send(DELETE_APP_INSTANCE_RESOURCE_CHANNEL, null);
1716
}

public/app/listeners/deleteFile.js

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const deleteFile = (mainWindow) => (event, payload = {}) => {
1919

2020
mainWindow.webContents.send(DELETE_FILE_CHANNEL, payload);
2121
} catch (e) {
22-
// eslint-disable-next-line no-console
2322
console.error(e);
2423
mainWindow.webContents.send(DELETE_FILE_CHANNEL, ERROR_GENERAL);
2524
}

public/app/listeners/getAppInstance.js

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const getAppInstance = (mainWindow, db) => (event, payload = {}) => {
3434

3535
mainWindow.webContents.send(GET_APP_INSTANCE_CHANNEL, appInstance);
3636
} catch (e) {
37-
// eslint-disable-next-line no-console
3837
console.error(e);
3938
mainWindow.webContents.send(GET_APP_INSTANCE_CHANNEL, null);
4039
}

public/app/listeners/getAppInstanceResources.js

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const getAppInstanceResources = (mainWindow, db) => (event, data = {}) => {
3232
}
3333
);
3434
} catch (e) {
35-
// eslint-disable-next-line no-console
3635
console.error(e);
3736
// error is sent back to channel specific for this app instance
3837
mainWindow.webContents.send(
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { DEFAULT_TOURS_ENABLED, SHOW_TOURS } = require('../config/config');
2+
const { GET_TOURS_ENABLED_CHANNEL } = require('../config/channels');
3+
const logger = require('../logger');
4+
const { ERROR_GENERAL } = require('../config/errors');
5+
6+
const getToursEnabled = (mainWindow) => async () => {
7+
try {
8+
const enabled = process.env[SHOW_TOURS]
9+
? process.env[SHOW_TOURS] === 'true'
10+
: DEFAULT_TOURS_ENABLED;
11+
mainWindow.webContents.send(GET_TOURS_ENABLED_CHANNEL, enabled);
12+
} catch (e) {
13+
logger.error(e);
14+
mainWindow.webContents.send(GET_TOURS_ENABLED_CHANNEL, ERROR_GENERAL);
15+
}
16+
};
17+
18+
module.exports = getToursEnabled;

public/app/listeners/index.js

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

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

public/app/listeners/loadSpace.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,23 @@ const loadSpace = (mainWindow, db) => async (
172172
return mainWindow.webContents.send(LOADED_SPACE_CHANNEL, ERROR_GENERAL);
173173
}
174174

175-
const savedResources = db.get(APP_INSTANCE_RESOURCES_COLLECTION);
175+
// remove already existing resources
176+
db.get(APP_INSTANCE_RESOURCES_COLLECTION)
177+
.remove(({ id }) =>
178+
appInstanceResources.find(({ id: thisId }) => thisId === id)
179+
)
180+
.write();
176181

177182
const newResources = appInstanceResources
178-
// keep only non-duplicate resources
179-
.filter(({ id }) => !savedResources.find({ id }).value())
180183
// change user id by current user id
181184
.map((resource) => ({
182185
...resource,
183186
user: userId,
184187
}));
185188

186-
savedResources.push(...newResources).write();
189+
db.get(APP_INSTANCE_RESOURCES_COLLECTION)
190+
.push(...newResources)
191+
.write();
187192
}
188193

189194
// write actions to database if selected

public/app/listeners/patchAppInstanceResource.js

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const patchAppInstanceResource = (mainWindow, db) => (event, payload = {}) => {
1919
db.write();
2020
mainWindow.webContents.send(PATCH_APP_INSTANCE_RESOURCE_CHANNEL, resource);
2121
} catch (e) {
22-
// eslint-disable-next-line no-console
2322
console.error(e);
2423
mainWindow.webContents.send(PATCH_APP_INSTANCE_RESOURCE_CHANNEL, null);
2524
}

public/app/listeners/postAppInstanceResource.js

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const postAppInstanceResource = (mainWindow, db) => (event, payload = {}) => {
4040
resourceToWrite
4141
);
4242
} catch (e) {
43-
// eslint-disable-next-line no-console
4443
console.error(e);
4544
mainWindow.webContents.send(POST_APP_INSTANCE_RESOURCE_CHANNEL, null);
4645
}

public/electron.js

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

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

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

src/actions/appInstance.js

-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const getAppInstance = async (
5151
);
5252
}
5353
} catch (err) {
54-
// eslint-disable-next-line no-console
5554
console.error(err);
5655
}
5756
};
@@ -79,7 +78,6 @@ const patchAppInstance = async (
7978
}
8079
);
8180
} catch (err) {
82-
// eslint-disable-next-line no-console
8381
console.error(err);
8482
}
8583
};

src/actions/appInstanceResource.js

-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const getAppInstanceResources = async (
3939
}
4040
);
4141
} catch (err) {
42-
// eslint-disable-next-line no-console
4342
console.error(err);
4443
}
4544
};
@@ -71,7 +70,6 @@ const postAppInstanceResource = async (
7170
}
7271
);
7372
} catch (err) {
74-
// eslint-disable-next-line no-console
7573
console.error(err);
7674
}
7775
};
@@ -100,7 +98,6 @@ const patchAppInstanceResource = async (
10098
}
10199
);
102100
} catch (err) {
103-
// eslint-disable-next-line no-console
104101
console.error(err);
105102
}
106103
};
@@ -130,7 +127,6 @@ const deleteAppInstanceResource = async (
130127
}
131128
);
132129
} catch (err) {
133-
// eslint-disable-next-line no-console
134130
console.error(err);
135131
}
136132
};

src/actions/authentication.js

-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ const signOut = (user) => (dispatch) => {
7878
dispatch(flagSigningOut(false));
7979
});
8080
} catch (e) {
81-
// eslint-disable-next-line no-console
8281
console.error(e);
8382
toastr.error(i18n.t(ERROR_MESSAGE_HEADER), i18n.t(ERROR_SIGNING_OUT));
8483
dispatch(flagSigningOut(false));
@@ -107,7 +106,6 @@ const isAuthenticated = async () => (dispatch) => {
107106
}
108107
);
109108
} catch (e) {
110-
// eslint-disable-next-line no-console
111109
console.error(e);
112110
toastr.error(
113111
i18n.t(ERROR_MESSAGE_HEADER),

src/actions/developer.js

-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const getDatabase = async () => (dispatch) => {
3737
dispatch(flagGettingDatabase(false));
3838
});
3939
} catch (err) {
40-
// eslint-disable-next-line no-console
4140
console.error(err);
4241
toastr.error(i18n.t(ERROR_MESSAGE_HEADER), i18n.t(ERROR_GETTING_DATABASE));
4342
}
@@ -62,7 +61,6 @@ const setDatabase = async (database) => (dispatch) => {
6261
dispatch(flagSettingDatabase(false));
6362
});
6463
} catch (err) {
65-
// eslint-disable-next-line no-console
6664
console.error(err);
6765
toastr.error(i18n.t(ERROR_MESSAGE_HEADER), i18n.t(ERROR_SETTING_DATABASE));
6866
}

src/actions/file.js

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export const deleteFile = async (payload = {}, callback) => {
7272
}
7373
});
7474
} catch (err) {
75-
// eslint-disable-next-line no-console
7675
console.error(err);
7776
}
7877
};

src/actions/tour.js

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

1418
const goToNextStep = (payload) => (dispatch) =>
@@ -71,6 +75,27 @@ const completeTour = async (tourName) => (dispatch) => {
7175
}
7276
};
7377

78+
const getToursEnabled = async (tourName) => (dispatch) => {
79+
try {
80+
window.ipcRenderer.send(GET_TOURS_ENABLED_CHANNEL, { tourName });
81+
window.ipcRenderer.once(
82+
GET_TOURS_ENABLED_CHANNEL,
83+
async (event, payload) => {
84+
if (payload === ERROR_GENERAL) {
85+
console.error(payload);
86+
} else {
87+
dispatch({
88+
type: GET_TOURS_ENABLED_SUCCESS,
89+
payload,
90+
});
91+
}
92+
}
93+
);
94+
} catch (e) {
95+
console.error(e);
96+
}
97+
};
98+
7499
export {
75100
stopTour,
76101
goToNextStep,
@@ -81,4 +106,5 @@ export {
81106
resetTour,
82107
completeTour,
83108
initializeTour,
109+
getToursEnabled,
84110
};

0 commit comments

Comments
 (0)