|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright CERN and copyright holders of ALICE O2. This software is |
| 4 | + * distributed under the terms of the GNU General Public License v3 (GPL |
| 5 | + * Version 3), copied verbatim in the file "COPYING". |
| 6 | + * |
| 7 | + * See http://alice-o2.web.cern.ch/license for full licensing information. |
| 8 | + * |
| 9 | + * In applying this license CERN does not waive the privileges and immunities |
| 10 | + * granted to it by virtue of its status as an Intergovernmental Organization |
| 11 | + * or submit itself to any jurisdiction. |
| 12 | + */ |
| 13 | + |
| 14 | +const chai = require('chai'); |
| 15 | +const { defaultBefore, defaultAfter, goToPage } = require('../defaults.js'); |
| 16 | +const { resetDatabaseContent } = require('../../utilities/resetDatabaseContent.js'); |
| 17 | + |
| 18 | +const { expect } = chai; |
| 19 | + |
| 20 | +module.exports = () => { |
| 21 | + let page; |
| 22 | + let browser; |
| 23 | + |
| 24 | + before(async () => { |
| 25 | + [page, browser] = await defaultBefore(page, browser); |
| 26 | + await page.setViewport({ |
| 27 | + width: 700, |
| 28 | + height: 720, |
| 29 | + deviceScaleFactor: 1, |
| 30 | + }); |
| 31 | + await resetDatabaseContent(); |
| 32 | + }); |
| 33 | + |
| 34 | + after(async () => { |
| 35 | + [page, browser] = await defaultAfter(page, browser); |
| 36 | + }); |
| 37 | + |
| 38 | + it('loads the page successfully', async () => { |
| 39 | + const response = await goToPage(page, 'error'); |
| 40 | + |
| 41 | + // We expect the page to return the correct status code, making sure the server is running properly |
| 42 | + expect(response.status()).to.equal(200); |
| 43 | + |
| 44 | + // We expect the page to return the correct title, making sure there isn't another server running on this port |
| 45 | + const title = await page.title(); |
| 46 | + expect(title).to.equal('AliceO2 Bookkeeping'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('shows the error message', async () => { |
| 50 | + await goToPage(page, 'error'); |
| 51 | + |
| 52 | + const errorTitle = await page.$eval('h2', (el) => el.innerText); |
| 53 | + expect(errorTitle).to.equal('Oops! Something went wrong.'); |
| 54 | + }); |
| 55 | + |
| 56 | + it ('shows the default text', async () => { |
| 57 | + await goToPage(page, 'error'); |
| 58 | + |
| 59 | + const errorCode = await page.$eval('h3', (el) => el.innerText); |
| 60 | + expect(errorCode).to.equal('Unknown Error - Something unexpected happened.'); |
| 61 | + }); |
| 62 | + |
| 63 | + it ('shows 404 when page is not found', async () => { |
| 64 | + await goToPage(page, 'sdf'); |
| 65 | + |
| 66 | + //eslint-disable-next-line no-console |
| 67 | + console.log(await page.title()); |
| 68 | + |
| 69 | + const errorCode = await page.$eval('.h3', (el) => el.innerText); |
| 70 | + expect(errorCode).to.equal('404 - Page not found'); |
| 71 | + }); |
| 72 | +}; |
0 commit comments