Skip to content
This repository has been archived by the owner on Oct 4, 2018. It is now read-only.

Commit

Permalink
#46 start fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cobbdb committed Aug 9, 2016
1 parent a30b533 commit d898388
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 86 deletions.
14 changes: 7 additions & 7 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ module.exports = function (grunt) {
grunt.loadTasks('tasks');

grunt.registerTask('build', 'Build distributable without tests.', [
'browserify:global',
'uglify:build'
'browserify:bundle',
'uglify:bundle'
]);
grunt.registerTask('default', 'Full build suite.', [
'browserify',
'jasmine:modules',
'jasmine:specBundles',
'jshint',
'uglify:build',
'jasmine:global'
'uglify:bundle',
'jasmine:bundle'
]);
grunt.registerTask('test', 'Run tests.', [
'browserify:tests',
'jasmine:modules'
'browserify:specs',
'jasmine:specBundles'
]);
grunt.registerTask('docs', 'Build and deploy autodocs.', [
'build-readme',
Expand Down
17 changes: 16 additions & 1 deletion src/types/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ module.exports = function (groupName) {
* @type {string}
*/
name: groupName,
/**
* ## group.length()
* @return {!number}
*/
length: function () {
return slotList.length;
},
/**
* ## group.add(slot)
* Add a new slot to this group.
Expand All @@ -35,7 +42,15 @@ module.exports = function (groupName) {
* @return {?Slot}
*/
get: function (name) {
return slotMap[name];
return slotMap[name] || null;
},
/**
* ## group.getAll()
* *Danger Zone* Fetch all slots in this group.
* @return {!Slot[]}
*/
getAll: function () {
return slotList;
},
/**
* ## group.has(name)
Expand Down
4 changes: 2 additions & 2 deletions tasks/browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function (grunt) {

grunt.config.merge({
browserify: {
global: {
bundle: {
files: {
'bin/harmony.js': 'src/harmony.js'
},
Expand All @@ -24,7 +24,7 @@ module.exports = function (grunt) {
}
}
},
tests: {
specs: {
files: specSet.reduce(function (prev, cur) {
prev['bin/tests/' + cur] = [
'tests/' + cur,
Expand Down
4 changes: 2 additions & 2 deletions tasks/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ var $ = require('curb');
module.exports = function (grunt) {
grunt.config.merge({
jasmine: {
global: {
bundle: {
src: 'dist/harmony.min.js',
options: {
specs: 'tests/global/*.spec.js'
}
},
modules: {
specBundles: {
src: $('bin/tests/%s.spec.js',
grunt.option('spec') || '*'
)
Expand Down
5 changes: 2 additions & 3 deletions tasks/uglify.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
module.exports = function (grunt) {
grunt.config.merge({
uglify: {
build: {
bundle: {
files: {
'dist/harmony.min.js': 'bin/harmony.js'
}
},
options: {
mangle: {
except: [
'googletag',
'Lumberjack'
'googletag'
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/breakpoint-watcher.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var watcher = require('../src/breakpoint-watcher.js'),
screen = require('../src/screen.js');
var watcher = require('../src/modules/breakpoint-watcher.js'),
screen = require('../src/modules/screen.js');

describe('Breakpoint Watcher', function () {
afterEach(function () {
Expand Down
4 changes: 2 additions & 2 deletions tests/global/global.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* Just smoke-test a few global properties.
*/
describe('Global variable', function () {
it('is provided', function () {
it('is provided as "harmony"', function () {
expect(harmony).toBeDefined();
});
it('is constructor', function () {
it('is defined', function () {
expect(harmony.defineSlot).toBeDefined();
expect(harmony.show).toBeDefined();
});
Expand Down
43 changes: 0 additions & 43 deletions tests/group-set.spec.js

This file was deleted.

60 changes: 60 additions & 0 deletions tests/group.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var Group = require('../src/types/group.js');

describe('Group', function () {
it('can have a name', function () {
var group = Group('test-name');
expect(group.name).toEqual('test-name');
});
it('is not required to have a name', function () {
var group = Group();
expect(group.name).toBeUndefined();
});
describe('length()', function () {
it('returns the current length', function () {
var group = Group();
expect(group.length()).toEqual(0);
});
});
describe('get()', function () {
it('returns null on bad name', function () {
var group = Group();
var slot = group.get('not-here');
expect(slot).toBeNull();
});
it('returns previously added data', function () {
var group = Group();
group.add({
name: 'testname1',
val: 'testval1'
});
group.add({
name: 'testname2',
val: 'testval2'
});
expect(group.length()).toEqual(2);
expect(group.get('testname1').val).toEqual('testval1');
expect(group.get('testname2').val).toEqual('testval2');
});
});
describe('getAll()', function () {
it('returns all slots in the group', function () {
var group = Group();
group.add({});
group.add({});
group.add({});
expect(group.getAll().length).toEqual(3);
});
});
describe('clear()', function () {
it('removes all existing data', function () {
var group = Group();
group.add({
name: 'testname',
val: 'testval'
});
expect(group.length()).toEqual(1);
group.clear();
expect(group.length()).toEqual(0);
});
});
});
20 changes: 11 additions & 9 deletions tests/harmony.accessor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ var harmony = require('../src/harmony.js'),
describe('accessor', function () {
beforeEach(function () {
Help.setupDOM();
harmony.load(Help.getConf());
var conf = Help.getConf();
harmony.load.slots(conf.slots);
harmony.load.targeting(conf.targeting);
});
describe('harmony.slot()', function () {
it('fetches an existing ad slot', function () {
var slot = harmony.slot('TST01');
expect(slot.mock).toBeUndefined();
expect(slot.divId).toEqual('h-ad-2');
expect(slot.id).toEqual('h-ad-2');
});
it('fetches a mock slot by default', function () {
var slot = harmony.slot('BAD01');
Expand All @@ -21,7 +23,7 @@ describe('accessor', function () {
it('can cache targeting', function () {
var slot = harmony.slot('new1');
expect(slot.mock).toBe(true);
slot.setTargeting('key1', 'val1');
slot.gpt.setTargeting('key1', 'val1');
var opts = Options({
id: 'newid',
name: 'new1',
Expand All @@ -35,20 +37,20 @@ describe('accessor', function () {
harmony.defineSlot(opts);
slot = harmony.slot('new1');
expect(slot.mock).toBeUndefined();
expect(slot.setTargeting).toHaveBeenCalledWith('key1', 'val1');
expect(slot.setTargeting).toHaveBeenCalledWith('key2', 'val2');
expect(slot.gpt.setTargeting).toHaveBeenCalledWith('key1', 'val1');
expect(slot.gpt.setTargeting).toHaveBeenCalledWith('key2', 'val2');
});
});
describe('harmony.group()', function () {
it('fetches an existing group', function () {
var group = harmony.group('TSTGRP00');
expect(group.length).toEqual(2);
expect(group[1].divId).toEqual('h-ad-3');
expect(group.length()).toEqual(2);
expect(group.get('TST02').id).toEqual('h-ad-3');
});
it('fetches an empty array by default', function () {
var group = harmony.group('BAD02');
expect(group.length).toEqual(0);
expect(group).toEqual([]);
expect(group.length()).toEqual(0);
expect(group.getAll()).toEqual([]);
});
});
});
4 changes: 2 additions & 2 deletions tests/harmony.construction.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var harmony = require('../src/harmony.js');

describe('construction', function () {
it('throws no errors', function () {
it('can be loaded with require()', function () {
expect(harmony).toBeDefined();
});
it('returns a useable instance', function () {
// Smoke check a couple attributes.
expect(harmony.load).toBeDefined();
expect(harmony.log).toBeDefined();
expect(harmony.show).toBeDefined();
expect(harmony.hide.slot).toBeDefined();
expect(harmony.show.slot).toBeDefined();
});
});
Loading

0 comments on commit d898388

Please sign in to comment.