-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): add tests for modules - card-list, cards, dates
- Loading branch information
Showing
5 changed files
with
598 additions
and
89 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* OpenSprinkler App | ||
* Copyright (C) 2015 - present, Samer Albahra. All rights reserved. | ||
* | ||
* This file is part of the OpenSprinkler project <http://opensprinkler.com>. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* global describe, beforeEach, OSApp, assert */ | ||
|
||
describe('OSApp.CardList', function() { | ||
var cardList; | ||
|
||
beforeEach(function() { | ||
// Mock the card list using jQuery to create a set of dummy cards | ||
cardList = $("<div class='card' data-station='A'></div>" + | ||
"<div class='card' data-station='B'></div>" + | ||
"<div class='card' data-station='C'></div>"); | ||
}); | ||
|
||
describe('getAllCards', function() { | ||
it('should return all elements with the class "card"', function() { | ||
var cards = OSApp.CardList.getAllCards(cardList); | ||
assert.equal(cards.length, 3); | ||
}); | ||
|
||
it('should return an empty jQuery object if no cards are found', function() { | ||
cardList = $("<div></div>"); // No .card elements | ||
var cards = OSApp.CardList.getAllCards(cardList); | ||
assert.equal(cards.length, 0); | ||
}); | ||
}); | ||
|
||
describe('getCardBySID', function() { | ||
it('should return the card with the specified SID', function() { | ||
var card = OSApp.CardList.getCardBySID(cardList, 'B'); | ||
assert.equal(card.length, 1); | ||
assert.equal(card.data('station'), 'B'); | ||
}); | ||
|
||
it('should return an empty jQuery object if no card with the SID is found', function() { | ||
var card = OSApp.CardList.getCardBySID(cardList, 'Z'); | ||
assert.equal(card.length, 0); | ||
}); | ||
}); | ||
|
||
describe('getCardByIndex', function() { | ||
it('should return the card at the specified index', function() { | ||
// Skipping this test for now since it uses jQuery internally | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
|
||
|
||
/* OpenSprinkler App | ||
* Copyright (C) 2015 - present, Samer Albahra. All rights reserved. | ||
* | ||
* This file is part of the OpenSprinkler project <http://opensprinkler.com>. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
describe('OSApp.Cards', function() { | ||
var cardObj; | ||
|
||
beforeEach(function() { | ||
cardObj = $("<div class='card' data-station='A'>" + | ||
"<div><span></span><span data-gid='1'></span></div>" + | ||
"<div class='content-divider'></div>" + | ||
"<div class='station-gid'></div>" + | ||
"</div>"); | ||
|
||
// Store original values | ||
originalSupported = OSApp.Supported; | ||
originalStations = OSApp.Stations; | ||
|
||
// Mock dependencies | ||
OSApp.Supported = { groups: function() { return true; } }; | ||
OSApp.Groups = { mapGIDValueToName: function(gid) { | ||
return 'Group ' + gid; | ||
} | ||
}; | ||
OSApp.Stations = { | ||
getGIDValue: function(sid) { | ||
return 1; | ||
}, | ||
isMaster: function(sid) { | ||
return sid === 'A'; | ||
} | ||
}; | ||
}); | ||
|
||
afterEach(function() { | ||
// Restore original values | ||
OSApp.Supported = originalSupported; | ||
OSApp.Stations = originalStations; | ||
}); | ||
|
||
describe('getSID', function() { | ||
it('should return the station ID', function() { | ||
var sid = OSApp.Cards.getSID(cardObj); | ||
assert.equal(sid, 'A'); | ||
}); | ||
}); | ||
|
||
describe('getDivider', function() { | ||
it('should return the divider element', function() { | ||
var divider = OSApp.Cards.getDivider(cardObj); | ||
assert.equal(divider.hasClass('content-divider'), true); | ||
}); | ||
}); | ||
|
||
describe('getGroupLabel', function() { | ||
it('should return the group label (groups supported)', function() { | ||
var groupLabel = OSApp.Cards.getGroupLabel(cardObj); | ||
assert.equal(groupLabel.hasClass('station-gid'), true); | ||
}); | ||
|
||
it('should return undefined (groups not supported)', function() { | ||
OSApp.Supported.groups = function() { return false; }; | ||
var groupLabel = OSApp.Cards.getGroupLabel(cardObj); | ||
assert.equal(groupLabel, undefined); | ||
}); | ||
}); | ||
|
||
describe('setGroupLabel', function() { | ||
it('should set group label text (groups supported)', function() { | ||
OSApp.Cards.setGroupLabel(cardObj, 'Group 1'); | ||
var groupLabel = OSApp.Cards.getGroupLabel(cardObj); | ||
assert.equal(groupLabel.text(), 'Group 1'); | ||
assert.equal(groupLabel.hasClass('hidden'), false); | ||
}); | ||
|
||
it('should do nothing (groups not supported)', function() { | ||
OSApp.Supported.groups = function() { return false; }; | ||
var groupLabelBefore = OSApp.Cards.getGroupLabel(cardObj); | ||
OSApp.Cards.setGroupLabel(cardObj, 'Group 1'); | ||
var groupLabelAfter = OSApp.Cards.getGroupLabel(cardObj); | ||
assert.equal(groupLabelBefore, groupLabelAfter); | ||
}); | ||
}); | ||
|
||
describe('getGIDValue', function() { | ||
it('should return the GID value', function() { | ||
var gid = OSApp.Cards.getGIDValue(cardObj); | ||
assert.equal(gid, 1); | ||
}); | ||
|
||
it('should return 0 (groups not supported)', function() { | ||
OSApp.Supported.groups = function() { return false; }; | ||
var gid = OSApp.Cards.getGIDValue(cardObj); | ||
assert.equal(gid, 0); | ||
}); | ||
}); | ||
|
||
describe('getGIDName', function() { | ||
it('should return the GID name', function() { | ||
var gidName = OSApp.Cards.getGIDName(cardObj); | ||
assert.equal(gidName, 'Group 1'); | ||
}); | ||
}); | ||
|
||
describe('isMasterStation', function() { | ||
it('should return true for master station', function() { | ||
var isMaster = OSApp.Cards.isMasterStation(cardObj); | ||
assert.equal(isMaster, true); | ||
}); | ||
|
||
it('should return false for non-master station', function() { | ||
cardObj.data('station', 'B'); | ||
var isMaster = OSApp.Cards.isMasterStation(cardObj); | ||
assert.equal(isMaster, false); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.