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