From 7733c8dfd454d89d87980a7e3b2338bfd8258402 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sun, 30 Aug 2020 21:39:52 +0200 Subject: [PATCH] run a first unit-test with egw object on login page: npm test --- .gitignore | 1 - package.json | 9 ++++++++- test/loginSpec.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/loginSpec.js diff --git a/.gitignore b/.gitignore index 3b5e1ddaf2..50f2cd74f2 100644 --- a/.gitignore +++ b/.gitignore @@ -45,7 +45,6 @@ /sitemgr/ /stylite/ /swool/ -/test/ /tracker/ /usage/ /vendor/ diff --git a/package.json b/package.json index ef613fb970..de31ca931c 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,13 @@ "name": "EGroupware", "description": "EGroupware is a groupware suite in PHP and Javascript: https://www.egroupware.org/", "license": "GPL-2.0", - "version": "19.1.001", + "version": "20.1.20200812", "dependencies": {}, "repository": {}, "devDependencies": { "@types/jquery": "^3.3.38", "@types/jqueryui": "^1.11.37", + "chai": "^4.2.0", "grunt": "^1.0.3", "grunt-contrib-cssmin": "^2.2.1", "grunt-contrib-uglify-es": "^3.3.0", @@ -15,7 +16,13 @@ "grunt-newer": "^1.3.0", "grunt-terser": "^1.0.0", "grunt-ts": "^6.0.0-beta.22", + "jsdom": "16.4.0", + "mocha": "^8.1.3", "terser": "^4.7.0", "typescript": "^3.7.4" + }, + "scripts": { + "test": "mocha", + "debug-test": "mocha --inspect-brk" } } diff --git a/test/loginSpec.js b/test/loginSpec.js new file mode 100644 index 0000000000..2b548cfa1f --- /dev/null +++ b/test/loginSpec.js @@ -0,0 +1,39 @@ +let expect = require('chai').expect; +const { JSDOM } = require('jsdom'), + +// the file I will be loading + uri = 'https://boulder.egroupware.org/egroupware/login.php', + +// the options that I will be giving to jsdom + options = { + runScripts: 'dangerously', // 'outside-only' does NOT work for scripts in the loaded page! + resources: 'usable' + }; + +// load from an external file +describe('EGroupware login-page', function() { + it('Should load egw object', function() { + debugger + return JSDOM.fromURL(uri, options).then(function (dom) { + let window = dom.window, + document = window.document; + expect(document.querySelectorAll('form')).key(0); + expect(document.querySelectorAll('form')[0].action).to.be.a('string').and.satisfy(msg => msg.startsWith(uri)); + return new Promise((resolve, reject) => { + window.onload = resolve; + }).then(function() { + console.log('Window loaded :)'); + return new Promise((resolve, reject) => { + window.egw_LAB.wait(function() { + console.log('Async script-loading / egw_LAB done :)') + resolve(window.egw); + }); + }) + }); + }).then(function(egw) { + expect(egw.webserverUrl).equal('/egroupware', 'egw.webserverURL !== "/egroupware"'); + expect(egw.lang('Test12345 %1', 'success')).to.equal('Test12345 success'); + egw.window.close(); + }) + }) +})