Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
fix(test): improved test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Yates committed Sep 17, 2016
1 parent 45f60cd commit afc0921
Show file tree
Hide file tree
Showing 32 changed files with 1,386 additions and 114 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
[![Dependencies](https://img.shields.io/david/dev/krux/gpt-mock.svg)](./package.json)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![Gitter](https://badges.gitter.im/krux/gpt-mock.svg)](https://gitter.im/krux/gpt-mock)

A test library to mock out the Google Publisher Tag library.

Expand Down
2 changes: 1 addition & 1 deletion gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ gulp.task('build', build(webpackConfig));
gulp.task('doc', () => {
return gulp.src('./src')
.pipe(esdoc({
destination: './doc'
destination: './docs'
}));
});

Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Test library for mocking out Google Publisher Tags",
"homepage": "https://github.com/krux/gpt-mock/",
"bugs": "https://github.com/krux/gpt-mock/issues",
"license": "Apache-2",
"license": "Apache-2.0",
"keywords": [
"gpt",
"dfp",
Expand Down Expand Up @@ -65,14 +65,14 @@
"babel-plugin-transform-es3-member-expression-literals": "6.8.0",
"babel-plugin-transform-es3-property-literals": "6.8.0",
"babel-plugin-transform-object-assign": "6.8.0",
"babel-plugin-transform-runtime": "6.12.0",
"babel-plugin-transform-runtime": "6.15.0",
"babel-preset-es2015": "6.14.0",
"babel-preset-es2015-loose": "7.0.0",
"babel-preset-es2015-loose": "8.0.0",
"babel-register": "6.14.0",
"babelify": "7.3.0",
"cz-conventional-changelog": "1.2.0",
"del": "2.2.2",
"eslint": "3.4.0",
"eslint": "3.5.0",
"expect.js": "0.3.1",
"gulp": "3.9.1",
"gulp-babel": "6.1.2",
Expand All @@ -86,25 +86,25 @@
"istanbul": "0.4.5",
"jscs": "3.0.7",
"json-loader": "0.5.4",
"karma": "1.2.0",
"karma": "1.3.0",
"karma-babel-preprocessor": "6.0.1",
"karma-coverage": "1.1.1",
"karma-coveralls": "1.1.2",
"karma-expect": "1.1.2",
"karma-mocha": "1.1.1",
"karma-mocha-reporter": "2.1.0",
"karma-phantomjs-launcher": "1.0.1",
"karma-phantomjs-launcher": "1.0.2",
"karma-sinon": "1.0.5",
"karma-webpack": "1.8.0",
"lolex": "1.5.1",
"mocha": "3.0.2",
"phantomjs-prebuilt": "2.1.12",
"process": "0.11.8",
"semantic-release": "^4.3.5",
"process": "0.11.9",
"semantic-release": "4.3.5",
"sinon": "1.17.5",
"watchify": "3.7.0",
"webpack": "1.13.2",
"webpack-dev-server": "1.15.0",
"webpack-dev-server": "1.15.2",
"webpack-stream": "3.2.0"
}
}
6 changes: 4 additions & 2 deletions src/CommandArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export default class CommandArray {
* compatible with Array.push's return value (the current length of the array).
*/
push(f) {
f();
this._count += 1;
if (f != null && typeof f === 'function') {
f();
this._count += 1;
}
return this._count;
}
}
22 changes: 11 additions & 11 deletions src/GPT.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class GPT {
this.cmd = [];
this._version = version;
this._slots = [];
this._slotsByDomId = {};
this._slotCounter = 0;
this._services = {};
this._addService(new CompanionAdsService(this));
this._addService(new ContentService(this));
Expand Down Expand Up @@ -127,7 +127,8 @@ export default class GPT {
* @returns {Slot} The newly created slot.
*/
defineSlot(adUnitPath, size, optDiv) {
return this._addSlot(new Slot(adUnitPath, size, optDiv));
this._slotCounter += 1;
return this._addSlot(new Slot(adUnitPath, size, optDiv, this._slotCounter));
}

/**
Expand All @@ -139,7 +140,8 @@ export default class GPT {
* @returns {Slot} The newly created slot.
*/
defineOutOfPageSlot(adUnitPath, optDiv) {
const slot = new Slot(adUnitPath, [], optDiv);
this._slotCounter += 1;
const slot = new Slot(adUnitPath, [], optDiv, this._slotCounter);
slot._outOfPage = true;
return this._addSlot(slot);
}
Expand All @@ -163,7 +165,7 @@ export default class GPT {
const i = this._slots.indexOf(slot);
if (i !== -1) {
slot._removeServices();
this._slots.splice(i, 1);
this._removeSlot(slot);
} else {
return false;
}
Expand All @@ -189,13 +191,12 @@ export default class GPT {
*/
display(div) {
if (div) {
if (this._slotsByDomId[div]) {
this._slotsByDomId[div].display();
} else {
// TODO - error
for (let slot of this._slots) {
if (slot.getSlotElementId() === div) {
slot.display();
return;
}
}
} else {
// TODO - error
}
}

Expand Down Expand Up @@ -227,7 +228,6 @@ export default class GPT {
_addSlot(slot) {
if (this._slots.indexOf(slot) === -1) {
this._slots.push(slot);
this._slotsByDomId[slot.getSlotElementId()] = slot;
}
return slot;
}
Expand Down
2 changes: 1 addition & 1 deletion src/GeneralSize.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as MultiSize from './MultiSize';
* @param {GeneralSize|*} obj The object to test
*/
export function isGeneralSize(obj) {
return SingleSize.isSingleSize(obj) || MultiSize.isMultiSize(obj);
return obj != null && (SingleSize.isSingleSize(obj) || MultiSize.isMultiSize(obj));
}

/**
Expand Down
4 changes: 0 additions & 4 deletions src/PubAdsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,6 @@ export default class PubAdsService extends Service {
return this;
}

_getCategoryExclusions() {
return this._categoryExclusions.slice(0);
}

/**
* Enables/disables centering of ads. This mode must be set before the service
* is enabled. Centering is disabled by default. In legacy gpt_mobile.js,
Expand Down
16 changes: 8 additions & 8 deletions src/Service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Base service class that contains methods common for all services.
*/
export default class Service {
Expand Down Expand Up @@ -66,16 +66,16 @@ export default class Service {
const index = this._slots.indexOf(slot);
if (index !== -1) {
this._slots.splice(index, 1);
this._gt.removeSlot(slot);
const id = `${slot.getAdUnitPath()}_${index}`;
this._gt._removeSlot(slot);
const id = `${slot.getAdUnitPath()}_${index + 1}`;
delete this._slotIdMap[id];
}
}

/**
* UNDOCUMENTED - Returns a map of ID's to slots.
*
* @returns {Object<string, Slot>} The map of ID's to slots.
* @returns {object} The map of ID's to slots.
*/
getSlotIdMap() {
return Object.assign({}, this._slotIdMap);
Expand All @@ -94,7 +94,7 @@ export default class Service {
*
* @param {string} eventType A string representing the type of event generated
* by GPT. Event types are case sensitive.
* @param {function(Object)} listener Function that takes a single event object argument.
* @param {function} listener Function that takes a single event object argument.
* @returns {Service} The service object on which the method was called.
*/
addEventListener(eventType, listener) {
Expand All @@ -103,8 +103,8 @@ export default class Service {
return this;
}

_fireEvent(event) {
for (let listener of (this._listeners[event.name] || [])) {
_fireEvent(eventType, event) {
for (let listener of (this._listeners[eventType] || [])) {
listener(event);
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ export default class Service {
*
* @param {string} key The name of the attribute.
* @param {string} value Attribute value.
* @returns {*} The service object on which the method was called.
* @returns {Service} The service object on which the method was called.
*/
set(key, value) {
this._attributes[key] = value;
Expand Down
4 changes: 2 additions & 2 deletions src/SingleSize.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as NamedSize from './NamedSize';
* @param {SingleSize|*} obj The object to test
*/
export function isSingleSize(obj) {
return SingleSizeArray.isSingleSizeArray(obj) || NamedSize.isNamedSize(obj);
return obj != null && (SingleSizeArray.isSingleSizeArray(obj) || NamedSize.isNamedSize(obj));
}

/**
Expand All @@ -23,6 +23,6 @@ export function toSize(obj) {
if (SingleSizeArray.isSingleSizeArray(obj)) {
return SingleSizeArray.toSize(obj);
} else {
return null; // TODO - what really happens here?
return null;
}
}
2 changes: 1 addition & 1 deletion src/SingleSizeArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Size from './Size';
* @param {SingleSizeArray|*} obj The object to test
*/
export function isSingleSizeArray(obj) {
if (!Array.isArray(obj) || obj.length !== 2) {
if (obj == null || !Array.isArray(obj) || obj.length !== 2) {
return false;
}

Expand Down
68 changes: 60 additions & 8 deletions src/Size.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/**
* Size is used internally in GPT and is not actually documented.
* UNDOCUMENTED
*
* Size captures a two dimensional size.
*/
export default class Size {
/**
* Creates a new Size instance.
* @param {number} w The width
* @param {number} h The height
* @param {number} width The width
* @param {number} height The height
*/
constructor(w, h) {
this.w = w;
this.h = h;
constructor(width, height) {
this.width = width;
this.height = height;
}

/**
Expand All @@ -18,7 +20,7 @@ export default class Size {
* @returns {number} The width in pixels
*/
getWidth() {
return this.w;
return this.width;
}

/**
Expand All @@ -27,6 +29,56 @@ export default class Size {
* @returns {number} The height in pixels
*/
getHeight() {
return this.h;
return this.height;
}

/**
* UNDOCUMENTED
*
* Returns whether the size is empty.
*
* @returns {boolean} True if the size is empty.
*/
isEmpty() {
return !(this.width * this.height);
}

/**
* UNDOCUMENTED
*
* Truncates the width and height upward.
*
* @returns {Size} The instance called
*/
ceil() {
this.width = Math.ceil(this.width);
this.height = Math.ceil(this.height);
return this;
}

/**
* UNDOCUMENTED
*
* Truncates the width and height downard.
*
* @returns {Size} The instance called
*/
floor() {
this.width = Math.floor(this.width);
this.height = Math.floor(this.height);
return this;
}

/**
* UNDOCUMENTED
*
* Rounds the width and height.
*
* @returns {Size} The instance called
*/
round() {
this.width = Math.round(this.width);
this.height = Math.round(this.height);
return this;
}
}
Loading

0 comments on commit afc0921

Please sign in to comment.