blob: 42cd5dd5df624315e34a746a0e862acf832b5374 [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();
Marc Kupietz7f1666a2024-07-12 18:35:31 +02007var slack = null;
Marc Kupietz55fc3162022-12-04 16:25:49 +01008
Marc Kupietz0f6c54d2022-12-03 15:32:40 +01009const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543";
Marc Kupietz55fc3162022-12-04 16:25:49 +010010const KORAP_LOGIN = 'KORAP_LOGIN' in process.env ? process.env.KORAP_LOGIN : "user2"
Marc Kupietzc4077822022-12-03 15:32:40 +010011const KORAP_PWD = process.env.KORAP_PWD || "password2";
Marc Kupietz26982382022-12-04 19:02:57 +010012const KORAP_QUERIES = process.env.KORAP_QUERIES || 'geht, [orth=geht & cmc/pos=VVFIN]'
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010013const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL)
14
Marc Kupietz7f1666a2024-07-12 18:35:31 +020015const slack_webhook = process.env.SLACK_WEBHOOK_URL;
16if (slack_webhook) {
17 slack = require('slack-notify')(slack_webhook);
18}
19
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010020function ifConditionIt(title, condition, test) {
Marc Kupietz55fc3162022-12-04 16:25:49 +010021 return condition ? it(title, test) : it.skip(title + " (skipped)", test)
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010022}
Marc Kupietzc4077822022-12-03 15:32:40 +010023
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010024describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
Marc Kupietzc4077822022-12-03 15:32:40 +010025
26 before(async () => {
Marc Kupietz69e02802023-11-08 14:37:22 +010027 browser = await puppeteer.launch({
28 headless: "new",
29 })
Marc Kupietzc4077822022-12-03 15:32:40 +010030 page = await browser.newPage()
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010031 await page.setViewport({
32 width: 1280,
33 height: 768,
34 deviceScaleFactor: 1,
35 });
Marc Kupietzc4077822022-12-03 15:32:40 +010036 })
37
38 after(async () => {
39 await browser.close()
40 })
41
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010042 afterEach(async function () {
43 if (this.currentTest.state == "failed") {
Marc Kupietzf838f8b2022-12-04 19:02:57 +010044 await page.screenshot({path: "failed_" + this.currentTest.title.replaceAll(/[ &\/]/g, "_") + '.png'});
Marc Kupietz7f1666a2024-07-12 18:35:31 +020045 if (slack) {
46 slack.alert({
47 text: 'Test on ' + KORAP_URL + ' failed: ' + this.currentTest.title,
48 })
49 }
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010050 }
51 })
52
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010053 it('KorAP UI is up and running',
54 (async () => {
55 await await page.goto(KORAP_URL);
56 const query_field = await page.$("#q-field")
57 assert.isNotNull(query_field, "#q-field not found. Kalamar not running?");
Marc Kupietz55fc3162022-12-04 16:25:49 +010058 }))
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010059
60
61 ifConditionIt('Login into KorAP with incorrect credentials fails',
62 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010063 (async () => {
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010064 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*")
Marc Kupietzc4077822022-12-03 15:32:40 +010065 login_result.should.be.false
Marc Kupietz55fc3162022-12-04 16:25:49 +010066 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010067
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010068 ifConditionIt('Login into KorAP with correct credentials succeeds',
69 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010070 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010071 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD)
Marc Kupietzc4077822022-12-03 15:32:40 +010072 login_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010073 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010074
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010075 it('Can turn glimpse off',
Marc Kupietzc4077822022-12-03 15:32:40 +010076 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010077 await korap_rc.assure_glimpse_off(page)
Marc Kupietz55fc3162022-12-04 16:25:49 +010078 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010079
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010080 describe('Running searches that should have hits', () => {
Marc Kupietz55fc3162022-12-04 16:25:49 +010081
82 before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) })
83
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010084 KORAP_QUERIES.split(/[;,] */).forEach((query, i) => {
85 it('Search for "' + query + '" has hits',
86 (async () => {
87 await korap_rc.assure_glimpse_off(page)
88 const hits = await korap_rc.search(page, query)
89 hits.should.be.above(0)
90 })).timeout(20000)
91 })
92 })
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010093
94 ifConditionIt('Logout works',
95 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010096 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010097 const logout_result = await korap_rc.logout(page)
Marc Kupietzc4077822022-12-03 15:32:40 +010098 logout_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010099 }))
Marc Kupietzc4077822022-12-03 15:32:40 +0100100
Marc Kupietz55fc3162022-12-04 16:25:49 +0100101})