blob: 9adfbc8094f08a9db465b922f1608c4f7dc561aa [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 () => {
Marc Kupietz69e02802023-11-08 14:37:22 +010021 browser = await puppeteer.launch({
22 headless: "new",
23 })
Marc Kupietzc4077822022-12-03 15:32:40 +010024 page = await browser.newPage()
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010025 await page.setViewport({
26 width: 1280,
27 height: 768,
28 deviceScaleFactor: 1,
29 });
Marc Kupietzc4077822022-12-03 15:32:40 +010030 })
31
32 after(async () => {
33 await browser.close()
34 })
35
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010036 afterEach(async function () {
37 if (this.currentTest.state == "failed") {
Marc Kupietzf838f8b2022-12-04 19:02:57 +010038 await page.screenshot({path: "failed_" + this.currentTest.title.replaceAll(/[ &\/]/g, "_") + '.png'});
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010039 }
40 })
41
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010042 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 Kupietz55fc3162022-12-04 16:25:49 +010047 }))
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010048
49
50 ifConditionIt('Login into KorAP with incorrect credentials fails',
51 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010052 (async () => {
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010053 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*")
Marc Kupietzc4077822022-12-03 15:32:40 +010054 login_result.should.be.false
Marc Kupietz55fc3162022-12-04 16:25:49 +010055 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010056
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010057 ifConditionIt('Login into KorAP with correct credentials succeeds',
58 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010059 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010060 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD)
Marc Kupietzc4077822022-12-03 15:32:40 +010061 login_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010062 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010063
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010064 it('Can turn glimpse off',
Marc Kupietzc4077822022-12-03 15:32:40 +010065 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010066 await korap_rc.assure_glimpse_off(page)
Marc Kupietz55fc3162022-12-04 16:25:49 +010067 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010068
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010069 describe('Running searches that should have hits', () => {
Marc Kupietz55fc3162022-12-04 16:25:49 +010070
71 before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) })
72
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010073 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 Kupietz5a73a4d2022-12-04 14:09:58 +010082
83 ifConditionIt('Logout works',
84 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010085 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010086 const logout_result = await korap_rc.logout(page)
Marc Kupietzc4077822022-12-03 15:32:40 +010087 logout_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010088 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010089
Marc Kupietz55fc3162022-12-04 16:25:49 +010090})