-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[O2B-1056] bookkeeping error page (#1820)
* Error page now shows when no page is found * Changed 404 styling * Error page can now be changed according to error * Added tests * Remove redundant tets * Page parameter will now be displayed even after navigating to error page * small code improvements * Reverted import refactor * Small code improvements --------- Co-authored-by: Fenne <[email protected]> Co-authored-by: Martin Boulais <[email protected]>
- Loading branch information
1 parent
86f5f39
commit e54eaec
Showing
7 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { | ||
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; | ||
} | ||
this.error = error; | ||
this.notify(); | ||
} | ||
|
||
/** | ||
* Returns the error object for the model | ||
* @returns {ApplicationError} The error object | ||
*/ | ||
getError() { | ||
return this.error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ', [ | ||
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', | ||
), | ||
]), | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters