Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 1 | const puppeteer = require('puppeteer') |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 2 | const chai = require('chai'); |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 3 | const { afterEach } = require('mocha'); |
| 4 | const { doesNotMatch } = require('assert'); |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 5 | const assert = chai.assert; |
| 6 | const should = chai.should(); |
| 7 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 8 | const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543"; |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 9 | const KORAP_LOGIN = 'KORAP_LOGIN' in process.env ? process.env.KORAP_LOGIN : "user2" |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 10 | const KORAP_PWD = process.env.KORAP_PWD || "password2"; |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 11 | const KORAP_QUERIES = 'geht, [orth=geht & cmc/pos=VVFIN]' |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 12 | const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL) |
| 13 | |
| 14 | function ifConditionIt(title, condition, test) { |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 15 | return condition ? it(title, test) : it.skip(title + " (skipped)", test) |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 16 | } |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 17 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 18 | describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => { |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 19 | |
| 20 | before(async () => { |
| 21 | browser = await puppeteer.launch() |
| 22 | page = await browser.newPage() |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 23 | await page.setViewport({ |
| 24 | width: 1280, |
| 25 | height: 768, |
| 26 | deviceScaleFactor: 1, |
| 27 | }); |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 28 | }) |
| 29 | |
| 30 | after(async () => { |
| 31 | await browser.close() |
| 32 | }) |
| 33 | |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 34 | afterEach(async function () { |
| 35 | if (this.currentTest.state == "failed") { |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 36 | await page.screenshot({path: "failed_" + this.currentTest.title.replaceAll(/[ ]/g, "_") + '.png'}); |
| 37 | } |
| 38 | }) |
| 39 | |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 40 | it('KorAP UI is up and running', |
| 41 | (async () => { |
| 42 | await await page.goto(KORAP_URL); |
| 43 | const query_field = await page.$("#q-field") |
| 44 | assert.isNotNull(query_field, "#q-field not found. Kalamar not running?"); |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 45 | })) |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 46 | |
| 47 | |
| 48 | ifConditionIt('Login into KorAP with incorrect credentials fails', |
| 49 | KORAP_LOGIN != "", |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 50 | (async () => { |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 51 | const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*") |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 52 | login_result.should.be.false |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 53 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 54 | |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 55 | ifConditionIt('Login into KorAP with correct credentials succeeds', |
| 56 | KORAP_LOGIN != "", |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 57 | (async () => { |
Marc Kupietz | 5e45a2f | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 58 | const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 59 | login_result.should.be.true |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 60 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 61 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 62 | it('Can turn glimpse off', |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 63 | (async () => { |
Marc Kupietz | 5e45a2f | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 64 | await korap_rc.assure_glimpse_off(page) |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 65 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 66 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 67 | describe('Running searches that should have hits', () => { |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 68 | |
| 69 | before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) }) |
| 70 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 71 | KORAP_QUERIES.split(/[;,] */).forEach((query, i) => { |
| 72 | it('Search for "' + query + '" has hits', |
| 73 | (async () => { |
| 74 | await korap_rc.assure_glimpse_off(page) |
| 75 | const hits = await korap_rc.search(page, query) |
| 76 | hits.should.be.above(0) |
| 77 | })).timeout(20000) |
| 78 | }) |
| 79 | }) |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 80 | |
| 81 | ifConditionIt('Logout works', |
| 82 | KORAP_LOGIN != "", |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 83 | (async () => { |
Marc Kupietz | 5e45a2f | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 84 | const logout_result = await korap_rc.logout(page) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 85 | logout_result.should.be.true |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 86 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 87 | |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 88 | }) |