blob: 79bd0b0f3f8444682d12d56fea93773156757225 [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');
3const assert = chai.assert;
4const should = chai.should();
5
Marc Kupietz0f6c54d2022-12-03 15:32:40 +01006const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543";
Marc Kupietz55fc3162022-12-04 16:25:49 +01007const KORAP_LOGIN = 'KORAP_LOGIN' in process.env ? process.env.KORAP_LOGIN : "user2"
Marc Kupietzc4077822022-12-03 15:32:40 +01008const KORAP_PWD = process.env.KORAP_PWD || "password2";
Marc Kupietz0f6c54d2022-12-03 15:32:40 +01009const KORAP_QUERIES = 'geht, [orth=geht & cmc/pos=VVFIN]'
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010010const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL)
11
12function ifConditionIt(title, condition, test) {
Marc Kupietz55fc3162022-12-04 16:25:49 +010013 return condition ? it(title, test) : it.skip(title + " (skipped)", test)
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010014}
Marc Kupietzc4077822022-12-03 15:32:40 +010015
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010016describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
Marc Kupietzc4077822022-12-03 15:32:40 +010017
18 before(async () => {
19 browser = await puppeteer.launch()
20 page = await browser.newPage()
21 })
22
23 after(async () => {
24 await browser.close()
25 })
26
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010027 it('KorAP UI is up and running',
28 (async () => {
29 await await page.goto(KORAP_URL);
30 const query_field = await page.$("#q-field")
31 assert.isNotNull(query_field, "#q-field not found. Kalamar not running?");
Marc Kupietz55fc3162022-12-04 16:25:49 +010032 }))
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010033
34
35 ifConditionIt('Login into KorAP with incorrect credentials fails',
36 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010037 (async () => {
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010038 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*")
Marc Kupietzc4077822022-12-03 15:32:40 +010039 login_result.should.be.false
Marc Kupietz55fc3162022-12-04 16:25:49 +010040 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010041
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010042 ifConditionIt('Login into KorAP with correct credentials succeeds',
43 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010044 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010045 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD)
Marc Kupietzc4077822022-12-03 15:32:40 +010046 login_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010047 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010048
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010049 it('Can turn glimpse off',
Marc Kupietzc4077822022-12-03 15:32:40 +010050 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010051 await korap_rc.assure_glimpse_off(page)
Marc Kupietz55fc3162022-12-04 16:25:49 +010052 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010053
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010054 describe('Running searches that should have hits', () => {
Marc Kupietz55fc3162022-12-04 16:25:49 +010055
56 before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) })
57
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010058 KORAP_QUERIES.split(/[;,] */).forEach((query, i) => {
59 it('Search for "' + query + '" has hits',
60 (async () => {
61 await korap_rc.assure_glimpse_off(page)
62 const hits = await korap_rc.search(page, query)
63 hits.should.be.above(0)
64 })).timeout(20000)
65 })
66 })
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010067
68 ifConditionIt('Logout works',
69 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010070 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010071 const logout_result = await korap_rc.logout(page)
Marc Kupietzc4077822022-12-03 15:32:40 +010072 logout_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010073 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010074
Marc Kupietz55fc3162022-12-04 16:25:49 +010075})