Skip to content

Commit

Permalink
small code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Fennne committed Jan 7, 2025
1 parent 3ab7098 commit 03f3863
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
12 changes: 10 additions & 2 deletions lib/public/views/Error/ErrorModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import { Observable } from '/js/src/index.js';
* Model representing handlers for errorPage.js
*/
export class ErrorModel extends Observable {
/**
* The Error object.
* @typedef {(Object)} Error
* @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
Expand All @@ -32,7 +40,7 @@ export class ErrorModel extends Observable {

/**
* Sets the error object for the model
* @param {Object} error The error object to set, must contain a code, codeDescription and message
* @param {Error} error The error object
* @returns {void}
*/
setError(error) {
Expand All @@ -45,7 +53,7 @@ export class ErrorModel extends Observable {

/**
* Returns the error object for the model
* @returns {Object} The error object
* @returns {Error} 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
Expand Down
14 changes: 6 additions & 8 deletions lib/public/views/Error/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* 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';
import { frontLink } from '../../components/common/navigation/frontLink.js';
import { h } from '/js/src/index.js';

/**
* Error page component that dynamically displays error details based on the model
Expand All @@ -29,13 +30,10 @@ export const ErrorPage = (model) => {
h('h2', 'Oops! Something went wrong.'),
h('h3', `${code} - ${codeDescription}`),
h('.f5', message),
h('button.btn.btn-primary', {
onclick: () => {
model.router.go('?page=home');
} }, [
iconHome(),
' Go to Home Page',
]),
frontLink(
h('nav-link', ['Go to Home Page']),
'home',
),
]),
]);
};
9 changes: 0 additions & 9 deletions test/public/error/error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ module.exports = () => {

before(async () => {
[page, browser] = await defaultBefore(page, browser);
await page.setViewport({
width: 700,
height: 720,
deviceScaleFactor: 1,
});
await resetDatabaseContent();
});

Expand All @@ -47,15 +42,11 @@ module.exports = () => {
});

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

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.');
});
Expand Down

0 comments on commit 03f3863

Please sign in to comment.