blob: 878b4987f58d0057c7937b0ec22226c02839900a [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 Kupietz0f6c54d2022-12-03 15:32:40 +010011const 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") {
36 console.log(this.currentTest);
37 await page.screenshot({path: "failed_" + this.currentTest.title.replaceAll(/[ ]/g, "_") + '.png'});
38 }
39 })
40
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010041 it('KorAP UI is up and running',
42 (async () => {
43 await await page.goto(KORAP_URL);
44 const query_field = await page.$("#q-field")
45 assert.isNotNull(query_field, "#q-field not found. Kalamar not running?");
Marc Kupietz55fc3162022-12-04 16:25:49 +010046 }))
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010047
48
49 ifConditionIt('Login into KorAP with incorrect credentials fails',
50 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010051 (async () => {
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010052 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*")
Marc Kupietzc4077822022-12-03 15:32:40 +010053 login_result.should.be.false
Marc Kupietz55fc3162022-12-04 16:25:49 +010054 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010055
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010056 ifConditionIt('Login into KorAP with correct credentials succeeds',
57 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010058 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010059 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD)
Marc Kupietzc4077822022-12-03 15:32:40 +010060 login_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010061 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010062
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010063 it('Can turn glimpse off',
Marc Kupietzc4077822022-12-03 15:32:40 +010064 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010065 await korap_rc.assure_glimpse_off(page)
Marc Kupietz55fc3162022-12-04 16:25:49 +010066 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010067
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010068 describe('Running searches that should have hits', () => {
Marc Kupietz55fc3162022-12-04 16:25:49 +010069
70 before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) })
71
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010072 KORAP_QUERIES.split(/[;,] */).forEach((query, i) => {
73 it('Search for "' + query + '" has hits',
74 (async () => {
75 await korap_rc.assure_glimpse_off(page)
76 const hits = await korap_rc.search(page, query)
77 hits.should.be.above(0)
78 })).timeout(20000)
79 })
80 })
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010081
82 ifConditionIt('Logout works',
83 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010084 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010085 const logout_result = await korap_rc.logout(page)
Marc Kupietzc4077822022-12-03 15:32:40 +010086 logout_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010087 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010088
Marc Kupietz55fc3162022-12-04 16:25:49 +010089})