blob: 4c18bd641424444790180e25c8cd5ca3e2a933b3 [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 Kupietz4d335a32024-09-04 16:13:48 +02005const { log } = require('console');
Marc Kupietz55fc3162022-12-04 16:25:49 +01006const assert = chai.assert;
7const should = chai.should();
Marc Kupietz7f1666a2024-07-12 18:35:31 +02008var slack = null;
Marc Kupietz55fc3162022-12-04 16:25:49 +01009
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010010const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543";
Marc Kupietz55fc3162022-12-04 16:25:49 +010011const KORAP_LOGIN = 'KORAP_LOGIN' in process.env ? process.env.KORAP_LOGIN : "user2"
Marc Kupietzc4077822022-12-03 15:32:40 +010012const KORAP_PWD = process.env.KORAP_PWD || "password2";
Marc Kupietz26982382022-12-04 19:02:57 +010013const KORAP_QUERIES = process.env.KORAP_QUERIES || 'geht, [orth=geht & cmc/pos=VVFIN]'
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010014const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL)
15
Marc Kupietz7f1666a2024-07-12 18:35:31 +020016const slack_webhook = process.env.SLACK_WEBHOOK_URL;
Marc Kupietz4d335a32024-09-04 16:13:48 +020017
Marc Kupietz7f1666a2024-07-12 18:35:31 +020018if (slack_webhook) {
19 slack = require('slack-notify')(slack_webhook);
20}
21
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010022function ifConditionIt(title, condition, test) {
Marc Kupietz55fc3162022-12-04 16:25:49 +010023 return condition ? it(title, test) : it.skip(title + " (skipped)", test)
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010024}
Marc Kupietzc4077822022-12-03 15:32:40 +010025
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010026describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
Marc Kupietzc4077822022-12-03 15:32:40 +010027
28 before(async () => {
Marc Kupietz69e02802023-11-08 14:37:22 +010029 browser = await puppeteer.launch({
30 headless: "new",
31 })
Marc Kupietzc4077822022-12-03 15:32:40 +010032 page = await browser.newPage()
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010033 await page.setViewport({
34 width: 1280,
35 height: 768,
36 deviceScaleFactor: 1,
37 });
Marc Kupietz4d335a32024-09-04 16:13:48 +020038 console.log("Browser version: " + await browser.version() + " started")
Marc Kupietzc4077822022-12-03 15:32:40 +010039 })
40
41 after(async () => {
42 await browser.close()
43 })
44
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010045 afterEach(async function () {
46 if (this.currentTest.state == "failed") {
Marc Kupietzf838f8b2022-12-04 19:02:57 +010047 await page.screenshot({path: "failed_" + this.currentTest.title.replaceAll(/[ &\/]/g, "_") + '.png'});
Marc Kupietz7f1666a2024-07-12 18:35:31 +020048 if (slack) {
49 slack.alert({
50 text: 'Test on ' + KORAP_URL + ' failed: ' + this.currentTest.title,
51 })
52 }
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010053 }
54 })
55
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010056 it('KorAP UI is up and running',
57 (async () => {
58 await await page.goto(KORAP_URL);
59 const query_field = await page.$("#q-field")
60 assert.isNotNull(query_field, "#q-field not found. Kalamar not running?");
Marc Kupietz55fc3162022-12-04 16:25:49 +010061 }))
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010062
63
64 ifConditionIt('Login into KorAP with incorrect credentials fails',
65 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010066 (async () => {
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010067 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*")
Marc Kupietzc4077822022-12-03 15:32:40 +010068 login_result.should.be.false
Marc Kupietz55fc3162022-12-04 16:25:49 +010069 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010070
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010071 ifConditionIt('Login into KorAP with correct credentials succeeds',
72 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010073 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010074 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD)
Marc Kupietzc4077822022-12-03 15:32:40 +010075 login_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010076 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010077
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010078 it('Can turn glimpse off',
Marc Kupietzc4077822022-12-03 15:32:40 +010079 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010080 await korap_rc.assure_glimpse_off(page)
Marc Kupietz55fc3162022-12-04 16:25:49 +010081 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010082
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010083 describe('Running searches that should have hits', () => {
Marc Kupietz55fc3162022-12-04 16:25:49 +010084
85 before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) })
86
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010087 KORAP_QUERIES.split(/[;,] */).forEach((query, i) => {
88 it('Search for "' + query + '" has hits',
89 (async () => {
90 await korap_rc.assure_glimpse_off(page)
91 const hits = await korap_rc.search(page, query)
92 hits.should.be.above(0)
93 })).timeout(20000)
94 })
95 })
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010096
97 ifConditionIt('Logout works',
98 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010099 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +0100100 const logout_result = await korap_rc.logout(page)
Marc Kupietzc4077822022-12-03 15:32:40 +0100101 logout_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +0100102 }))
Marc Kupietzc4077822022-12-03 15:32:40 +0100103
Marc Kupietz55fc3162022-12-04 16:25:49 +0100104})