Best Python code snippet using autotest_python
test_Signal.js
Source:test_Signal.js
1if (typeof(dojo) != 'undefined') { dojo.require('MochiKit.Signal'); }2if (typeof(JSAN) != 'undefined') { JSAN.use('MochiKit.Signal'); }3if (typeof(tests) == 'undefined') { tests = {}; }4tests.test_Signal = function (t) {5 6 var submit = MochiKit.DOM.getElement('submit');7 var ident = null;8 var i = 0;9 var aFunction = function() {10 t.ok(this === submit, "aFunction should have 'this' as submit");11 i++;12 if (typeof(this.someVar) != 'undefined') {13 i += this.someVar;14 }15 };16 17 var aObject = {};18 aObject.aMethod = function() {19 t.ok(this === aObject, "aMethod should have 'this' as aObject");20 i++;21 };22 ident = connect('submit', 'onclick', aFunction);23 MochiKit.DOM.getElement('submit').click();24 t.is(i, 1, 'HTML onclick event can be connected to a function');25 disconnect(ident);26 MochiKit.DOM.getElement('submit').click();27 t.is(i, 1, 'HTML onclick can be disconnected from a function');28 var submit = MochiKit.DOM.getElement('submit');29 ident = connect(submit, 'onclick', aFunction);30 submit.click();31 t.is(i, 2, 'Checking that a DOM element can be connected to a function');32 disconnect(ident);33 submit.click();34 t.is(i, 2, '...and then disconnected'); 35 36 if (MochiKit.DOM.getElement('submit').fireEvent || 37 (document.createEvent && 38 typeof(document.createEvent('MouseEvents').initMouseEvent) == 'function')) {39 40 /* 41 42 Adapted from: 43 http://www.devdaily.com/java/jwarehouse/jforum/tests/selenium/javascript/htmlutils.js.shtml44 License: Apache45 Copyright: Copyright 2004 ThoughtWorks, Inc46 47 */48 var triggerMouseEvent = function(element, eventType, canBubble) {49 element = MochiKit.DOM.getElement(element);50 canBubble = (typeof(canBubble) == 'undefined') ? true : canBubble;51 if (element.fireEvent) {52 var newEvt = document.createEventObject();53 newEvt.clientX = 1;54 newEvt.clientY = 1;55 newEvt.button = 1;56 element.fireEvent('on' + eventType, newEvt);57 } else if (document.createEvent && (typeof(document.createEvent('MouseEvents').initMouseEvent) == 'function')) {58 var evt = document.createEvent('MouseEvents');59 evt.initMouseEvent(eventType, canBubble, true, // event, bubbles, cancelable60 document.defaultView, 1, // view, # of clicks61 1, 0, 0, 0, // screenX, screenY, clientX, clientY62 false, false, false, false, // ctrlKey, altKey, shiftKey, metaKey63 0, null); // buttonCode, relatedTarget64 element.dispatchEvent(evt);65 }66 };67 var eventTest = function(e) {68 i++;69 t.ok((typeof(e.event()) === 'object'), 'checking that event() is an object');70 t.ok((typeof(e.type()) === 'string'), 'checking that type() is a string');71 t.ok((e.target() === MochiKit.DOM.getElement('submit')), 'checking that target is "submit"');72 t.ok((typeof(e.modifier()) === 'object'), 'checking that modifier() is an object');73 t.ok(e.modifier().alt === false, 'checking that modifier().alt is defined, but false');74 t.ok(e.modifier().ctrl === false, 'checking that modifier().ctrl is defined, but false');75 t.ok(e.modifier().meta === false, 'checking that modifier().meta is defined, but false');76 t.ok(e.modifier().shift === false, 'checking that modifier().shift is defined, but false');77 t.ok((typeof(e.mouse()) === 'object'), 'checking that mouse() is an object');78 t.ok((typeof(e.mouse().button) === 'object'), 'checking that mouse().button is an object');79 t.ok(e.mouse().button.left === true, 'checking that mouse().button.left is true');80 t.ok(e.mouse().button.middle === false, 'checking that mouse().button.middle is false');81 t.ok(e.mouse().button.right === false, 'checking that mouse().button.right is false');82 t.ok((typeof(e.mouse().page) === 'object'), 'checking that mouse().page is an object');83 t.ok((typeof(e.mouse().page.x) === 'number'), 'checking that mouse().page.x is a number');84 t.ok((typeof(e.mouse().page.y) === 'number'), 'checking that mouse().page.y is a number');85 t.ok((typeof(e.mouse().client) === 'object'), 'checking that mouse().client is an object');86 t.ok((typeof(e.mouse().client.x) === 'number'), 'checking that mouse().client.x is a number');87 t.ok((typeof(e.mouse().client.y) === 'number'), 'checking that mouse().client.y is a number');88 /* these should not be defined */89 t.ok((typeof(e.relatedTarget()) === 'undefined'), 'checking that relatedTarget() is undefined');90 t.ok((typeof(e.key()) === 'undefined'), 'checking that key() is undefined');91 };92 93 ident = connect('submit', 'onmousedown', eventTest);94 triggerMouseEvent('submit', 'mousedown', false);95 t.is(i, 3, 'Connecting an event to an HTML object and firing a synthetic event');96 disconnect(ident);97 triggerMouseEvent('submit', 'mousedown', false);98 t.is(i, 3, 'Disconnecting an event to an HTML object and firing a synthetic event');99 100 } 101 // non-DOM tests102 var hasNoSignals = {};103 104 var hasSignals = {someVar: 1};105 var i = 0;106 107 var aFunction = function() {108 i++;109 if (typeof(this.someVar) != 'undefined') {110 i += this.someVar;111 }112 };113 114 var bFunction = function(someArg, someOtherArg) {115 i += someArg + someOtherArg;116 };117 118 var aObject = {};119 aObject.aMethod = function() {120 i++;121 };122 123 aObject.bMethod = function() {124 i++;125 };126 127 var bObject = {};128 bObject.bMethod = function() {129 i++;130 };131 ident = connect(hasSignals, 'signalOne', aFunction);132 signal(hasSignals, 'signalOne');133 t.is(i, 2, 'Connecting function');134 i = 0;135 disconnect(ident);136 signal(hasSignals, 'signalOne');137 t.is(i, 0, 'New style disconnecting function');138 i = 0;139 ident = connect(hasSignals, 'signalOne', bFunction);140 signal(hasSignals, 'signalOne', 1, 2);141 t.is(i, 3, 'Connecting function');142 i = 0;143 disconnect(ident);144 signal(hasSignals, 'signalOne', 1, 2);145 t.is(i, 0, 'New style disconnecting function');146 i = 0;147 connect(hasSignals, 'signalOne', aFunction);148 signal(hasSignals, 'signalOne');149 t.is(i, 2, 'Connecting function');150 i = 0;151 disconnect(hasSignals, 'signalOne', aFunction);152 signal(hasSignals, 'signalOne');153 t.is(i, 0, 'Old style disconnecting function');154 i = 0;155 ident = connect(hasSignals, 'signalOne', aObject, aObject.aMethod);156 signal(hasSignals, 'signalOne');157 t.is(i, 1, 'Connecting obj-function');158 i = 0;159 disconnect(ident);160 signal(hasSignals, 'signalOne');161 t.is(i, 0, 'New style disconnecting obj-function');162 i = 0;163 connect(hasSignals, 'signalOne', aObject, aObject.aMethod);164 signal(hasSignals, 'signalOne');165 t.is(i, 1, 'Connecting obj-function');166 i = 0;167 disconnect(hasSignals, 'signalOne', aObject, aObject.aMethod);168 signal(hasSignals, 'signalOne');169 t.is(i, 0, 'Disconnecting obj-function');170 i = 0;171 ident = connect(hasSignals, 'signalTwo', aObject, 'aMethod');172 signal(hasSignals, 'signalTwo');173 t.is(i, 1, 'Connecting obj-string');174 i = 0;175 disconnect(ident);176 signal(hasSignals, 'signalTwo');177 t.is(i, 0, 'New style disconnecting obj-string');178 i = 0;179 connect(hasSignals, 'signalTwo', aObject, 'aMethod');180 signal(hasSignals, 'signalTwo');181 t.is(i, 1, 'Connecting obj-string');182 i = 0;183 disconnect(hasSignals, 'signalTwo', aObject, 'aMethod');184 signal(hasSignals, 'signalTwo');185 t.is(i, 0, 'Old style disconnecting obj-string');186 i = 0;187 var shouldRaise = function() { return undefined.attr; };188 try {189 connect(hasSignals, 'signalOne', shouldRaise);190 signal(hasSignals, 'signalOne');191 t.ok(false, 'An exception was not raised');192 } catch (e) {193 t.ok(true, 'An exception was raised');194 }195 disconnect(hasSignals, 'signalOne', shouldRaise);196 t.is(i, 0, 'Exception raised, signal should not have fired');197 i = 0;198 199 connect(hasSignals, 'signalOne', aObject, 'aMethod');200 connect(hasSignals, 'signalOne', aObject, 'bMethod');201 signal(hasSignals, 'signalOne');202 t.is(i, 2, 'Connecting one signal to two slots in one object');203 i = 0;204 205 disconnect(hasSignals, 'signalOne', aObject, 'aMethod');206 disconnect(hasSignals, 'signalOne', aObject, 'bMethod');207 signal(hasSignals, 'signalOne');208 t.is(i, 0, 'Disconnecting one signal from two slots in one object');209 i = 0;210 connect(hasSignals, 'signalOne', aObject, 'aMethod');211 connect(hasSignals, 'signalOne', bObject, 'bMethod');212 signal(hasSignals, 'signalOne');213 t.is(i, 2, 'Connecting one signal to two slots in two objects');214 i = 0;215 disconnect(hasSignals, 'signalOne', aObject, 'aMethod');216 disconnect(hasSignals, 'signalOne', bObject, 'bMethod');217 signal(hasSignals, 'signalOne');218 t.is(i, 0, 'Disconnecting one signal from two slots in two objects');219 i = 0;220 221 try {222 connect(nothing, 'signalOne', aObject, 'aMethod');223 signal(nothing, 'signalOne');224 t.ok(false, 'An exception was not raised when connecting undefined');225 } catch (e) {226 t.ok(true, 'An exception was raised when connecting undefined');227 }228 try {229 disconnect(nothing, 'signalOne', aObject, 'aMethod');230 t.ok(false, 'An exception was not raised when disconnecting undefined');231 } catch (e) {232 t.ok(true, 'An exception was raised when disconnecting undefined');233 }234 235 236 try {237 connect(hasSignals, 'signalOne', nothing);238 signal(hasSignals, 'signalOne');239 t.ok(false, 'An exception was not raised when connecting an undefined function');240 } catch (e) {241 t.ok(true, 'An exception was raised when connecting an undefined function');242 }243 try {244 disconnect(hasSignals, 'signalOne', nothing);245 t.ok(false, 'An exception was not raised when disconnecting an undefined function');246 } catch (e) {247 t.ok(true, 'An exception was raised when disconnecting an undefined function');248 }249 250 251 try {252 connect(hasSignals, 'signalOne', aObject, aObject.nothing);253 signal(hasSignals, 'signalOne');254 t.ok(false, 'An exception was not raised when connecting an undefined method');255 } catch (e) {256 t.ok(true, 'An exception was raised when connecting an undefined method');257 }258 259 try {260 connect(hasSignals, 'signalOne', aObject, 'nothing');261 signal(hasSignals, 'signalOne');262 t.ok(false, 'An exception was not raised when connecting an undefined method (as string)');263 } catch (e) {264 t.ok(true, 'An exception was raised when connecting an undefined method (as string)');265 }266 t.is(i, 0, 'Signals should not have fired');267 connect(hasSignals, 'signalOne', aFunction);268 connect(hasSignals, 'signalOne', aObject, 'aMethod');269 disconnectAll(hasSignals, 'signalOne');270 signal(hasSignals, 'signalOne');271 t.is(i, 0, 'disconnectAll works with single explicit signal');272 i = 0;273 connect(hasSignals, 'signalOne', aFunction);274 connect(hasSignals, 'signalOne', aObject, 'aMethod');275 connect(hasSignals, 'signalTwo', aFunction);276 connect(hasSignals, 'signalTwo', aObject, 'aMethod');277 disconnectAll(hasSignals, 'signalOne');278 signal(hasSignals, 'signalOne');279 t.is(i, 0, 'disconnectAll works with single explicit signal');280 signal(hasSignals, 'signalTwo');281 t.is(i, 3, 'disconnectAll does not disconnect unrelated signals');282 i = 0;283 connect(hasSignals, 'signalOne', aFunction);284 connect(hasSignals, 'signalOne', aObject, 'aMethod');285 connect(hasSignals, 'signalTwo', aFunction);286 connect(hasSignals, 'signalTwo', aObject, 'aMethod');287 disconnectAll(hasSignals, 'signalOne', 'signalTwo');288 signal(hasSignals, 'signalOne');289 signal(hasSignals, 'signalTwo');290 t.is(i, 0, 'disconnectAll works with two explicit signals');291 i = 0;292 connect(hasSignals, 'signalOne', aFunction);293 connect(hasSignals, 'signalOne', aObject, 'aMethod');294 connect(hasSignals, 'signalTwo', aFunction);295 connect(hasSignals, 'signalTwo', aObject, 'aMethod');296 disconnectAll(hasSignals, ['signalOne', 'signalTwo']);297 signal(hasSignals, 'signalOne');298 signal(hasSignals, 'signalTwo');299 t.is(i, 0, 'disconnectAll works with two explicit signals as a list');300 i = 0;301 connect(hasSignals, 'signalOne', aFunction);302 connect(hasSignals, 'signalOne', aObject, 'aMethod');303 connect(hasSignals, 'signalTwo', aFunction);304 connect(hasSignals, 'signalTwo', aObject, 'aMethod');305 disconnectAll(hasSignals);306 signal(hasSignals, 'signalOne');307 signal(hasSignals, 'signalTwo');308 t.is(i, 0, 'disconnectAll works with implicit signals');309 i = 0;310 311 var toggle = function() {312 disconnectAll(hasSignals, 'signalOne');313 connect(hasSignals, 'signalOne', aFunction);314 i++;315 };316 317 connect(hasSignals, 'signalOne', aFunction);318 connect(hasSignals, 'signalTwo', function() { i++; });319 connect(hasSignals, 'signalTwo', toggle);320 connect(hasSignals, 'signalTwo', function() { i++; }); // #147321 connect(hasSignals, 'signalTwo', function() { i++; });322 signal(hasSignals, 'signalTwo');323 t.is(i, 4, 'disconnectAll fired in a signal loop works');324 i = 0;325 disconnectAll('signalOne');326 disconnectAll('signalTwo');327 var testfunc = function () { arguments.callee.count++; };328 testfunc.count = 0;329 var testObj = {330 methOne: function () { this.countOne++; }, countOne: 0,331 methTwo: function () { this.countTwo++; }, countTwo: 0332 };333 connect(hasSignals, 'signalOne', testfunc);334 connect(hasSignals, 'signalTwo', testfunc);335 signal(hasSignals, 'signalOne');336 signal(hasSignals, 'signalTwo');337 t.is(testfunc.count, 2, 'disconnectAllTo func precondition');338 disconnectAllTo(testfunc);339 signal(hasSignals, 'signalOne');340 signal(hasSignals, 'signalTwo');341 t.is(testfunc.count, 2, 'disconnectAllTo func');342 connect(hasSignals, 'signalOne', testObj, 'methOne');343 connect(hasSignals, 'signalTwo', testObj, 'methTwo');344 signal(hasSignals, 'signalOne');345 signal(hasSignals, 'signalTwo');346 t.is(testObj.countOne, 1, 'disconnectAllTo obj precondition');347 t.is(testObj.countTwo, 1, 'disconnectAllTo obj precondition');348 disconnectAllTo(testObj);349 signal(hasSignals, 'signalOne');350 signal(hasSignals, 'signalTwo');351 t.is(testObj.countOne, 1, 'disconnectAllTo obj');352 t.is(testObj.countTwo, 1, 'disconnectAllTo obj');353 testObj.countOne = testObj.countTwo = 0;354 connect(hasSignals, 'signalOne', testObj, 'methOne');355 connect(hasSignals, 'signalTwo', testObj, 'methTwo');356 disconnectAllTo(testObj, 'methOne');357 signal(hasSignals, 'signalOne');358 signal(hasSignals, 'signalTwo');359 t.is(testObj.countOne, 0, 'disconnectAllTo obj+str');360 t.is(testObj.countTwo, 1, 'disconnectAllTo obj+str');361 362 has__Connect = {363 count: 0,364 __connect__: function (ident) {365 this.count += arguments.length;366 disconnect(ident);367 }368 };369 connect(has__Connect, 'signalOne', aFunction);370 t.is(has__Connect.count, 3, '__connect__ is called when it exists');371 signal(has__Connect, 'signalOne');372 t.is(has__Connect.count, 3, '__connect__ can disconnect the signal');373 var events = {};374 var test_ident = connect(events, "test", function() {375 var fail_ident = connect(events, "fail", function () {376 events.failed = true;377 });378 disconnect(fail_ident);379 signal(events, "fail");380 });381 signal(events, "test");382 t.is(events.failed, undefined, 'disconnected slots do not fire');383 var sink = {f: function (ev) { this.ev = ev; }};384 var src = {};385 bindMethods(sink);386 connect(src, 'signal', sink.f);387 signal(src, 'signal', 'worked');388 t.is(sink.ev, 'worked', 'custom signal does not re-bind methods');389 ...
header.js
Source:header.js
1/*2 backgrid3 http://github.com/wyuenho/backgrid4 Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors5 Licensed under the MIT license.6*/7describe("A HeaderCell", function () {8 var col;9 var cell;10 beforeEach(function () {11 col = new Backbone.Collection([{id: 2}, {id: 1}, {id: 3}]);12 cell = new Backgrid.HeaderCell({13 column: {14 name: "id",15 cell: "integer"16 },17 collection: col18 });19 cell.render();20 });21 it("renders a table header cell with the label text and an optional anchor with sort-caret", function () {22 expect(cell.el.tagName).toBe("TH");23 expect(cell.$el.find("a").text()).toBe("id");24 expect(cell.$el.find(".sort-caret").length).toBe(1);25 cell.column.set("sortable", false);26 cell.render();27 expect(cell.el.tagName).toBe("TH");28 expect(cell.$el.text()).toBe("id");29 expect(cell.$el.find(".sort-caret").length).toBe(0);30 });31 it("adds an editable, sortable and a renderable class to the cell if these column attributes are true", function () {32 var column = {33 name: "title",34 cell: "string"35 };36 cell = new Backgrid.HeaderCell({37 column: column,38 collection: col39 });40 expect(cell.$el.hasClass("editable")).toBe(true);41 expect(cell.$el.hasClass("sortable")).toBe(true);42 expect(cell.$el.hasClass("renderable")).toBe(true);43 cell.column.set("editable", false);44 expect(cell.$el.hasClass("editable")).toBe(false);45 cell.column.set("sortable", false);46 expect(cell.$el.hasClass("sortable")).toBe(false);47 cell.column.set("renderable", false);48 expect(cell.$el.hasClass("renderable")).toBe(false);49 var TrueCol = Backgrid.Column.extend({50 mySortable: function () { return true; },51 myRenderable: function () { return true; },52 myEditable: function () { return true; }53 });54 var FalseCol = Backgrid.Column.extend({55 mySortable: function () { return false; },56 myRenderable: function () { return false; },57 myEditable: function () { return false; }58 });59 column = new TrueCol({60 name: "title",61 cell: "string",62 sortable: "mySortable",63 renderable: "myRenderable",64 editable: "myEditable"65 });66 cell = new Backgrid.HeaderCell({67 column: column,68 collection: col69 });70 expect(cell.$el.hasClass("editable")).toBe(true);71 expect(cell.$el.hasClass("sortable")).toBe(true);72 expect(cell.$el.hasClass("renderable")).toBe(true);73 column = new FalseCol({74 name: "title",75 cell: "string",76 sortable: "mySortable",77 renderable: "myRenderable",78 editable: "myEditable"79 });80 cell = new Backgrid.HeaderCell({81 column: column,82 collection: col83 });84 expect(cell.$el.hasClass("editable")).toBe(false);85 expect(cell.$el.hasClass("sortable")).toBe(false);86 expect(cell.$el.hasClass("renderable")).toBe(false);87 column = new Backgrid.Column({88 name: "title",89 cell: "string",90 sortable: function () { return true; },91 editable: function () { return true; },92 renderable: function () { return true; }93 });94 cell = new Backgrid.HeaderCell({95 column: column,96 collection: col97 });98 expect(cell.$el.hasClass("editable")).toBe(true);99 expect(cell.$el.hasClass("sortable")).toBe(true);100 expect(cell.$el.hasClass("renderable")).toBe(true);101 });102 it("will rerender with the column name and/or label changes", function () {103 expect(cell.$el.find("a").text(), "id");104 expect(cell.$el.hasClass("id"), true);105 cell.column.set("name", "name");106 expect(cell.$el.find("name"), true);107 expect(cell.$el.hasClass("name"), true);108 cell.column.set("label", "Name");109 expect(cell.$el.find("a").text(), "Name");110 expect(cell.$el.hasClass("Name"), true);111 });112 it("will put a class indicating the sorting direction if `direction` is set in the column", function () {113 cell = new Backgrid.HeaderCell({114 column: {115 name: "id",116 cell: "integer",117 direction: "descending"118 },119 collection: col120 });121 cell.render();122 expect(cell.el.tagName).toBe("TH");123 expect(cell.$el.find("a").text()).toBe("id");124 expect(cell.$el.find(".sort-caret").length).toBe(1);125 expect(cell.$el.hasClass("descending")).toBe(true);126 });127 it("triggers `backgrid:sort` with the column and direction set to 'ascending' if the column's direction is not set", function () {128 var column, direction;129 cell.collection.on("backgrid:sort", function (col, dir) { column = col; direction = dir; });130 cell.$el.find("a").click();131 expect(column).toBe(cell.column);132 expect(direction).toBe("ascending");133 });134 it("triggers `backgrid:sort` with the column and direction set to 'descending' if the column's direction is set to 'ascending'", function () {135 var column, direction;136 cell.collection.on("backgrid:sort", function (col, dir) { column = col; direction = dir; });137 cell.column.set("direction", "ascending");138 cell.$el.find("a").click();139 expect(column).toBe(cell.column);140 expect(direction).toBe("descending");141 });142 it("triggers `backgrid:sort` with the column and direction set to `null` if the column's direction is set to 'descending'", function () {143 var column, direction;144 cell.collection.on("backgrid:sort", function (col, dir) { column = col; direction = dir; });145 cell.column.set("direction", "descending");146 cell.$el.find("a").click();147 expect(column).toBe(cell.column);148 expect(direction).toBeNull();149 });150 it("will set the column to the correct direction when `change:direction` is triggered from the column", function () {151 cell.column.set("direction", "ascending");152 expect(cell.$el.hasClass("ascending")).toBe(true);153 cell.column.set("direction", "descending");154 expect(cell.$el.hasClass("descending")).toBe(true);155 cell.column.set("direction", null);156 expect(cell.$el.hasClass("ascending")).toBe(false);157 expect(cell.$el.hasClass("descending")).toBe(false);158 });159 it("will remove its direction CSS class if `sort` is triggered from the collection or pageableCollection#fullCollection", function () {160 cell.column.set("direction", "ascending");161 cell.collection.comparator = "id";162 cell.collection.sort();163 expect(cell.$el.hasClass("ascending")).toBe(false);164 expect(cell.$el.hasClass("descending")).toBe(false);165 col = new Backbone.PageableCollection(col.toJSON(), {166 mode: "client"167 });168 col.setSorting("id", 1);169 cell = new Backgrid.HeaderCell({170 column: {171 name: "id",172 cell: "integer"173 },174 collection: col175 });176 cell.column.set("direction", "ascending");177 cell.collection.fullCollection.comparator = "id";178 cell.collection.fullCollection.sort();179 expect(cell.$el.hasClass("ascending")).toBe(false);180 expect(cell.$el.hasClass("descending")).toBe(false);181 });182 it("with `sortType` set to `toggle`, triggers `backgrid:sort` with the column and direction set to 'ascending' if the column's direction is not set", function () {183 var column, direction;184 cell.column.set("sortType", "toggle");185 cell.collection.on("backgrid:sort", function (col, dir) { column = col; direction = dir; });186 cell.$el.find("a").click();187 expect(column).toBe(cell.column);188 expect(direction).toBe("ascending");189 });190 it("with `sortType` set to `toggle`, triggers `backgrid:sort` with the column and direction set to 'descending' if the column's direction is set to 'ascending'", function () {191 var column, direction;192 cell.column.set("sortType", "toggle");193 cell.column.set("direction", "ascending");194 cell.collection.on("backgrid:sort", function (col, dir) { column = col; direction = dir; });195 cell.$el.find("a").click();196 expect(column).toBe(cell.column);197 expect(direction).toBe("descending");198 });199 it("with `sortType` set to `toggle`, triggers `backgrid:sort` with the column and direction set to 'ascending' if the column's direction is set to 'descending'", function () {200 var column, direction;201 cell.column.set("sortType", "toggle");202 cell.column.set("direction", "descending");203 cell.collection.on("backgrid:sort", function (col, dir) { column = col; direction = dir; });204 cell.$el.find("a").click();205 expect(column).toBe(cell.column);206 expect(direction).toBe("ascending");207 });208});209describe("A HeaderRow", function () {210 var Book = Backbone.Model.extend({});211 var Books = Backbone.Collection.extend({212 model: Book213 });214 var books;215 var row;216 beforeEach(function () {217 books = new Books([{218 title: "Alice's Adventures in Wonderland",219 year: 1865220 }, {221 title: "A Tale of Two Cities",222 year: 1859223 }, {224 title: "The Catcher in the Rye",225 year: 1951226 }]);227 row = new Backgrid.HeaderRow({228 columns: [{229 name: "name",230 cell: "string"231 }, {232 name: "year",233 cell: "integer"234 }],235 collection: books236 });237 row.render();238 });239 it("renders a row of header cells", function () {240 expect(row.$el[0].tagName).toBe("TR");241 var th1 = $(row.el.childNodes[0]);242 expect(th1.hasClass("editable")).toBe(true);243 expect(th1.hasClass("sortable")).toBe(true);244 expect(th1.hasClass("renderable")).toBe(true);245 expect(th1.hasClass("name")).toBe(true);246 expect(th1.find("a").text()).toBe("name");247 expect(th1.find("a").eq(1).is($("b", {className: "sort-caret"})));248 var th2 = $(row.el.childNodes[1]);249 expect(th2.hasClass("editable")).toBe(true);250 expect(th2.hasClass("sortable")).toBe(true);251 expect(th2.hasClass("renderable")).toBe(true);252 expect(th2.hasClass("year")).toBe(true);253 expect(th2.find("a").text()).toBe("year");254 expect(th2.find("a > b:last-child").eq(0).hasClass("sort-caret")).toBe(true);255 });256 it("resets the carets of the non-sorting columns", function () {257 row.$el.find("a").eq(0).click(); // ascending258 row.$el.find("a").eq(1).click(); // ascending, resets the previous259 expect(row.$el.find("a").eq(0).hasClass("ascending")).toBe(false);260 expect(row.$el.find("a").eq(1).hasClass("ascending")).toBe(false);261 });262 it("inserts or removes a cell if a column is added or removed", function () {263 row.columns.add({name: "price", cell: "number"});264 expect(row.$el.children().length).toBe(3);265 var lastTh = $(row.el.lastChild);266 expect(lastTh.hasClass("editable")).toBe(true);267 expect(lastTh.hasClass("sortable")).toBe(true);268 expect(lastTh.hasClass("renderable")).toBe(true);269 expect(lastTh.hasClass("price")).toBe(true);270 expect(lastTh.find("a").text()).toBe("price");271 expect(lastTh.find("a > b:last-child").eq(0).hasClass("sort-caret")).toBe(true);272 row.columns.add({name: "publisher", cell: "string", renderable: false});273 expect(row.$el.children().length).toBe(4);274 expect(row.$el.children().last().find("a").text()).toBe("publisher");275 expect(row.$el.children().last().hasClass("renderable")).toBe(false);276 row.columns.remove(row.columns.first());277 expect(row.$el.children().length).toBe(3);278 var firstTh = $(row.el.firstChild);279 expect(firstTh.hasClass("editable")).toBe(true);280 expect(firstTh.hasClass("sortable")).toBe(true);281 expect(firstTh.hasClass("renderable")).toBe(true);282 expect(firstTh.hasClass("year")).toBe(true);283 expect(firstTh.find("a").text()).toBe("year");284 expect(firstTh.find("a > b:last-child").eq(0).hasClass("sort-caret")).toBe(true);285 });286});287describe("A Header", function () {288 var Book = Backbone.Model.extend({});289 var Books = Backbone.Collection.extend({290 model: Book291 });292 var books;293 var head;294 beforeEach(function () {295 books = new Books([{296 title: "Alice's Adventures in Wonderland",297 year: 1865298 }, {299 title: "A Tale of Two Cities",300 year: 1859301 }, {302 title: "The Catcher in the Rye",303 year: 1951304 }]);305 head = new Backgrid.Header({306 columns: [{307 name: "name",308 cell: "string"309 }, {310 name: "year",311 cell: "integer"312 }],313 collection: books314 });315 head.render();316 });317 it("renders a header with a row of header cells", function () {318 expect(head.$el[0].tagName).toBe("THEAD");319 var th1 = $(head.row.el.childNodes[0]);320 expect(th1.hasClass("editable")).toBe(true);321 expect(th1.hasClass("sortable")).toBe(true);322 expect(th1.hasClass("renderable")).toBe(true);323 expect(th1.hasClass("name")).toBe(true);324 expect(th1.find("a").text()).toBe("name");325 expect(th1.find("a").eq(1).is($("b", {className: "sort-caret"})));326 var th2 = $(head.row.el.childNodes[1]);327 expect(th2.hasClass("editable")).toBe(true);328 expect(th2.hasClass("sortable")).toBe(true);329 expect(th2.hasClass("renderable")).toBe(true);330 expect(th2.hasClass("year")).toBe(true);331 expect(th2.find("a").text()).toBe("year");332 expect(th2.find("a > b:last-child").eq(0).hasClass("sort-caret")).toBe(true);333 });...
has.js.uncompressed.js
Source:has.js.uncompressed.js
...75 // | // el == the generic element. a `has` element.76 // | return false; // fake test, byid-when-form-has-name-matching-an-id is slightly longer77 // | });78 (typeof cache[name]=="undefined" || force) && (cache[name]= test);79 return now && has(name);80 };81 // since we're operating under a loader that doesn't provide a has API, we must explicitly initialize82 // has as it would have otherwise been initialized by the dojo loader; use has.add to the builder83 // can optimize these away iff desired84 1 || has.add("host-browser", isBrowser);85 0 && has.add("host-node", (typeof process == "object" && process.versions && process.versions.node && process.versions.v8));86 0 && has.add("host-rhino", (typeof load == "function" && (typeof Packages == "function" || typeof Packages == "object")));87 1 || has.add("dom", isBrowser);88 1 || has.add("dojo-dom-ready-api", 1);89 1 || has.add("dojo-sniff", 1);90 }91 if( 1 ){92 // Common application level tests93 has.add("dom-addeventlistener", !!document.addEventListener);94 // Do the device and browser have touch capability?95 has.add("touch", "ontouchstart" in document96 || ("onpointerdown" in document && navigator.maxTouchPoints > 0)97 || window.navigator.msMaxTouchPoints);98 // Touch events support99 has.add("touch-events", "ontouchstart" in document);100 // Pointer Events support101 has.add("pointer-events", "onpointerdown" in document);102 has.add("MSPointer", "msMaxTouchPoints" in navigator); //IE10 (+IE11 preview)103 // I don't know if any of these tests are really correct, just a rough guess104 has.add("device-width", screen.availWidth || innerWidth);105 // Tests for DOMNode.attributes[] behavior:106 // - dom-attributes-explicit - attributes[] only lists explicitly user specified attributes107 // - dom-attributes-specified-flag (IE8) - need to check attr.specified flag to skip attributes user didn't specify108 // - Otherwise, in IE6-7. attributes[] will list hundreds of values, so need to do outerHTML to get attrs instead.109 var form = document.createElement("form");110 has.add("dom-attributes-explicit", form.attributes.length == 0); // W3C111 has.add("dom-attributes-specified-flag", form.attributes.length > 0 && form.attributes.length < 40); // IE8112 }113 has.clearElement = function(element){114 // summary:115 // Deletes the contents of the element passed to test functions.116 element.innerHTML= "";117 return element;118 };119 has.normalize = function(id, toAbsMid){120 // summary:121 // Resolves id into a module id based on possibly-nested tenary expression that branches on has feature test value(s).122 //123 // toAbsMid: Function124 // Resolves a relative module id into an absolute module id125 var126 tokens = id.match(/[\?:]|[^:\?]*/g), i = 0,127 get = function(skip){128 var term = tokens[i++];129 if(term == ":"){130 // empty string module name, resolves to 0131 return 0;132 }else{133 // postfixed with a ? means it is a feature to branch on, the term is the name of the feature134 if(tokens[i++] == "?"){135 if(!skip && has(term)){136 // matched the feature, get the first value from the options137 return get();138 }else{139 // did not match, get the second value, passing over the first140 get(true);141 return get(skip);142 }143 }144 // a module145 return term || 0;146 }147 };148 id = get();149 return id && toAbsMid(id);...
weeks_in_year.js
Source:weeks_in_year.js
1import { module, test } from '../qunit';2import moment from '../../moment';3module('weeks in year');4test('isoWeeksInYear', function (assert) {5 assert.equal(moment([2004]).isoWeeksInYear(), 53, '2004 has 53 iso weeks');6 assert.equal(moment([2005]).isoWeeksInYear(), 52, '2005 has 53 iso weeks');7 assert.equal(moment([2006]).isoWeeksInYear(), 52, '2006 has 53 iso weeks');8 assert.equal(moment([2007]).isoWeeksInYear(), 52, '2007 has 52 iso weeks');9 assert.equal(moment([2008]).isoWeeksInYear(), 52, '2008 has 53 iso weeks');10 assert.equal(moment([2009]).isoWeeksInYear(), 53, '2009 has 53 iso weeks');11 assert.equal(moment([2010]).isoWeeksInYear(), 52, '2010 has 52 iso weeks');12 assert.equal(moment([2011]).isoWeeksInYear(), 52, '2011 has 52 iso weeks');13 assert.equal(moment([2012]).isoWeeksInYear(), 52, '2012 has 52 iso weeks');14 assert.equal(moment([2013]).isoWeeksInYear(), 52, '2013 has 52 iso weeks');15 assert.equal(moment([2014]).isoWeeksInYear(), 52, '2014 has 52 iso weeks');16 assert.equal(moment([2015]).isoWeeksInYear(), 53, '2015 has 53 iso weeks');17});18test('weeksInYear doy/dow = 1/4', function (assert) {19 moment.locale('1/4', {week: {dow: 1, doy: 4}});20 assert.equal(moment([2004]).weeksInYear(), 53, '2004 has 53 weeks');21 assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks');22 assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks');23 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');24 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');25 assert.equal(moment([2009]).weeksInYear(), 53, '2009 has 53 weeks');26 assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks');27 assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks');28 assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks');29 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');30 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');31 assert.equal(moment([2015]).weeksInYear(), 53, '2015 has 53 weeks');32});33test('weeksInYear doy/dow = 6/12', function (assert) {34 moment.locale('6/12', {week: {dow: 6, doy: 12}});35 assert.equal(moment([2004]).weeksInYear(), 53, '2004 has 53 weeks');36 assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks');37 assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks');38 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');39 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');40 assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks');41 assert.equal(moment([2010]).weeksInYear(), 53, '2010 has 52 weeks');42 assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks');43 assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks');44 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');45 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');46 assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks');47});48test('weeksInYear doy/dow = 1/7', function (assert) {49 moment.locale('1/7', {week: {dow: 1, doy: 7}});50 assert.equal(moment([2004]).weeksInYear(), 52, '2004 has 53 weeks');51 assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks');52 assert.equal(moment([2006]).weeksInYear(), 53, '2006 has 53 weeks');53 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');54 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');55 assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks');56 assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks');57 assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks');58 assert.equal(moment([2012]).weeksInYear(), 53, '2012 has 52 weeks');59 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');60 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');61 assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks');62});63test('weeksInYear doy/dow = 0/6', function (assert) {64 moment.locale('0/6', {week: {dow: 0, doy: 6}});65 assert.equal(moment([2004]).weeksInYear(), 52, '2004 has 53 weeks');66 assert.equal(moment([2005]).weeksInYear(), 53, '2005 has 53 weeks');67 assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks');68 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');69 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');70 assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks');71 assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks');72 assert.equal(moment([2011]).weeksInYear(), 53, '2011 has 52 weeks');73 assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks');74 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');75 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');76 assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks');...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!