From ec92ac735c17a4ef741ed8f626466e7b4acc8c77 Mon Sep 17 00:00:00 2001 From: execjosh Date: Sun, 28 Aug 2011 20:13:38 +0900 Subject: [PATCH 1/2] Add basic tests for WebPage --- test/run-tests.js | 22 +++++++++++ test/webpage-spec.js | 88 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 test/webpage-spec.js diff --git a/test/run-tests.js b/test/run-tests.js index 03d355e4..ed871f8d 100644 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -2,8 +2,30 @@ phantom.injectJs("./lib/jasmine.js"); phantom.injectJs("./lib/jasmine-console.js"); +// Helper funcs +function expectHasFunction(o, name) { + it("should have '" + name + "' function", function() { + expect(typeof o[name]).toEqual('function'); + }); +} + +function expectHasProperty(o, name) { + it("should have '" + name + "' property", function() { + expect(o.hasOwnProperty(name)).toBeTruthy(); + }); +} + +function expectHasPropertyString(o, name) { + expectHasProperty(o, name); + + it("should have '" + name + "' as a string", function() { + expect(typeof o[name]).toEqual('string'); + }); +} + // Load specs phantom.injectJs("./phantom-spec.js"); +phantom.injectJs("./webpage-spec.js"); phantom.injectJs("./fs-spec-01.js"); //< Filesystem Specs 01 (Basic) phantom.injectJs("./fs-spec-02.js"); //< Filesystem Specs 02 (Attributes) phantom.injectJs("./fs-spec-03.js"); //< Filesystem Specs 03 (Paths) diff --git a/test/webpage-spec.js b/test/webpage-spec.js new file mode 100644 index 00000000..dfb959c1 --- /dev/null +++ b/test/webpage-spec.js @@ -0,0 +1,88 @@ +describe("WebPage constructor", function() { + it("should exist in window", function() { + expect(window.hasOwnProperty('WebPage')).toBeTruthy(); + }); + + it("should be a function", function() { + expect(typeof window.WebPage).toEqual('function'); + }); +}); + +describe("WebPage object", function() { + var page = new WebPage(); + + it("should be creatable", function() { + expect(typeof page).toEqual('object'); + expect(page).toNotEqual(null); + }); + + expectHasProperty(page, 'clipRect'); + it("should have clipRect with height 0", function() { + expect(page.clipRect.height).toEqual(0); + }); + it("should have clipRect with left 0", function() { + expect(page.clipRect.left).toEqual(0); + }); + it("should have clipRect with top 0", function() { + expect(page.clipRect.top).toEqual(0); + }); + it("should have clipRect with width 0", function() { + expect(page.clipRect.width).toEqual(0); + }); + + expectHasPropertyString(page, 'content'); + + expectHasPropertyString(page, 'libraryPath'); + it("should have objectName as 'WebPage'", function() { + expect(page.objectName).toEqual('WebPage'); + }); + + expectHasProperty(page, 'paperSize'); + it("should have paperSize as an empty object", function() { + expect(page.paperSize).toEqual({}); + }); + + expectHasProperty(page, 'scrollPosition'); + it("should have scrollPosition with left 0", function() { + expect(page.scrollPosition.left).toEqual(0); + }); + it("should have scrollPosition with top 0", function() { + expect(page.scrollPosition.top).toEqual(0); + }); + + expectHasProperty(page, 'settings'); + it("should have non-empty settings", function() { + expect(page.settings).toNotEqual(null); + expect(page.settings).toNotEqual({}); + }); + + + expectHasProperty(page, 'viewportSize'); + it("should have viewportSize with height 300", function() { + expect(page.viewportSize.height).toEqual(300); + }); + it("should have viewportSize with width 400", function() { + expect(page.viewportSize.width).toEqual(400); + }); + + expectHasFunction(page, 'destroyed'); + expectHasFunction(page, 'deleteLater'); + expectHasFunction(page, 'initialized'); + expectHasFunction(page, 'loadStarted'); + expectHasFunction(page, 'loadFinished'); + expectHasFunction(page, 'javaScriptAlertSent'); + expectHasFunction(page, 'javaScriptConsoleMessageSent'); + expectHasFunction(page, 'resourceRequested'); + expectHasFunction(page, 'resourceReceived'); + expectHasFunction(page, 'openUrl'); + expectHasFunction(page, 'release'); + expectHasFunction(page, 'evaluate'); + expectHasFunction(page, 'render'); + expectHasFunction(page, 'injectJs'); + expectHasFunction(page, '_appendScriptElement'); + expectHasFunction(page, 'uploadFile'); + expectHasFunction(page, 'click'); + expectHasFunction(page, 'mouseDown'); + expectHasFunction(page, 'mouseUp'); + expectHasFunction(page, 'mouseMoveTo'); +}); From cad33014b43937ac9eb4f4e759fed9fb6420dc26 Mon Sep 17 00:00:00 2001 From: execjosh Date: Sun, 28 Aug 2011 20:24:46 +0900 Subject: [PATCH 2/2] Alphabetize WebPage function tests --- test/webpage-spec.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/webpage-spec.js b/test/webpage-spec.js index dfb959c1..91fc959b 100644 --- a/test/webpage-spec.js +++ b/test/webpage-spec.js @@ -65,24 +65,24 @@ describe("WebPage object", function() { expect(page.viewportSize.width).toEqual(400); }); - expectHasFunction(page, 'destroyed'); + expectHasFunction(page, '_appendScriptElement'); + expectHasFunction(page, 'click'); expectHasFunction(page, 'deleteLater'); + expectHasFunction(page, 'destroyed'); + expectHasFunction(page, 'evaluate'); expectHasFunction(page, 'initialized'); - expectHasFunction(page, 'loadStarted'); - expectHasFunction(page, 'loadFinished'); + expectHasFunction(page, 'injectJs'); expectHasFunction(page, 'javaScriptAlertSent'); expectHasFunction(page, 'javaScriptConsoleMessageSent'); - expectHasFunction(page, 'resourceRequested'); - expectHasFunction(page, 'resourceReceived'); + expectHasFunction(page, 'loadFinished'); + expectHasFunction(page, 'loadStarted'); + expectHasFunction(page, 'mouseDown'); + expectHasFunction(page, 'mouseMoveTo'); + expectHasFunction(page, 'mouseUp'); expectHasFunction(page, 'openUrl'); expectHasFunction(page, 'release'); - expectHasFunction(page, 'evaluate'); expectHasFunction(page, 'render'); - expectHasFunction(page, 'injectJs'); - expectHasFunction(page, '_appendScriptElement'); + expectHasFunction(page, 'resourceReceived'); + expectHasFunction(page, 'resourceRequested'); expectHasFunction(page, 'uploadFile'); - expectHasFunction(page, 'click'); - expectHasFunction(page, 'mouseDown'); - expectHasFunction(page, 'mouseUp'); - expectHasFunction(page, 'mouseMoveTo'); });