blob: 2d82fc95d3d29fd3376b952a0af3f69a17e8d7d0 [file] [log] [blame]
Marc Kupietzc4077822022-12-03 15:32:40 +01001const puppeteer = require('puppeteer')
Marc Kupietz55fc3162022-12-04 16:25:49 +01002const chai = require('chai');
Marc Kupietz4c5a7a52022-12-04 16:56:30 +01003const { afterEach } = require('mocha');
4const { doesNotMatch } = require('assert');
Marc Kupietz55fc3162022-12-04 16:25:49 +01005const assert = chai.assert;
6const should = chai.should();
7
Marc Kupietz0f6c54d2022-12-03 15:32:40 +01008const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543";
Marc Kupietz55fc3162022-12-04 16:25:49 +01009const KORAP_LOGIN = 'KORAP_LOGIN' in process.env ? process.env.KORAP_LOGIN : "user2"
Marc Kupietzc4077822022-12-03 15:32:40 +010010const KORAP_PWD = process.env.KORAP_PWD || "password2";
Marc Kupietz26982382022-12-04 19:02:57 +010011const KORAP_QUERIES = process.env.KORAP_QUERIES || 'geht, [orth=geht & cmc/pos=VVFIN]'
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010012const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL)
13
14function ifConditionIt(title, condition, test) {
Marc Kupietz55fc3162022-12-04 16:25:49 +010015 return condition ? it(title, test) : it.skip(title + " (skipped)", test)
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010016}
Marc Kupietzc4077822022-12-03 15:32:40 +010017
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010018describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
Marc Kupietzc4077822022-12-03 15:32:40 +010019
20 before(async () => {
21 browser = await puppeteer.launch()
22 page = await browser.newPage()
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010023 await page.setViewport({
24 width: 1280,
25 height: 768,
26 deviceScaleFactor: 1,
27 });
Marc Kupietzc4077822022-12-03 15:32:40 +010028 })
29
30 after(async () => {
31 await browser.close()
32 })
33
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010034 afterEach(async function () {
35 if (this.currentTest.state == "failed") {
Marc Kupietzf838f8b2022-12-04 19:02:57 +010036 await page.screenshot({path: "failed_" + this.currentTest.title.replaceAll(/[ &\/]/g, "_") + '.png'});
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010037 }
38 })
39
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010040 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 Kupietz55fc3162022-12-04 16:25:49 +010045 }))
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010046
47
48 ifConditionIt('Login into KorAP with incorrect credentials fails',
49 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010050 (async () => {
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010051 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*")
Marc Kupietzc4077822022-12-03 15:32:40 +010052 login_result.should.be.false
Marc Kupietz55fc3162022-12-04 16:25:49 +010053 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010054
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010055 ifConditionIt('Login into KorAP with correct credentials succeeds',
56 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010057 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010058 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD)
Marc Kupietzc4077822022-12-03 15:32:40 +010059 login_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010060 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010061
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010062 it('Can turn glimpse off',
Marc Kupietzc4077822022-12-03 15:32:40 +010063 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010064 await korap_rc.assure_glimpse_off(page)
Marc Kupietz55fc3162022-12-04 16:25:49 +010065 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010066
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010067 describe('Running searches that should have hits', () => {
Marc Kupietz55fc3162022-12-04 16:25:49 +010068
69 before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) })
70
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010071 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 Kupietz5a73a4d2022-12-04 14:09:58 +010080
81 ifConditionIt('Logout works',
82 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010083 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010084 const logout_result = await korap_rc.logout(page)
Marc Kupietzc4077822022-12-03 15:32:40 +010085 logout_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010086 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010087
Marc Kupietz55fc3162022-12-04 16:25:49 +010088})