Created
April 10, 2013 13:14
-
-
Save JamieKnight/5354522 to your computer and use it in GitHub Desktop.
RadioNav Code Review - Drawer & Panel Tests (WIP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define("drawerTest", ['Drawer', "Panel"], function(Drawer, Panel) { | |
//Object init - no parameters | |
describe("Radionav Drawer object", function(){ | |
describe("Contructor accepts correct paramaters", function(){ | |
it("Should accept a DOM node as paramater 1", function() { | |
var node = document.createElement("div"); | |
var draw = new Drawer(node) | |
expect(draw instanceof Drawer).toBeTruthy(); | |
}); | |
it("Should throw if parameter 1 is not a DOM node", function() { | |
expect(Drawer).toThrow("Invalid Paramater"); | |
}); | |
}); | |
describe("Panels can be added and retrieved", function(){ | |
it("Should add panel when a panel object is passed as first paramater", function() { | |
var node = document.createElement("div"); | |
var draw = new Drawer(node) | |
var panel = new Panel('name', node, node); | |
expect(draw.addPanel(panel)).toBe(true); | |
expect(draw.panels['name']).toBe(panel); | |
}); | |
it("Should return false is same panel is added more than once", function() { | |
var node = document.createElement("div"); | |
var draw = new Drawer(node) | |
var panel = new Panel('name', node, node); | |
draw.addPanel(panel) | |
expect(draw.addPanel(panel)).toBe(false); | |
}); | |
it("Should throw if paramamter 1 is not a panel", function() { | |
var node = document.createElement("div"); | |
var draw = new Drawer(node) | |
var panel = new Panel('name', node, node); | |
expect(function(){ draw.addPanel('bar')}).toThrow('Invalid Paramater - paramater 1 should be panel object'); | |
}); | |
it("Should return panel when a panel_id string is passed as first paramater", function() { | |
var node = document.createElement("div"); | |
var draw = new Drawer(node) | |
var panel = new Panel('name', node, node); | |
draw.addPanel(panel) | |
expect(draw.getPanel('name')).toBe(panel); | |
}); | |
it("Should return false when a panel_id string is passed as first paramater but no matching panel is found", function() { | |
var node = document.createElement("div"); | |
var draw = new Drawer(node) | |
var panel = new Panel('hamster', node, node); | |
draw.addPanel(panel) | |
expect(draw.getPanel('name')).toBe(false); | |
}); | |
//test setup code moved to outer scope for convinence | |
var node = document.createElement("div"); | |
var draw = new Drawer(node) | |
var panel = new Panel('hamster', node, node); | |
draw.addPanel(panel) | |
it("Should set current panel", function() { | |
expect(draw.setCurrentPanel(panel)).toBe(true); | |
expect(draw.setCurrentPanel(panel)).toBe(true); | |
}); | |
it("Should return false on attempt to set current panel to unknown panel", function() { | |
expect(draw.setCurrentPanel({id: 'example'})).toBe(false); | |
}); | |
it("Should Get current panel", function() { | |
expect(draw.getCurrentPanel()).toBe(panel); | |
}); | |
}); | |
describe("functions for checking state and binding events work correctly", function(){ | |
it("Should return true when drawer is in 'open' state.", function() { | |
var node = document.createElement("div"); | |
var draw = new Drawer(node) | |
expect(draw.isOpen()).toBe(draw.open); | |
}); | |
/* Deffered | |
it("Should bind panel controls", function() { | |
expect(true).toBe(false); | |
}); | |
it("Should return rsn:drawer:open event after rsn:action if panel is correct and drawer is upopned", function() { | |
expect(true).toBe(false); | |
}); | |
it("Should return rsn:drawer:close event after rsn:action if panel is correct and drawer is open on the same panel", function() { | |
expect(true).toBe(false); | |
}); | |
it("Should return rsn:drawer:swap event after rsn:action if panel is correct and drawer is open on a different panel. ", function() { | |
expect(true).toBe(false); | |
}); | |
*/ | |
}); | |
/* | |
describe("openening and closing the drawer and swapping panels.", function(){ | |
it("Should return a promise when drawer is opened", function() { | |
expect(true).toBe(false); | |
}); | |
it("Should return a promise when drawer is close", function() { | |
expect(true).toBe(false); | |
}); | |
it("Should return a promise when panel is swapped", function() { | |
expect(true).toBe(false); | |
}); | |
}); | |
*/ | |
}); | |
describe("Radionav Panel Object", function(){ | |
describe("Contructor is robust", function(){ | |
it("Should accept a string as paramater 1, and DOM node as paramamter 2 and 3", function() { | |
var node = document.createElement("div"); | |
var panel = new Panel('name', node, node); | |
expect(panel instanceof Panel).toBeTruthy(); | |
}); | |
it("Should throw if parameter 1 is not a string", function() { | |
expect(Panel).toThrow("Invalid Paramater - paramater 1 should be a string"); | |
}); | |
it("Should throw if paramamter 2 is not a DOM node", function() { | |
var node = document.createElement("div"); | |
expect(function(){ new Panel('name', null)}).toThrow("Invalid Paramater - paramater 2 should be a DOM Node") | |
}); | |
/* | |
it("Should accept a DOM node as paramater 3", function() { | |
expect(true).toBe(false); | |
}); | |
it("Should throw if paramamter 3 is not a DOM node", function() { | |
expect(true).toBe(false); | |
}); | |
*/ | |
}); | |
/* | |
describe("Hide and show return promises", function(){ | |
it("Should return a promise when panel is show", function() { | |
expect(true).toBe(false); | |
}); | |
it("Should return a promise when panel is hidden", function() { | |
expect(true).toBe(false); | |
}); | |
}) | |
*/ | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment