'use strict';

const
	sinon = require('sinon');

require('chai')
	.use(require('sinon-chai'))
	.should();

const
	clientUserActivityEvents = require('../../src/plugins/user-activity-events/client');

let MockClient = function() {};

describe('user-activity-events', () => {

	beforeEach(() => {
		global.document = {
		};
	});

	describe('client', () => {

		var client;

		beforeEach(() => {
			global.window = {};
			client = new MockClient();
		});

		afterEach(() => {
		});

		describe('mutation-observer', () => {

			var addEventListener;

			beforeEach(() => {
				addEventListener = sinon.spy();
				global.document.addEventListener = addEventListener;
			});

			it('should add an click event listener', () => {
				clientUserActivityEvents(client);
				addEventListener.should.have.been.calledWith('click');
			});

			it('should add an keydown event listener', () => {
				clientUserActivityEvents(client);
				addEventListener.should.have.been.calledWith('keydown');
			});

		});

	});

});

@@ -201,33 +201,99 @@
 let 
-MockClient = function() %7B
+sendEvent = function() %7B%7D;%0Alet MockClient = function() %7B%0A%09return %7B sendEvent: sendEvent %7D;%0A
 %7D;%0A%0A
@@ -430,17 +430,16 @@
 client;%0A
-%0A
 %09%09before
@@ -554,25 +554,35 @@
 be('
-mutation-observer
+user activity events client
 ', (
@@ -614,16 +614,33 @@
 stener;%0A
+%09%09%09var sendEvent;
 %0A%09%09%09befo
@@ -690,16 +690,45 @@
 .spy();%0A
+%09%09%09%09sendEvent = sinon.spy();%0A
 %09%09%09%09glob
@@ -776,16 +776,50 @@
 stener;%0A
+%09%09%09%09client.sendEvent = sendEvent;%0A
 %09%09%09%7D);%0A%0A
@@ -851,32 +851,79 @@
 k event listener
+ which triggers a userIsActiveEvent when called
 ', () =%3E %7B%0A%09%09%09%09c
@@ -1010,24 +1010,256 @@
 h('click');%0A
+%09%09%09%09//call the actual event handler function and test if it is actually triggering the userIsActive event when it is called%0A%09%09%09%09addEventListener.getCall(0).args%5B1%5D.apply();%0A%09%09%09%09sendEvent.should.have.been.calledWith('userIsActive');%0A
 %09%09%09%7D);%0A%0A%09%09%09i

make unit tests meatier