Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[O2B-1056] bookkeeping error page #1820

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions lib/public/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,32 @@

import { Loader, Observable, QueryRouter, sessionService } from '/js/src/index.js';

import { LogsModel } from './views/Logs/LogsModel.js';
import Tags from './views/Tags/Tags.js';
import { RunsModel } from './views/Runs/RunsModel.js';
import Flps from './views/Flps/Flps.js';
import { EnvironmentModel } from './views/Environments/EnvironmentModel.js';
import LhcFills from './views/LhcFills/LhcFills.js';
import RunTypeModel from './views/RunTypes/RunTypeModel.js';
import { registerFrontLinkListener } from './components/common/navigation/frontLinkListener.js';
import { ModalModel } from './components/modal/ModalModel.js';
import { BkpRoles } from './domain/enums/BkpRoles.js';
import { UserRoleSelectionModel } from './models/UserRoleSelectionModel.js';
import { detectorsProvider } from './services/detectors/detectorsProvider.js';
import { ObservableData } from './utilities/ObservableData.js';
import { debounce, INPUT_DEBOUNCE_TIME } from './utilities/debounce.js';
import { getRoleForDetector } from './utilities/getRoleForDetector.js';
import { userPreferencesStore } from './utilities/userPreferencesStore.js';
import { registerFrontLinkListener } from './components/common/navigation/frontLinkListener.js';
import { EosReportModel } from './views/EosReport/EosReportModel.js';
import { AboutModel } from './views/About/About.js';
import { StatisticsPageModel } from './views/Statistics/StatisticsPageModel.js';
import { LhcPeriodsModel } from './views/lhcPeriods/LhcPeriodsModel.js';
import { HomePageModel } from './views/Home/Overview/HomePageModel.js';
import { DataPassesModel } from './views/DataPasses/DataPassesModel.js';
import { SimulationPassesModel } from './views/SimulationPasses/SimulationPassesModel.js';
import { EnvironmentModel } from './views/Environments/EnvironmentModel.js';
import { EosReportModel } from './views/EosReport/EosReportModel.js';
import { ErrorModel } from './views/Error/ErrorModel.js';
import Flps from './views/Flps/Flps.js';
import { HomePageModel } from './views/Home/Overview/HomePageModel.js';
import LhcFills from './views/LhcFills/LhcFills.js';
import { LogsModel } from './views/Logs/LogsModel.js';
import { QcFlagTypesModel } from './views/QcFlagTypes/QcFlagTypesModel.js';
import { QcFlagsModel } from './views/QcFlags/QcFlagsModel.js';
import { UserRoleSelectionModel } from './models/UserRoleSelectionModel.js';
import { ObservableData } from './utilities/ObservableData.js';
import { BkpRoles } from './domain/enums/BkpRoles.js';
import { getRoleForDetector } from './utilities/getRoleForDetector.js';
import { detectorsProvider } from './services/detectors/detectorsProvider.js';
import RunTypeModel from './views/RunTypes/RunTypeModel.js';
import { RunsModel } from './views/Runs/RunsModel.js';
import { SimulationPassesModel } from './views/SimulationPasses/SimulationPassesModel.js';
import { StatisticsPageModel } from './views/Statistics/StatisticsPageModel.js';
import Tags from './views/Tags/Tags.js';
Comment on lines +16 to +40
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should try to avoid as much as possible this kind of huge changes, for example reordering imports. It adds a lot of noise for review, and someone might do the other way around in a future commit, and this is an endless cycle of changes.

import { LhcPeriodsModel } from './views/lhcPeriods/LhcPeriodsModel.js';

/**
* Root of model tree
Expand Down Expand Up @@ -168,6 +169,12 @@
this.aboutModel = new AboutModel();
this.aboutModel.bubbleTo(this);

/**
* @type {ErrorModel}
*/
this.errorModel = new ErrorModel();
this.errorModel.bubbleTo(this);

Check warning on line 176 in lib/public/Model.js

View check run for this annotation

Codecov / codecov/patch

lib/public/Model.js#L175-L176

Added lines #L175 - L176 were not covered by tests

// Setup router
this.router = new QueryRouter();
this.router.observe(this.handleLocationChange.bind(this));
Expand Down Expand Up @@ -309,9 +316,22 @@
case 'eos-report-create':
this.eosReportModel.loadCreation(this.router.params.shiftType);
break;
default:
this.router.go('?page=home');
case 'error':

Check warning on line 319 in lib/public/Model.js

View check run for this annotation

Codecov / codecov/patch

lib/public/Model.js#L319

Added line #L319 was not covered by tests
break;
default:
if (this.router.params.page) {
this.errorModel.setError({

Check warning on line 323 in lib/public/Model.js

View check run for this annotation

Codecov / codecov/patch

lib/public/Model.js#L321-L323

Added lines #L321 - L323 were not covered by tests
code: '404',
codeDescription: 'Page not found',
message: 'The page you are looking for might have been removed, had its name changed or is temorarily unavailable.',
});
this.router.params.page = 'error';
this.router.notify();
break;
} else {
this.router.go('?page=home');
break;

Check warning on line 333 in lib/public/Model.js

View check run for this annotation

Codecov / codecov/patch

lib/public/Model.js#L328-L333

Added lines #L328 - L333 were not covered by tests
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/public/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { QcFlagDetailsForDataPassPage } from './views/QcFlags/details/forDataPas
import { QcFlagDetailsForSimulationPassPage } from './views/QcFlags/details/forSimulationPass/QcFlagDetailsForSimulationPassPage.js';
import { GaqFlagsOverviewPage } from './views/QcFlags/GaqFlags/GaqFlagsOverviewPage.js';
import { SynchronousQcFlagsOverviewPage } from './views/QcFlags/Synchronous/SynchronousQcFlagsOverviewPage.js';
import { ErrorPage } from './views/Error/index.js';

/**
* Main view layout
Expand Down Expand Up @@ -114,6 +115,8 @@ export default (model) => {
'tag-create': TagCreate,

'eos-report-create': EosReportCreationPage,

error: ErrorPage,
};

return [
Expand Down
53 changes: 53 additions & 0 deletions lib/public/views/Error/ErrorModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

import { Observable } from '/js/src/index.js';

/**
* Model representing handlers for errorPage.js
*/
export class ErrorModel extends Observable {
/**
* The constructor for the Error model object
* @returns {Object} Constructs the Error model
*/
constructor() {
super();
this.error = {

Check warning on line 26 in lib/public/views/Error/ErrorModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Error/ErrorModel.js#L24-L26

Added lines #L24 - L26 were not covered by tests
code: 'Unknown Error',
codeDescription: 'Something unexpected happened.',
message: 'Please try again later.',
};
}

/**
* Sets the error object for the model
* @param {Object} error The error object to set, must contain a code, codeDescription and message
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a precise object description instead of simply suggesting it in comment. Because you use it in different places, I suppose you should create a typedef.

* @returns {void}
*/
setError(error) {
if (!error.code || !error.codeDescription || !error.message) {
return;

Check warning on line 40 in lib/public/views/Error/ErrorModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Error/ErrorModel.js#L38-L40

Added lines #L38 - L40 were not covered by tests
}
this.error = error;
this.notify();

Check warning on line 43 in lib/public/views/Error/ErrorModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Error/ErrorModel.js#L42-L43

Added lines #L42 - L43 were not covered by tests
}

/**
* Returns the error object for the model
* @returns {Object} The error object
*/
getError() {
return this.error;

Check warning on line 51 in lib/public/views/Error/ErrorModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Error/ErrorModel.js#L50-L51

Added lines #L50 - L51 were not covered by tests
}
}
41 changes: 41 additions & 0 deletions lib/public/views/Error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
import { h, iconHome } from '/js/src/index.js';

/**
* Error page component that dynamically displays error details based on the model
* @param {Model} model - Represents the current application state
* @returns {Component} Error page component
*/
export const ErrorPage = (model) => {
const { code, codeDescription, message } = model.errorModel.error;
return h('div.flex-column.justify-center ', [

Check warning on line 22 in lib/public/views/Error/index.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Error/index.js#L20-L22

Added lines #L20 - L22 were not covered by tests
h('.flex-column.items-center.g3.mv4', [
h('img', {
src: 'assets/alice.png',
alt: 'Alice logo',
style: 'width: 200px',
}),
h('h2', 'Oops! Something went wrong.'),
h('h3', `${code} - ${codeDescription}`),
h('.f5', message),
h('button.btn.btn-primary', {
onclick: () => {
model.router.go('?page=home');

Check warning on line 34 in lib/public/views/Error/index.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Error/index.js#L33-L34

Added lines #L33 - L34 were not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, we should avoid as much as possible dependencies inside components. The ideal would be for it to depend only on a very specific submodel, in this case only on model.errorModel. Using router is an external dependency that should be avoided outside of models.
Instead, you should try to have a look at "frontLink" component, that hides this dependency for you (and puts it in one single place). You might style it as a button if you like, but in my personal opinion, a link should look like a link (I am fine with the button if you prefer it).

} }, [
iconHome(),
' Go to Home Page',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use flex container and flex-gap instead of putting a space in your text

]),
]),
]);
};
62 changes: 62 additions & 0 deletions test/public/error/error.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

const chai = require('chai');
const { defaultBefore, defaultAfter, goToPage } = require('../defaults.js');
const { resetDatabaseContent } = require('../../utilities/resetDatabaseContent.js');

const { expect } = chai;

module.exports = () => {
let page;
let browser;

before(async () => {
[page, browser] = await defaultBefore(page, browser);
await page.setViewport({
width: 700,
height: 720,
deviceScaleFactor: 1,
});
Comment on lines +26 to +30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to set this?

await resetDatabaseContent();
});

after(async () => {
[page, browser] = await defaultAfter(page, browser);
});

it('loads the page successfully', async () => {
const response = await goToPage(page, 'error');

// We expect the page to return the correct status code, making sure the server is running properly
expect(response.status()).to.equal(200);

// We expect the page to return the correct title, making sure there isn't another server running on this port
const title = await page.title();
expect(title).to.equal('AliceO2 Bookkeeping');
});

it('shows the error message', async () => {
await goToPage(page, 'error');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can consider that one suite of frontend test is a continuous test, basically you can make them dependent one of the other. In this test for example you can suppose that you are already in the right page, and simply do your tests. Same for the next ones, and this way we avoid navigation.


const errorTitle = await page.$eval('h2', (el) => el.innerText);
expect(errorTitle).to.equal('Oops! Something went wrong.');
});

it ('shows the default text', async () => {
await goToPage(page, 'error');

const errorCode = await page.$eval('h3', (el) => el.innerText);
expect(errorCode).to.equal('Unknown Error - Something unexpected happened.');
});
};
17 changes: 17 additions & 0 deletions test/public/error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
const ErrorSuite = require('./error.test');

module.exports = () => {
describe('Error Page', ErrorSuite);
};
2 changes: 2 additions & 0 deletions test/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const FlpsSuite = require('./flps');
const HomeSuite = require('./home');
const AboutSuite = require('./about');
const EnvsSuite = require('./envs');
const ErrorSuite = require('./error');
const EosReportSuite = require('./eosReport');
const LhcPeriodsSuite = require('./lhcPeriods');
const DataPassesSuite = require('./dataPasses');
Expand All @@ -41,4 +42,5 @@ module.exports = () => {
describe('SimulationPasses', SimulationPassesSuite);
describe('QcFlagTypes', QcFlagTypesSuite);
describe('QcFlags', QcFlagsSuite);
describe('Error', ErrorSuite);
};
Loading