blob: bb5e293a65079eff9e726ae64ff59d39ed6389c6 [file] [log] [blame]
Marc Kupietzc4077822022-12-03 15:32:40 +01001const { beforeEach } = require('mocha');
2const puppeteer = require('puppeteer')
3var chai = require('chai');
Marc Kupietz5a73a4d2022-12-04 14:09:58 +01004const { expect, assert } = require('chai');
Marc Kupietzc4077822022-12-03 15:32:40 +01005var should = chai.should();
Marc Kupietz0f6c54d2022-12-03 15:32:40 +01006const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543";
Marc Kupietz5a73a4d2022-12-04 14:09:58 +01007const KORAP_LOGIN = (process.env.KORAP_LOGIN || process.env.KORAP_LOGIN == "" ? process.env.KORAP_LOGIN : "user2")
Marc Kupietzc4077822022-12-03 15:32:40 +01008const KORAP_PWD = process.env.KORAP_PWD || "password2";
Marc Kupietz0f6c54d2022-12-03 15:32:40 +01009const KORAP_QUERIES = 'geht, [orth=geht & cmc/pos=VVFIN]'
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010010const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL)
11
12function ifConditionIt(title, condition, test) {
13 return condition ? it(title, test) : it.skip(title, test)
14}
Marc Kupietzc4077822022-12-03 15:32:40 +010015
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010016describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
Marc Kupietzc4077822022-12-03 15:32:40 +010017 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 Kupietz5a73a4d2022-12-04 14:09:58 +010028 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 Kupietzc4077822022-12-03 15:32:40 +010038 (async () => {
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010039 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*")
Marc Kupietzc4077822022-12-03 15:32:40 +010040 login_result.should.be.false
41 })).timeout(10000)
42
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010043 ifConditionIt('Login into KorAP with correct credentials succeeds',
44 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010045 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010046 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD)
Marc Kupietzc4077822022-12-03 15:32:40 +010047 login_result.should.be.true
48 })).timeout(10000)
49
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010050 it('Can turn glimpse off',
Marc Kupietzc4077822022-12-03 15:32:40 +010051 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010052 await korap_rc.assure_glimpse_off(page)
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010053 })).timeout(10000)
Marc Kupietzc4077822022-12-03 15:32:40 +010054
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010055 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 Kupietz5a73a4d2022-12-04 14:09:58 +010065
66 ifConditionIt('Logout works',
67 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010068 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010069 const logout_result = await korap_rc.logout(page)
Marc Kupietzc4077822022-12-03 15:32:40 +010070 logout_result.should.be.true
71 })).timeout(10000)
72
73})