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

Merged
merged 11 commits into from
Jan 16, 2025
24 changes: 22 additions & 2 deletions lib/public/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import { BkpRoles } from './domain/enums/BkpRoles.js';
import { getRoleForDetector } from './utilities/getRoleForDetector.js';
import { detectorsProvider } from './services/detectors/detectorsProvider.js';
import { ErrorModel } from './views/Error/ErrorModel.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
61 changes: 61 additions & 0 deletions lib/public/views/Error/ErrorModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @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 ApplicationError object.
* @typedef {(object)} ApplicationError
* @property {string} code - The error code
* @property {string} codeDescription - The description of the error code
* @property {string} message - The error message
*/

/**
* The constructor for the Error model object
* @returns {object} Constructs the Error model
*/
constructor() {
super();
this.error = {

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

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Error/ErrorModel.js#L32-L34

Added lines #L32 - L34 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 {ApplicationError} error The error object
* @returns {void}
*/
setError(error) {
if (!error.code || !error.codeDescription || !error.message) {
return;

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

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Error/ErrorModel.js#L46-L48

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

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
}

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

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

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Error/ErrorModel.js#L58-L59

Added lines #L58 - L59 were not covered by tests
}
}
42 changes: 42 additions & 0 deletions lib/public/views/Error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @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 { frontLink } from '../../components/common/navigation/frontLink.js';
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 23 in lib/public/views/Error/index.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Error/index.js#L21-L23

Added lines #L21 - L23 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),
frontLink(
h('div.flex-row.justify-center.items-center.g1', [
iconHome(),
'Go to Home Page',
]),
'home',
),
]),
]);
};
53 changes: 53 additions & 0 deletions test/public/error/error.test.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.
*/

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 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 () => {
const errorTitle = await page.$eval('h2', (el) => el.innerText);
expect(errorTitle).to.equal('Oops! Something went wrong.');
});

it ('shows the default text', async () => {
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