You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@senssoft.apache.org by rf...@apache.org on 2016/09/20 21:03:59 UTC
[8/8] incubator-senssoft-useralejs git commit: Added test coverage
for configure_spec and packageLogs
Added test coverage for configure_spec and packageLogs
Project: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/commit/416450cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/416450cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/416450cd
Branch: refs/heads/master
Commit: 416450cdbc6324ef90eec3f65d6e8eb22c90832f
Parents: 56f1409
Author: Rob Foley <ro...@gmail.com>
Authored: Tue Sep 20 16:59:28 2016 -0400
Committer: Rob Foley <ro...@gmail.com>
Committed: Tue Sep 20 16:59:28 2016 -0400
----------------------------------------------------------------------
test/configure_spec.js | 38 ++++++++-
test/packageLogs.html | 8 ++
test/packageLogs_spec.js | 180 +++++++++++++++++++++++++++++++++++++++---
3 files changed, 211 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/416450cd/test/configure_spec.js
----------------------------------------------------------------------
diff --git a/test/configure_spec.js b/test/configure_spec.js
index 9f1d6a0..d31f2b4 100644
--- a/test/configure_spec.js
+++ b/test/configure_spec.js
@@ -1,12 +1,44 @@
import { expect } from 'chai';
import jsdom from 'jsdom';
import fs from 'fs';
+import { getUserIdFromParams, configure } from '../src/configure';
describe('configure', () => {
- it('merges new configs into main config object');
+ it('merges new configs into main config object', (done) => {
+ const config = {};
+ const newConfig = { foo: 'bar' };
+ configure(config, newConfig);
+ expect(config).to.deep.equal({ foo: 'bar' });
+ done();
+ });
+
+ it('includes a userid if present in the window.location', (done) => {
+ const config = {};
+ const newConfig = { foo: 'bar', userFromParams: 'user', };
+ const initialWindow = global.window;
+ global.window = { location: { href: '?user=test&'} };
+ configure(config, newConfig);
+ global.window = initialWindow;
+ expect(config).to.deep.equal({ foo: 'bar', userFromParams: 'user', userId: 'test' });
+ done();
+ });
describe('getUserIdFromParams', () => {
- it('fetches userId from URL params');
- it('returns null if no matching param');
+ it('fetches userId from URL params', (done) => {
+ const initialWindow = global.window;
+ global.window = { location: { href: '?user=foo&'} };
+ const userId = getUserIdFromParams('user');
+ global.window = initialWindow;
+ expect(userId).to.equal('foo');
+ done();
+ });
+ it('returns null if no matching param', (done) => {
+ const initialWindow = global.window;
+ global.window = { location: { href: '?user=foo&'} };
+ const userId = getUserIdFromParams('bar');
+ global.window = initialWindow;
+ expect(userId).to.equal(null);
+ done();
+ });
});
});
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/416450cd/test/packageLogs.html
----------------------------------------------------------------------
diff --git a/test/packageLogs.html b/test/packageLogs.html
new file mode 100644
index 0000000..3925545
--- /dev/null
+++ b/test/packageLogs.html
@@ -0,0 +1,8 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+</head>
+<body>
+ <div id="test"></div>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/416450cd/test/packageLogs_spec.js
----------------------------------------------------------------------
diff --git a/test/packageLogs_spec.js b/test/packageLogs_spec.js
index d651ba4..d5401fa 100644
--- a/test/packageLogs_spec.js
+++ b/test/packageLogs_spec.js
@@ -1,24 +1,180 @@
import { expect } from 'chai';
import jsdom from 'jsdom';
import fs from 'fs';
+import * as mod from '../src/packageLogs';
describe('packageLogs', () => {
- it('packages a log');
+ const url = 'file://' + __dirname + '/packageLogs.html';
+ const html = fs.readFileSync(__dirname + '/packageLogs.html');
- describe('getLocation', function(done) {
- it('returns event page location');
- it('calculates page location if unavailable');
- it('fails to null');
+ describe('packageLog', () => {
+ it('only executes if on', (done) => {
+ mod.initPackager([], { on: true });
+ const evt = { target: {}, type: 'test' };
+ expect(mod.packageLog(evt)).to.equal(true);
+
+ mod.initPackager([], { on: false });
+ expect(mod.packageLog({})).to.equal(false);
+
+ done();
+ });
+ it('calls detailFcn with the event as an argument if provided', (done) => {
+ mod.initPackager([], { on: true });
+ let called = false;
+ const evt = { target: {}, type: 'test' };
+ const detailFcn = (e) => {
+ called = true;
+ expect(e).to.equal(evt);
+ };
+ mod.packageLog(evt, detailFcn);
+ expect(called).to.equal(true);
+ done();
+ });
+ it('packages logs', (done) => {
+ mod.initPackager([], { on: true });
+ const evt = {
+ target: {},
+ type: 'test'
+ };
+ expect(mod.packageLog(evt)).to.equal(true);
+ done();
+ });
});
- describe('getSelector', function(done) {
- it('builds a selector');
- it('identifies window');
- it('fails to Unknown');
+ describe('getLocation', () => {
+ it('returns event page location', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ const document = window.document;
+ const ele = document.createElement('div');
+ const evt = new window.MouseEvent('click', {
+ 'view': window,
+ 'bubbles': true,
+ 'cancelable': true
+ });
+ document.body.appendChild(ele);
+ ele.addEventListener('click', (e) => {
+ e.pageX = 0;
+ e.pageY = 0;
+ expect(mod.getLocation(e)).to.deep.equal({ x: 0, y: 0 });
+ done();
+ });
+ ele.dispatchEvent(evt);
+ },
+ });
+ });
+
+ it('calculates page location if unavailable', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ const document = window.document;
+ const ele = document.createElement('div');
+ const evt = new window.MouseEvent('click', {
+ 'view': window,
+ 'bubbles': true,
+ 'cancelable': true
+ });
+ document.body.appendChild(ele);
+ ele.addEventListener('click', (e) => {
+ document.documentElement.scrollLeft = 0;
+ document.documentElement.scrollTop = 0;
+ const originalDocument = global.document;
+ global.document = document;
+ expect(mod.getLocation(e)).to.deep.equal({ x: 0, y: 0 });
+ global.document = originalDocument;
+ done();
+ });
+ ele.dispatchEvent(evt);
+ },
+ });
+ });
+
+ it('fails to null', (done) => {
+ let hadError = false;
+ try {
+ mod.getLocation(null);
+ } catch (e) {
+ hadError = true;
+ }
+ expect(hadError).to.equal(true);
+ done();
+ });
});
- describe('buildPath', function(done) {
- it('builds a path');
- it('defaults to path if available');
+ describe('getSelector', () => {
+ it('builds a selector', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ const document = window.document;
+ const element = document.createElement('div');
+ expect(mod.getSelector(element)).to.equal('div');
+ element.id = 'bar';
+ expect(mod.getSelector(element)).to.equal('div#bar');
+ element.removeAttribute('id');
+ element.classList.add('baz');
+ expect(mod.getSelector(element)).to.equal('div.baz');
+ element.id = 'bar';
+ expect(mod.getSelector(element)).to.equal('div#bar.baz');
+ done();
+ },
+ });
+ });
+
+ it('identifies window', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ expect(mod.getSelector(window)).to.equal('Window');
+ done();
+ },
+ });
+ });
+
+ it('handles a non-null unknown value', (done) => {
+ expect(mod.getSelector('foo')).to.equal('Unknown');
+ done();
+ });
+ });
+
+ describe('buildPath', () => {
+ it('builds a path', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ const document = window.document;
+ const ele = document.createElement('div');
+ const evt = document.createEvent('CustomEvent');
+ evt.initEvent('testEvent', true, true);
+ document.body.appendChild(ele);
+ ele.addEventListener('testEvent', (e) => {
+ expect(mod.buildPath(e)).to.deep.equal(['div', 'body', 'html']);
+ done();
+ });
+ ele.dispatchEvent(evt);
+ },
+ });
+ });
+
+ it('defaults to path if available', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ const document = window.document;
+ const ele = document.createElement('div');
+ const evt = document.createEvent('CustomEvent');
+ evt.initEvent('testEvent', true, true);
+ document.body.appendChild(ele);
+ ele.addEventListener('testEvent', (e) => {
+ e.path = [ele, ele.parentElement, ele.parentElement.parentElement];
+ expect(mod.buildPath(e)).to.deep.equal(['div', 'body', 'html']);
+ done();
+ });
+ ele.dispatchEvent(evt);
+ },
+ });
+ });
});
});