/g, /<\/i>/g];
+ stringsToRemove.forEach(function (stringToRemove) {
+ text = text.replace(stringToRemove, '');
+ });
+ if (isFileName) {
+ text = text.replace(/[^a-zA-Z0-9]+/g, "");
+ }
+ return text.trim();
+ };
+
+ var isPage = function (title) {
+ return title && title.toLowerCase() != "content" && title.indexOf("~") != 0;
+ };
+
+ return {
+ isPage: isPage,
+ stripText: stripText
+ };
+});
\ No newline at end of file
diff --git a/test/converter.test.js b/test/converter.test.js
index 67cc9df..5a5514d 100644
--- a/test/converter.test.js
+++ b/test/converter.test.js
@@ -1,64 +1,47 @@
-var async = {
- series: function(arr, cb) {
- cb();
- }
-};
-describe('converter', function() {
- // Define mocks
- var converter;
- var mockZip = {
- file: function() {},
- generate: function() {
- return 'generatedZip';
- }
- };
- var mockOutline = {
- process: function() {
- return [
- {
- filePath: 'path1',
- content: 'content1'
- },
- {
- filePath: 'path2',
- content: 'content2'
- }
- ];
- }
- };
- beforeEach(function() {
- converter = new Converter($($.parseXML('')), 'The Title');
- spyOn(mockZip, 'file');
- spyOn(mockZip, 'generate').and.callThrough();
- spyOn(async, 'series').and.callThrough();
- spyOn(window, 'Outline').and.returnValue(mockOutline);
- spyOn(window, 'JSZip').and.returnValue(mockZip);
- });
+define([
+ 'src/converter',
+ 'test/mock/jszip.mock',
+ 'test/mock/async.mock'
+], function(Converter, mockZip, async) {
- describe('GetZippedHtmlFiles', function() {
- it('adds pages to the zip file for each page returned from the outline', function(done) {
- converter.GetZippedHtmlFiles(function() {
- expect(mockZip.file.calls.count()).toEqual(2);
- expect(mockZip.file).toHaveBeenCalledWith('path1', 'content1');
- expect(mockZip.file).toHaveBeenCalledWith('path2', 'content2');
- done();
- });
+ describe('converter', function() {
+ var converter;
+ var spies = new mockZip().spies;
+
+ beforeEach(function() {
+ converter = new Converter($($.parseXML('')), 'The Title');
+ spyOn(async, 'series').and.callThrough();
});
-
- it('adds static files to the zip', function(done) {
- converter.GetZippedHtmlFiles(function() {
- expect(async.series.calls.count()).toEqual(1);
- expect(async.series.calls.mostRecent().args[0].length).toEqual(8);
- done();
- });
+
+ afterEach(function() {
+ spies.reset();
});
-
- it('calls callback function with generated zip file', function(done) {
- converter.GetZippedHtmlFiles(function(generatedZip) {
- expect(mockZip.generate.calls.count()).toEqual(1);
- expect(mockZip.generate.calls.mostRecent().args[0].type).toEqual('blob');
- expect(generatedZip).toEqual('generatedZip');
- done();
+
+ describe('GetZippedHtmlFiles', function() {
+ it('adds pages to the zip file for each page returned from the outline', function(done) {
+ converter.GetZippedHtmlFiles(function() {
+ expect(spies.file.count).toEqual(2);
+ expect(spies.file.args[0]).toEqual(['path1', 'content1']);
+ expect(spies.file.args[1]).toEqual(['path2', 'content2']);
+ done();
+ });
+ });
+
+ it('adds static files to the zip', function(done) {
+ converter.GetZippedHtmlFiles(function() {
+ expect(async.series.calls.count()).toEqual(1);
+ expect(async.series.calls.mostRecent().args[0].length).toEqual(9);
+ done();
+ });
+ });
+
+ it('calls callback function with generated zip file', function(done) {
+ converter.GetZippedHtmlFiles(function(generatedZip) {
+ expect(spies.generate.count).toEqual(1);
+ expect(spies.generate.lastArg().type).toEqual('blob');
+ expect(generatedZip).toEqual('generatedZip');
+ done();
+ });
});
});
});
diff --git a/test/htmlGenerator.test.js b/test/htmlGenerator.test.js
index 2f895cd..4b66f1f 100644
--- a/test/htmlGenerator.test.js
+++ b/test/htmlGenerator.test.js
@@ -1,52 +1,56 @@
-describe('outline', function() {
- var generator = new HtmlGenerator();
- var opml = '' +
-'' +
- '' +
- 'sat@softwire.com' +
- '' +
- '' +
- '' +
- '' +
- '' +
- '' +
- '' +
+define([
+ 'src/htmlGenerator'
+], function(HtmlGenerator) {
+ describe('outline', function() {
+ var generator = new HtmlGenerator();
+ var opml = '' +
+ '' +
+ '' +
+ 'sat@softwire.com' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
'' +
- '' +
- '' +
- '' +
- '' +
-'';
- var navObject = [[
- {
- displayText: 'Home',
- path: '../../home.html',
- selected: true
- },
- {
- displayText: 'Section',
- path: '../../section.html',
- selected: false
- }
- ],[
- {
- displayText: 'Top',
- path: '../top.html',
- selected: true
- },
- {
- displayText: 'Footer - tag',
- path: '../footertag.html',
- selected: false
- }
- ]];
- var expectedHtml = 'Footer - tagSite Title
Something - or other
TV – Quarterly Reach / Share / Av Time
';
+ '' +
+ '' +
+ '' +
+ '' +
+ '';
+ var navObject = [[
+ {
+ displayText: 'Home',
+ path: '../../home.html',
+ selected: true
+ },
+ {
+ displayText: 'Section',
+ path: '../../section.html',
+ selected: false
+ }
+ ],[
+ {
+ displayText: 'Top',
+ path: '../top.html',
+ selected: true
+ },
+ {
+ displayText: 'Footer - tag',
+ path: '../footertag.html',
+ selected: false
+ }
+ ]];
+ var expectedHtml = 'Footer - tagSite Title
Something - or other
TV � Quarterly Reach / Share / Av Time
';
- describe('generate', function() {
- it('returns the correct HTML', function() {
- var result = generator.generate($($($.parseXML(opml)).find('body').children()[1]),
- 'Site Title', 'Footer - tag', navObject, 2);
- expect(result).toEqual(expectedHtml);
+ describe('generate', function() {
+ it('returns the correct HTML', function() {
+ var result = generator.generate($($($.parseXML(opml)).find('body').children()[1]),
+ 'Site Title', 'Footer - tag', navObject, 2);
+ expect(result).toEqual(expectedHtml);
+ });
});
});
});
\ No newline at end of file
diff --git a/test/mock/async.mock.js b/test/mock/async.mock.js
new file mode 100644
index 0000000..ce1c540
--- /dev/null
+++ b/test/mock/async.mock.js
@@ -0,0 +1,7 @@
+define([], function () {
+ return {
+ series: function (arr, cb) {
+ cb();
+ }
+ };
+});
\ No newline at end of file
diff --git a/test/mock/jszip.mock.js b/test/mock/jszip.mock.js
new file mode 100644
index 0000000..732cd8c
--- /dev/null
+++ b/test/mock/jszip.mock.js
@@ -0,0 +1,35 @@
+define([], function () {
+ var Spy = function () {
+ return {
+ count: 0,
+ args: [],
+ lastArg: function () {
+ if (this.args.length === 0) {
+ return null;
+ } else {
+ return this.args[this.args.length - 1];
+ }
+ }
+ };
+ };
+ var spies = {
+ file: new Spy(),
+ generate: new Spy(),
+ reset: function () {
+ this.file = new Spy();
+ this.generate = new Spy();
+ }
+ };
+ return function () {
+ this.file = function (arg1, arg2) {
+ spies.file.count++;
+ spies.file.args.push([arg1, arg2]);
+ };
+ this.generate = function (arg) {
+ spies.generate.count++;
+ spies.generate.args.push(arg);
+ return 'generatedZip';
+ };
+ this.spies = spies;
+ };
+});
\ No newline at end of file
diff --git a/test/mock/outline.mock.js b/test/mock/outline.mock.js
new file mode 100644
index 0000000..afc4ec7
--- /dev/null
+++ b/test/mock/outline.mock.js
@@ -0,0 +1,16 @@
+define([], function () {
+ return function () {
+ this.process = function () {
+ return [
+ {
+ filePath: 'path1',
+ content: 'content1'
+ },
+ {
+ filePath: 'path2',
+ content: 'content2'
+ }
+ ];
+ }
+ };
+});
\ No newline at end of file
diff --git a/test/outline.test.js b/test/outline.test.js
index e0e0a68..5cae3f0 100644
--- a/test/outline.test.js
+++ b/test/outline.test.js
@@ -1,87 +1,92 @@
-describe('outline', function() {
- var outline;
+define([
+ 'src/outline'
+], function(Outline) {
- beforeEach(function() {
- var opml = '' +
-'' +
- '' +
- 'sat@softwire.com' +
- '' +
- '' +
- '' +
- '' +
- '' +
- '' +
- '' +
- '' +
- '' +
- '' +
- '' +
- '' +
-'';
- var generator = {
- generate: function(node, siteTitle, title, navigationObject, navLevel) {
- return arguments;
- }
- };
- outline = new Outline(
- $($.parseXML(opml)).find('body'),
- 'Site Title',
- generator,
- 'Page Title',
- 'pageTitle',
- '/path/to',
- [[
- {
- displayText: 'Home',
- path: 'path/to/home.html',
- selected: true
- },
- {
- displayText: 'Section',
- path: 'path/to/section.html',
- selected: false
- }
- ]]);
- });
+ describe('outline', function () {
+ var outline;
- describe('process', function() {
- it('returns a list of html pages with structured file paths', function() {
- var result = outline.process();
- expect(result.length).toBe(4);
- expect(result[0].filePath).toEqual('/path/to/pageTitle.html');
- expect(result[1].filePath).toEqual('/path/to/pageTitle/top.html');
- expect(result[2].filePath).toEqual('/path/to/pageTitle/footertag.html');
- expect(result[3].filePath).toEqual('/path/to/pageTitle/footertag/print.html');
+ beforeEach(function () {
+ var opml = '' +
+ '' +
+ '' +
+ 'sat@softwire.com' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '';
+ var generator = {
+ generate: function (node, siteTitle, title, navigationObject, navLevel) {
+ return arguments;
+ }
+ };
+ outline = new Outline(
+ $($.parseXML(opml)).find('body'),
+ 'Site Title',
+ generator,
+ 'Page Title',
+ 'pageTitle',
+ '/path/to',
+ [[
+ {
+ displayText: 'Home',
+ path: 'path/to/home.html',
+ selected: true
+ },
+ {
+ displayText: 'Section',
+ path: 'path/to/section.html',
+ selected: false
+ }
+ ]]);
});
- it('calls the generator with the correct title for each page', function() {
- var result = outline.process();
- expect(result[0].content[2]).toEqual('Page Title');
- expect(result[1].content[2]).toEqual('Top');
- expect(result[2].content[2]).toEqual('Footer - tag');
- expect(result[3].content[2]).toEqual('Print');
- });
-
- it('calls the generator with the navigation object for the page', function() {
- var result = outline.process();
- expect(result[0].content[3].length).toEqual(2);
- expect(result[3].content[3][2][0].path).toEqual('../footertag/print.html');
- });
-
- it('sets the selected state of parent pages in the navigation object', function() {
- var result = outline.process();
- expect(result[3].content[3][0][0].selected).toEqual(true);
- expect(result[3].content[3][1][1].selected).toEqual(true);
- expect(result[3].content[3][2][0].selected).toEqual(true);
- });
-
- it('calls the generator with the navigation level of the page', function() {
- var result = outline.process();
- expect(result[0].content[4]).toEqual(1);
- expect(result[1].content[4]).toEqual(2);
- expect(result[2].content[4]).toEqual(2);
- expect(result[3].content[4]).toEqual(3);
+ describe('process', function () {
+ it('returns a list of html pages with structured file paths', function () {
+ var result = outline.process();
+ expect(result.length).toBe(4);
+ expect(result[0].filePath).toEqual('/path/to/pageTitle.html');
+ expect(result[1].filePath).toEqual('/path/to/pageTitle/top.html');
+ expect(result[2].filePath).toEqual('/path/to/pageTitle/footertag.html');
+ expect(result[3].filePath).toEqual('/path/to/pageTitle/footertag/print.html');
+ });
+
+ it('calls the generator with the correct title for each page', function () {
+ var result = outline.process();
+ expect(result[0].content[2]).toEqual('Page Title');
+ expect(result[1].content[2]).toEqual('Top');
+ expect(result[2].content[2]).toEqual('Footer - tag');
+ expect(result[3].content[2]).toEqual('Print');
+ });
+
+ it('calls the generator with the navigation object for the page', function () {
+ var result = outline.process();
+ expect(result[0].content[3].length).toEqual(2);
+ expect(result[3].content[3][2][0].path).toEqual('../footertag/print.html');
+ });
+
+ it('sets the selected state of parent pages in the navigation object', function () {
+ var result = outline.process();
+ expect(result[3].content[3][0][0].selected).toEqual(true);
+ expect(result[3].content[3][1][1].selected).toEqual(true);
+ expect(result[3].content[3][2][0].selected).toEqual(true);
+ });
+
+ it('calls the generator with the navigation level of the page', function () {
+ var result = outline.process();
+ expect(result[0].content[4]).toEqual(1);
+ expect(result[1].content[4]).toEqual(2);
+ expect(result[2].content[4]).toEqual(2);
+ expect(result[3].content[4]).toEqual(3);
+ });
});
});
});
\ No newline at end of file
diff --git a/test/test-main.js b/test/test-main.js
new file mode 100644
index 0000000..0134f6a
--- /dev/null
+++ b/test/test-main.js
@@ -0,0 +1,38 @@
+var tests = [];
+for (var file in window.__karma__.files) {
+ if (window.__karma__.files.hasOwnProperty(file)) {
+ if (/\.test\.js$/.test(file)) {
+ tests.push(file);
+ }
+ }
+}
+window.chrome = {
+ extension: {
+ getURL: function (url, callback) {
+ }
+ }
+};
+
+requirejs.config({
+ // Karma serves files from '/base'
+ baseUrl: '/base',
+
+ paths: {
+ 'lib': '/base/lib'
+ },
+
+ map: {
+ 'src/converter': {
+ 'src/outline': 'test/mock/outline.mock',
+ 'lib/jszip.min': 'test/mock/jszip.mock',
+ 'lib/async.min': 'test/mock/async.mock'
+ }
+ },
+
+ // ask Require.js to load these files (all our tests)
+ deps: tests,
+
+ // start test run, once Require.js is done
+ callback: window.__karma__.start
+});
+
diff --git a/test/utilities.test.js b/test/utilities.test.js
index c6da8d3..bd31e54 100644
--- a/test/utilities.test.js
+++ b/test/utilities.test.js
@@ -1,38 +1,42 @@
-describe('utilities', function() {
- describe('stripText', function() {
- it('returns an empty string if no string is provided', function() {
- expect(stripText(null)).toBe('');
- expect(stripText()).toBe('');
+define([
+ 'src/utilities'
+], function(Util) {
+ describe('utilities', function () {
+ describe('stripText', function () {
+ it('returns an empty string if no string is provided', function () {
+ expect(Util.stripText(null)).toBe('');
+ expect(Util.stripText()).toBe('');
+ });
+ it('removes bold tags', function () {
+ expect(Util.stripText('Something important here')).toBe('Something important here');
+ });
+ it('removes italic tags', function () {
+ expect(Util.stripText('Something important here')).toBe('Something important here');
+ });
+ it('trims excess spaces', function () {
+ expect(Util.stripText('Something important ')).toBe('Something important');
+ });
+ it('removes removes all spaces from file names', function () {
+ expect(Util.stripText('File name', true)).toBe('Filename');
+ });
+ it('removes removes all non alpha-numeric characters from file names', function () {
+ expect(Util.stripText('[]#~:;File"�$%^&* name!()-+@{}', true)).toBe('Filename');
+ });
});
- it('removes bold tags', function() {
- expect(stripText('Something important here')).toBe('Something important here');
- });
- it('removes italic tags', function() {
- expect(stripText('Something important here')).toBe('Something important here');
- });
- it('trims excess spaces', function() {
- expect(stripText('Something important ')).toBe('Something important');
- });
- it('removes removes all spaces from file names', function() {
- expect(stripText('File name', true)).toBe('Filename');
- });
- it('removes removes all non alpha-numeric characters from file names', function() {
- expect(stripText('[]#~:;File"£$%^&* name!()-+@{}', true)).toBe('Filename');
- });
- });
- describe('isPage', function() {
- it('returns false if title is empty', function() {
- expect(isPage('')).toBe('');
- });
- it('returns false if title is Content', function() {
- expect(isPage('Content')).toBe(false);
- });
- it('returns false if title starts with ~', function() {
- expect(isPage('~Something')).toBe(false);
- });
- it('returns true otherwise', function() {
- expect(isPage('Something~')).toBe(true);
+ describe('isPage', function () {
+ it('returns false if title is empty', function () {
+ expect(Util.isPage('')).toBe('');
+ });
+ it('returns false if title is Content', function () {
+ expect(Util.isPage('Content')).toBe(false);
+ });
+ it('returns false if title starts with ~', function () {
+ expect(Util.isPage('~Something')).toBe(false);
+ });
+ it('returns true otherwise', function () {
+ expect(Util.isPage('Something~')).toBe(true);
+ });
});
});
});
\ No newline at end of file