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