added jquery lib natively. Note: would be better to use git submodules.

This commit is contained in:
root
2022-12-21 12:44:27 +01:00
parent 9ddc28c0a0
commit c057d3b3a6
11 changed files with 2426 additions and 0 deletions

View File

@@ -0,0 +1,509 @@
(function ($) {
module('general');
//Creates a very simple map and returns map's container.
function simpleMapSetup(params) {
var $fixture = $('#qunit-fixture'),
$div = $('<div id="seat-map">');
$fixture.append($div);
$div.seatCharts(
$.extend(true, {}, {
map: [
'aa_aa',
'bbbbb',
'bbbbb'
],
seats: {
a: {
classes : 'a1-seat-class a2-seat-class'
},
b: {
classes : ['b1-seat-class', 'b2-seat-class']
}
}
}, params)
);
return $div;
}
function Counter() {
this.click = 0;
this.focus = 0;
this.blur = 0;
this.reset = function () {
this.click = this.focus = this.blur = 0;
};
}
test('Testing general structure of a simple map.', function () {
expect(5);
var $seatCharts = simpleMapSetup(),
$space = $seatCharts.find('.seatCharts-row:eq(1) .seatCharts-cell:eq(3)');
equal($seatCharts.find('.seatCharts-row').length, 4, 'Number of rows.');
ok($space.hasClass('seatCharts-space') && !$space.hasClass('seatCharts-seat'), 'There should be a spacer cell in the first row.')
equal($seatCharts.find('.seatCharts-row:eq(1) .seatCharts-seat').length, 4, 'Number of columns in row 1.');
for (var i = 2; i <= 3; i += 1) {
equal($seatCharts.find('.seatCharts-row:eq('+(i)+') .seatCharts-seat').length, 5, 'Number of columns in row '+i+'.');
}
});
test('Testing seat classes', function () {
expect(6);
var $seatCharts = simpleMapSetup(),
$aSeat = $seatCharts.find('.seatCharts-row:eq(1) .seatCharts-seat:eq(0)'),
$bSeat = $seatCharts.find('.seatCharts-row:eq(2) .seatCharts-seat:eq(3)');
ok($aSeat.hasClass('a1-seat-class'), 'Seat a has its a1-seat-class assigned using a string.');
ok($aSeat.hasClass('a2-seat-class'), 'Seat a has its a2-seat-class assigned using a string.');
ok($bSeat.hasClass('b1-seat-class'), 'Seat b has its b1-seat-class assigned using an array.');
ok($bSeat.hasClass('b2-seat-class'), 'Seat b has its b2-seat-class assigned using an array.');
ok(!($aSeat.hasClass('b1-seat-class') || $aSeat.hasClass('b2-seat-class')), 'Seat a does not have any b seat classes.');
ok(!($bSeat.hasClass('a1-seat-class') || $bSeat.hasClass('a2-seat-class')), 'Seat b does not have any a seat classes.');
});
test('Testing default column & row labels', function () {
expect(9);
var $seatCharts = simpleMapSetup();
equal($seatCharts.find('.seatCharts-row:eq(0) .seatCharts-cell:eq(0)').text(), '', 'Top leftmost cell should be empty.');
for (var i = 1; i <= 5; i += 1) {
equal($seatCharts.find('.seatCharts-row:eq(0) .seatCharts-cell:eq('+i+')').text(), i, 'Column header '+i+' has correct label.');
}
for (var i = 1; i <= 3; i += 1) {
equal($seatCharts.find('.seatCharts-row:eq('+i+') .seatCharts-cell:eq(0)').text(), i, 'Row header '+i+' has correct label.');
}
});
test('Testing custom column & row labels', function () {
expect(3);
var $seatCharts = simpleMapSetup({
naming : {
columns : ['I', 'II', 'III', 'IV', 'V'],
rows : ['a', 'b', 'c']
}
});
equal($seatCharts.find('.seatCharts-row:eq(0) .seatCharts-cell:eq(0)').text(), '', 'Top leftmost cell should be empty.');
equal($seatCharts.find('.seatCharts-row:eq(0) .seatCharts-cell:eq(3)').text(), 'III', '3rd column header has correct label.');
equal($seatCharts.find('.seatCharts-row:eq(2) .seatCharts-cell:eq(0)').text(), 'b', '2nd row header has correct label.');
});
test('Testing default seat labels and IDs', function () {
expect(4);
var $seatCharts = simpleMapSetup();
equal($seatCharts.find('.seatCharts-row:eq(1) .seatCharts-seat:eq(0)').text(), '1', 'First seat in the first row label.');
equal($seatCharts.find('.seatCharts-row:eq(1) .seatCharts-seat:eq(2)').text(), '4', 'Third seat in the first row label.');
equal($seatCharts.find('#3_5').length, 1, 'Seat with id 3_5 exists.');
equal($seatCharts.find('#3_6').length, 0, 'And it is the last seat id.');
});
test('Testing custom seat labels and IDs', function () {
expect(4);
var getIdExecutions = 0,
getLabelExecutions = 0,
$seatCharts = simpleMapSetup({
naming : {
getId : function (character, row, column) {
getIdExecutions += 1
//return all arguments separated with -
return [].slice.call(arguments).join('-');
},
getLabel : function (character, row, column) {
getLabelExecutions += 1;
//return all arguments separated with +
return [].slice.call(arguments).join('+');
}
}
});
equal(getIdExecutions, 14, 'getId has been called for each seat.');
equal(getLabelExecutions, 14, 'getLabel has been called for each seat.');
equal($seatCharts.find('.seatCharts-row:eq(1) .seatCharts-seat:eq(2)').text(), 'a+1+4', 'Correct label assigned.');
equal($seatCharts.find('.seatCharts-row:eq(3) .seatCharts-seat:eq(4)').attr('id'), 'b-3-5', 'Correct id assigned.');
});
test('Testing overriding labels and IDs', function () {
expect(10);
var $seatCharts = simpleMapSetup({
map: [
'a[1_A1,A1]a[1_A2,A2]_aa',
'bbbbb',
'bb[3_B2]bbb[,B5]'
]
}),
//a[1_A1,A1]
$seat1 = $seatCharts.find('.seatCharts-row:eq(1) .seatCharts-seat:eq(0)'),
//a[1_A2,A2]
$seat2 = $seatCharts.find('.seatCharts-row:eq(1) .seatCharts-seat:eq(1)'),
//a
$seat3 = $seatCharts.find('.seatCharts-row:eq(1) .seatCharts-seat:eq(2)'),
//b[3_B2]
$seat4 = $seatCharts.find('.seatCharts-row:eq(3) .seatCharts-seat:eq(1)'),
//b[,B5]
$seat5 = $seatCharts.find('.seatCharts-row:eq(3) .seatCharts-seat:eq(4)');
equal($seat1.text(), 'A1', 'Seat 1 has correct label assigned.');
equal($seat1.attr('id'), '1_A1', 'Seat 1 has correct id assigned.');
equal($seat2.text(), 'A2', 'Seat 2 has correct label assigned.');
equal($seat2.attr('id'), '1_A2', 'Seat 2 has correct id assigned.');
equal($seat3.text(), '4', 'Seat 3 has correct label assigned.');
equal($seat3.attr('id'), '1_4', 'Seat 3 has correct id assigned.');
equal($seat4.text(), '2', 'Seat 4 has correct label assigned.');
equal($seat4.attr('id'), '3_B2', 'Seat 4 has correct id assigned.');
equal($seat5.text(), 'B5', 'Seat 5 has correct label assigned.');
equal($seat5.attr('id'), '3_5', 'Seat 5 has correct id assigned.');
});
test('Testing overriding+custom labels and IDs', function () {
expect(12);
var getIdExecutions = 0,
getLabelExecutions = 0,
$seatCharts = simpleMapSetup({
naming : {
getId : function (character, row, column) {
getIdExecutions += 1
//return all arguments separated with -
return [].slice.call(arguments).join('-');
},
getLabel : function (character, row, column) {
getLabelExecutions += 1;
//return all arguments separated with +
return [].slice.call(arguments).join('+');
}
},
map: [
'a[1_A1,A1]a[1_A2,A2]_aa',
'bbbbb',
'bb[3_B2]bbb[,B5]'
]
}),
//a[1_A1,A1]
$seat1 = $seatCharts.find('.seatCharts-row:eq(1) .seatCharts-seat:eq(0)'),
//a[1_A2,A2]
$seat2 = $seatCharts.find('.seatCharts-row:eq(1) .seatCharts-seat:eq(1)'),
//a
$seat3 = $seatCharts.find('.seatCharts-row:eq(1) .seatCharts-seat:eq(2)'),
//b[3_B2]
$seat4 = $seatCharts.find('.seatCharts-row:eq(3) .seatCharts-seat:eq(1)'),
//b[,B5]
$seat5 = $seatCharts.find('.seatCharts-row:eq(3) .seatCharts-seat:eq(4)');
equal(getIdExecutions, 11, 'getId has been called for each seat.');
equal(getLabelExecutions, 11, 'getLabel has been called for each seat.');
equal($seat1.text(), 'A1', 'Seat 1 has correct label assigned.');
equal($seat1.attr('id'), '1_A1', 'Seat 1 has correct id assigned.');
equal($seat2.text(), 'A2', 'Seat 2 has correct label assigned.');
equal($seat2.attr('id'), '1_A2', 'Seat 2 has correct id assigned.');
equal($seat3.text(), 'a+1+4', 'Seat 3 has correct label assigned.');
equal($seat3.attr('id'), 'a-1-4', 'Seat 3 has correct id assigned.');
equal($seat4.text(), 'b+3+2', 'Seat 4 has correct label assigned.');
equal($seat4.attr('id'), '3_B2', 'Seat 4 has correct id assigned.');
equal($seat5.text(), 'B5', 'Seat 5 has correct label assigned.');
equal($seat5.attr('id'), 'b-3-5', 'Seat 5 has correct id assigned.');
});
test('Testing disabled left & top containers for labels', function () {
var $seatCharts = simpleMapSetup({
naming : {
top: false,
left: false
}
});
ok($seatCharts.find('.seatCharts-row:eq(0) .seatCharts-cell:eq(0)').hasClass('seatCharts-seat'), 'Top leftmost cell should contain a seat.');
})
test('Testing legend with container specified', function () {
expect(4);
var $fixture = $('#qunit-fixture'),
$legend = $('<div>').appendTo($fixture),
$seatCharts = simpleMapSetup({
legend : {
node : $legend,
items : [
['a', 'available', 'A seat when available'],
['b', 'available', 'B seat when available'],
['a', 'unavailable', 'A seat when unavailable'],
['b', 'unavailable', 'B seat when unavailable']
]
}
}),
$item,
$seat;
ok($legend.hasClass('seatCharts-legend'), 'Legend class has been assigned to the container');
equal($legend.find('ul.seatCharts-legendList li.seatCharts-legendItem').length, 4, 'There is a list of 4 legend items.');
$item = $legend.find('.seatCharts-legendItem:eq(0)');
$seat = $item.find('div:first');
ok($seat.hasClass('seatCharts-seat') && $seat.hasClass('seatCharts-cell') && $seat.hasClass('available') && $seat.hasClass('a1-seat-class') && $seat.hasClass('a2-seat-class'), 'The first legend item has correct classes assigned.');
equal($item.find('.seatCharts-legendDescription').text(), 'A seat when available', 'The first item has correct label assigned.');
});
test('Testing legend without container specified', function () {
expect(4);
var $fixture = $('#qunit-fixture'),
$seatCharts = simpleMapSetup({
legend : {
items : [
['a', 'available', 'A seat when available'],
['b', 'available', 'B seat when available'],
['a', 'unavailable', 'A seat when unavailable'],
['b', 'unavailable', 'B seat when unavailable']
]
}
}),
$legend,
$item,
$seat;
equal($('div.seatCharts-legend').length, 1, 'Legend div has been created.');
$legend = $('div.seatCharts-legend:eq(0)');
equal($legend.find('ul.seatCharts-legendList li.seatCharts-legendItem').length, 4, 'There is a list of 4 legend items.');
$item = $legend.find('.seatCharts-legendItem:eq(0)');
$seat = $item.find('div:first');
ok($seat.hasClass('seatCharts-seat') && $seat.hasClass('seatCharts-cell') && $seat.hasClass('available') && $seat.hasClass('a1-seat-class') && $seat.hasClass('a2-seat-class'), 'The first legend item has correct classes assigned.');
equal($item.find('.seatCharts-legendDescription').text(), 'A seat when available', 'The first item has correct label assigned.');
});
test('Testing map-level callbacks', function () {
var $seatCharts = simpleMapSetup({
click : function () {
executions.click += 1;
if (this.status() == 'available') {
return 'selected';
} else if (this.status() == 'selected') {
return 'available';
} else {
return this.style();
}
},
focus : function() {
executions.focus += 1;
if (this.status() == 'available') {
return 'focused';
} else {
return this.style();
}
},
blur : function() {
executions.blur += 1;
return this.status();
}
}),
seatCharts = $seatCharts.seatCharts(),
//simple counter object
executions = new Counter,
clickEvent = $.Event('click'),
mouseenterEvent = $.Event('mouseenter'),
mouseleaveEvent = $.Event('mouseleave'),
focusEvent = $.Event('focus'),
keyEvent = $.Event('keydown');
seatCharts.get('2_3').status('unavailable');
seatCharts.get('2_1').node().trigger(mouseenterEvent);
seatCharts.get('2_1').node().trigger(mouseleaveEvent);
seatCharts.get('2_2').node().trigger(mouseenterEvent);
seatCharts.get('2_2').node().trigger(mouseleaveEvent);
seatCharts.get('2_3').node().trigger(mouseenterEvent);
propEqual(executions, {
click : 0,
focus : 3,
blur : 4,
reset : function () {}
}, 'Blur and focus are correctly triggered.');
//start over
executions.reset();
seatCharts.get('3_1').node().trigger(mouseenterEvent);
//arrow down
keyEvent.which = 38;
seatCharts.get('3_1').node().trigger(keyEvent);
//spacebar
keyEvent.which = 32;
seatCharts.get('2_1').node().trigger(keyEvent);
propEqual(executions, {
click : 1,
focus : 2,
blur : 3,
reset : function () {}
}, 'Blur, focus and click are correctly triggered.');
});
test('Testing seat-level callbacks', function () {
var $seatCharts = simpleMapSetup({
seats : {
a : {
click : function () {
executionsA.click += 1;
if (this.status() == 'available') {
return 'selected';
} else if (this.status() == 'selected') {
return 'available';
} else {
return this.style();
}
},
focus : function() {
executionsA.focus += 1;
if (this.status() == 'available') {
return 'focused';
} else {
return this.style();
}
},
blur : function() {
executionsA.blur += 1;
return this.status();
}
},
b : {
click : function () {
executionsB.click += 1;
if (this.status() == 'available') {
return 'selected';
} else if (this.status() == 'selected') {
return 'available';
} else {
return this.style();
}
},
focus : function() {
executionsB.focus += 1;
if (this.status() == 'available') {
return 'focused';
} else {
return this.style();
}
},
blur : function() {
executionsB.blur += 1;
return this.status();
}
}
}
}),
seatCharts = $seatCharts.seatCharts(),
//each seat type has its own callbacks and hence different counters
executionsA = new Counter,
executionsB = new Counter,
clickEvent = $.Event('click'),
mouseenterEvent = $.Event('mouseenter'),
mouseleaveEvent = $.Event('mouseleave'),
focusEvent = $.Event('focus'),
keyEvent = $.Event('keydown');
seatCharts.get('2_3').status('unavailable');
seatCharts.get('2_1').node().trigger(mouseenterEvent);
seatCharts.get('2_1').node().trigger(mouseleaveEvent);
seatCharts.get('2_2').node().trigger(mouseenterEvent);
seatCharts.get('2_2').node().trigger(mouseleaveEvent);
seatCharts.get('2_3').node().trigger(mouseenterEvent);
propEqual(executionsB, {
click : 0,
focus : 3,
blur : 4,
reset : function () {}
}, 'Blur, focus and click are correctly triggered for B seats.');
seatCharts.get('1_1').node().trigger(mouseenterEvent);
//arrow right
keyEvent.which = 39;
seatCharts.get('1_1').node().trigger(keyEvent);
seatCharts.get('1_2').node().trigger(keyEvent);
//spacebar
keyEvent.which = 32;
seatCharts.get('1_4').node().trigger(keyEvent);
propEqual(executionsA, {
click : 1,
focus : 3,
blur : 4,
reset : function () {}
}, 'Blur, focus and click are correctly triggered for A seats.');
});
})(jQuery);

View File

@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>JSC Test Suite</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.14.0.css">
<link rel="stylesheet" href="../jquery.seat-charts.css">
<script src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../jquery.seat-charts.min.js"></script>
<script type="text/javascript" src="general.js"></script>
<script type="text/javascript" src="methods.js"></script>
<script type="text/javascript" src="interactions.js"></script>
<script type="text/javascript" src="multiple.js"></script>
</head>
<body>
<h1 id="qunit-header">JSC Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<div id="qunit-fixture"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
</body>
</html>

View File

@@ -0,0 +1,283 @@
(function ($) {
module('interactions');
//Creates a very simple map and returns map's container.
function interactionsMapSetup(params) {
var $fixture = $('#qunit-fixture'),
$div = $('<div id="seat-map">');
$fixture.append($div);
$div.seatCharts(
$.extend(true, {}, {
map: [
'aa_aa',
'aaaaa',
'bbbbb',
'bbbbb',
'ccccc',
'_____',
'cc_cc',
'_____',
'cc___'
],
seats: {
a: {
classes : 'a1-seat-class a2-seat-class',
price : 45,
anObject : {
aProperty: 'testing'
}
},
b: {
classes : ['b1-seat-class', 'b2-seat-class'],
price : 25,
anObject2: {
aProperty2: 23
}
}
}
}, params)
);
return $div;
}
test('Testing focus/blur with mouse', function () {
expect(8);
var $seatCharts = interactionsMapSetup(),
seatCharts = $seatCharts.seatCharts(),
seat1 = seatCharts.get('3_4'),
seat2 = seatCharts.get('4_1'),
mouseenterEvent,
focusEvent;
//focus the first seat
mouseenterEvent = $.Event('mouseenter');
seat1.node().trigger(mouseenterEvent);
equal(seat1.style(), 'focused', 'Test if focused using .style function.');
equal(seat1.node()[0], document.activeElement, 'Test if focused using document.activeElement');
equal($seatCharts.attr('aria-activedescendant'), seat1.node().attr('id'), 'Test if aria-activedescendant has been populated with the correct id.');
//move focus to some other seat
seat2.node().trigger(mouseenterEvent);
equal(seat1.style(), 'available', 'Test if previous seat lost focus using .style function.');
equal(seat2.style(), 'focused', 'Test if focused using .style function.');
equal(seat2.node()[0], document.activeElement, 'Test if focused using document.activeElement');
equal($seatCharts.attr('aria-activedescendant'), '4_1', 'Test if aria-activedescendant has been populated with the correct id.');
focusEvent = $.Event('focus');
$seatCharts.trigger(focusEvent);
equal(document.getElementById('1_1'), document.activeElement, 'First seat should be focused by default');
});
test('Testing focus/blur with keyboard', function () {
expect(14);
var $seatCharts = interactionsMapSetup(),
seatCharts = $seatCharts.seatCharts(),
focusEvent,
leftEvent,
rightEvent,
upEvent,
downEvent;
focusEvent = $.Event('focus');
$seatCharts.trigger(focusEvent);
leftEvent = $.Event('keydown');
leftEvent.which = 37;
rightEvent = $.Event('keydown');
rightEvent.which = 39;
downEvent = $.Event('keydown');
downEvent.which = 40;
upEvent = $.Event('keydown');
upEvent.which = 38;
seatCharts.get('1_1').node().trigger(rightEvent);
//right arrow
equal(document.activeElement, document.getElementById('1_2'), 'Right arrow moves focus to the right seat.');
equal($seatCharts.attr('aria-activedescendant'), seatCharts.get('1_2').node().attr('id'), 'Test if aria-activedescendant has been populated with the correct id.');
seatCharts.get('1_2').node().trigger(rightEvent);
equal(document.activeElement, document.getElementById('1_4'), 'Right arrow moves focus to the right seat skipping the empty space.');
seatCharts.get('1_4').node().trigger(rightEvent);
seatCharts.get('1_5').node().trigger(rightEvent);
equal(document.activeElement, document.getElementById('2_1'), 'Right arrow moves focus to the first seat of the next row when it reaches the end of the current row.');
seatCharts.get('5_5').node().trigger(focusEvent);
seatCharts.get('5_5').node().trigger(rightEvent);
equal(document.activeElement, document.getElementById('7_1'), 'Right arrow moves focus to the first seat skipping empty spaces.');
seatCharts.get('9_1').node().trigger(focusEvent);
seatCharts.get('9_1').node().trigger(rightEvent);
seatCharts.get('9_2').node().trigger(rightEvent);
equal(document.activeElement, document.getElementById('1_1'), 'Right arrow moves focus to the first seat skipping empty spaces and starting over when the last seat is reached.');
//left arrow
seatCharts.get('2_3').node().trigger(focusEvent);
seatCharts.get('2_3').node().trigger(leftEvent);
equal(document.activeElement, document.getElementById('2_2'), 'Left arrow moves focus to the left seat.');
seatCharts.get('2_2').node().trigger(leftEvent);
seatCharts.get('2_1').node().trigger(leftEvent);
equal(document.activeElement, document.getElementById('1_5'), 'Left arrow moves focus to the last seat of the previous row when the beginning of the current row is reached.');
seatCharts.get('9_1').node().trigger(focusEvent);
seatCharts.get('9_1').node().trigger(leftEvent);
equal(document.activeElement, document.getElementById('7_5'), 'Left arrow moves focus to the last seat of the previous row when the beginning of the current row is reached skipping empty spaces.');
seatCharts.get('1_1').node().trigger(focusEvent);
seatCharts.get('1_1').node().trigger(leftEvent);
equal(document.activeElement, document.getElementById('9_2'), 'Left arrow moves focus to the last seat when pressed on the first seat skipping empty spaces.');
//down
seatCharts.get('2_2').node().trigger(focusEvent);
seatCharts.get('2_2').node().trigger(downEvent);
equal(document.activeElement, document.getElementById('3_2'), 'Down arrow moves focus to the seat below.');
seatCharts.get('5_3').node().trigger(focusEvent);
seatCharts.get('5_3').node().trigger(downEvent);
equal(document.activeElement, document.getElementById('2_3'), 'Down arrow moves focus to the seat below skipping empty spaces.');
//up
seatCharts.get('4_4').node().trigger(focusEvent);
seatCharts.get('4_4').node().trigger(upEvent);
equal(document.activeElement, document.getElementById('3_4'), 'Up arrow moves focus to the seat above.');
$(document.activeElement).trigger(upEvent);
$(document.activeElement).trigger(upEvent);
$(document.activeElement).trigger(upEvent);
$(document.activeElement).trigger(upEvent);
equal(document.activeElement, document.getElementById('5_4'), 'Up arrow moves focus to the seat above skipping empty spaces.');
});
test('Testing default click callback with mouse', function () {
expect(7);
var $seatCharts = interactionsMapSetup(),
seatCharts = $seatCharts.seatCharts(),
clickEvent,
focusEvent;
//disable some seats
seatCharts.get(['1_4', '4_2']).status('unavailable');
clickEvent = $.Event('click');
focusEvent = $.Event('focus');
$('#5_2').trigger(clickEvent);
equal(seatCharts.find('selected').length, '1', 'Clicking on an available seat should change its status to selected.');
equal(seatCharts.get('5_2').style(), 'selected', 'Selected seat should return selected style.');
equal(seatCharts.get('5_2').status(), 'selected', 'Selected seat should return selected status.');
ok(seatCharts.get('5_2').node().hasClass('selected'), 'Selected seat should have selected class.');
$('#1_4').trigger(clickEvent);
equal(seatCharts.find('selected').length, '1', 'You can not select an unavailable seat.');
$('#5_2').trigger(clickEvent);
equal(seatCharts.find('selected').length, '0', 'Clicking on a selected seat should change its status to available.');
$('#3_3').trigger(focusEvent);
$('#3_3').trigger(clickEvent);
equal(seatCharts.get('3_3').status(), 'selected', 'Clicking on a focused seat should change its status to selected.');
});
test('Testing default click callback with keyboard', function () {
expect(7);
var $seatCharts = interactionsMapSetup(),
seatCharts = $seatCharts.seatCharts(),
spacebarEvent,
focusEvent;
//disable some seats
seatCharts.find('c').status('unavailable');
spacebarEvent = $.Event('keydown');
spacebarEvent.which = 32;
focusEvent = $.Event('focus');
$('#1_1').trigger(spacebarEvent);
equal(seatCharts.find('selected').length, '1', 'Pressing spacebar on an available seat should change its status to selected.');
equal(seatCharts.get('1_1').style(), 'selected', 'Selected seat should return selected style.');
equal(seatCharts.get('1_1').status(), 'selected', 'Selected seat should return selected status.');
ok(seatCharts.get('1_1').node().hasClass('selected'), 'Selected seat should have selected class.');
$('#7_2').trigger(spacebarEvent);
equal(seatCharts.find('selected').length, '1', 'You can not select an unavailable seat.');
$('#1_1').trigger(spacebarEvent);
equal(seatCharts.find('selected').length, '0', 'Pressing spacebar on a selected seat should change its status to available.');
$('#2_5').trigger(focusEvent);
$('#2_5').trigger(spacebarEvent);
equal(seatCharts.get('2_5').status(), 'selected', 'Pressing spacebar on a focused seat should change its status to selected.');
});
})(jQuery);

View File

@@ -0,0 +1,294 @@
(function ($) {
module('methods');
//Creates a very simple map and returns map's container.
function methodsMapSetup(params) {
var $fixture = $('#qunit-fixture'),
$div = $('<div id="seat-map">');
$fixture.append($div);
$div.seatCharts(
$.extend(true, {}, {
map: [
'aa_aa',
'aaaaa',
'bbbbb',
'bbbbb',
'ccccc',
],
seats: {
a: {
classes : 'a1-seat-class a2-seat-class',
price : 45,
anObject : {
aProperty: 'testing'
}
},
b: {
classes : ['b1-seat-class', 'b2-seat-class'],
price : 25,
anObject2: {
aProperty2: 23
}
}
}
}, params)
);
return $div;
}
test('Testing Seat methods & properties', function () {
expect(9);
var $seatCharts = methodsMapSetup(),
seatCharts = $seatCharts.seatCharts(),
seat = seatCharts.get('1_2');
equal(typeof seat.blur, 'function', '.blur method present.');
equal(typeof seat.char, 'function', '.char method present.');
equal(typeof seat.click, 'function', '.click method present.');
equal(typeof seat.data, 'function', '.data method present.');
equal(typeof seat.focus, 'function', '.focus method present.');
equal(typeof seat.node, 'function', '.node method present.');
equal(typeof seat.settings, 'object', '.settings property present.');
equal(typeof seat.status, 'function', '.status method present.');
equal(typeof seat.style, 'function', '.style method present.');
});
test('Testing Seat Set methods & properties', function () {
expect(11);
var $seatCharts = methodsMapSetup(),
seatCharts = $seatCharts.seatCharts(),
seat = seatCharts.get(['1_2', '4_3']);
equal(typeof seat.each, 'function', '.each method present.');
equal(typeof seat.find, 'function', '.find method present.');
equal(typeof seat.get, 'function', '.get method present.');
equal(typeof seat.length, 'number', '.length property present.');
equal(typeof seat.node, 'function', '.node method present.');
equal(typeof seat.push, 'function', '.push method present.');
equal(typeof seat.seatIds, 'object', '.seatIds property present.');
equal(seat.seatIds.length, 2, '.seatIds property correct.');
equal(typeof seat.seats, 'object', '.seats property present.');
equal(typeof seat.set, 'function', '.set method present.');
equal(typeof seat.status, 'function', '.status method present.');
});
test('Testing .get selector', function () {
expect(7);
var $seatCharts = methodsMapSetup(),
seatCharts = $seatCharts.seatCharts();
equal(typeof seatCharts.get('1_1'), 'object', '.get for one id should return an object.');
equal(typeof seatCharts.get('1_1').length, 'undefined', '.get for one id should return an object without length property.');
equal(typeof seatCharts.get(['1_1', '3_3']), 'object', '.get for two ids should return an object.');
equal(seatCharts.get(['1_1', '3_3', '2_4']).length, 3, '.get for three ids should have a property length with value 3.');
equal(typeof seatCharts.get('99_99'), 'undefined', '.get for invalid id should return undefined.');
equal(typeof seatCharts.get(['99_99', '2_3']), 'object', '.get for invalid and valid id and should return an object.');
equal(seatCharts.get(['99_99', '2_3']).length, 1, 'With 1 as length.');
});
test('Testing .status method', function () {
expect(10);
var $seatCharts = methodsMapSetup(),
seatCharts = $seatCharts.seatCharts(),
seat1,
seatsSet;
seat1 = seatCharts.get('2_3');
equal(seat1.status(), 'available', 'Default status is available.');
seat1.status('unavailable');
equal(seat1.status(), 'unavailable', 'Status has been changed.');
seat1.status('selected');
equal(seat1.status(), 'selected', 'Status has been changed again.');
seatsSet = seatCharts.get(['2_2', '2_4']);
seatsSet.status('selected');
equal(seatCharts.get('2_2').status(), 'selected', 'Setting status for the whole set 1.');
equal(seatCharts.get('2_4').status(), 'selected', 'Setting status for the whole set 2.');
seatCharts.status('3_2', 'unavailable');
equal(seatCharts.get('3_2').status(), 'unavailable', 'Alternative .status usage.');
seatCharts.status(['4_4', '5_2', '5_1'], 'unavailable');
equal(seatCharts.get('4_4').status(), 'unavailable', 'Alternative .status usage for the whole set 1.');
equal(seatCharts.get('5_2').status(), 'unavailable', 'Alternative .status usage for the whole set 2.');
equal(seatCharts.get('5_1').status(), 'unavailable', 'Alternative .status usage for the whole set 3.');
//Issue #8 - Very odd behaviour when using sc.status();
seatCharts.get(['1_1', '1_2']).status('unavailable');
//settings the same status twice
seatCharts.get(['1_1', '1_2']).status('unavailable');
equal(seatCharts.get('1_1').status(), 'unavailable', 'Status remains correct after setting the same status again');
});
test('Testing .find selector', function () {
expect(16);
var $seatCharts = methodsMapSetup(),
seatCharts = $seatCharts.seatCharts();
seatCharts.get(['4_1', '1_5', '2_3']).status('unavailable');
seatCharts.get(['5_2', '1_4']).status('selected');
equal(seatCharts.find('available').length, 19, 'Finding by status alone.');
equal(seatCharts.find('avble').length, 0, 'Finding by invalid status alone.');
equal(seatCharts.get(['4_1', '4_2']).find('unavailable').length, 1, 'Finding in set by status alone.');
equal(seatCharts.find('c').length, 5, 'Finding by character alone.');
equal(seatCharts.find('O').length, 0, 'Finding by invalid character.');
equal(seatCharts.get(['2_1', '3_2', '5_5', '5_3', '4_2']).find('b').length, 2, 'Finding in set by character alone.');
equal(seatCharts.get(['2_1', '3_2', '5_5', '5_3', '4_2']).find('_').length, 0, 'Finding in set by invalid character.');
equal(seatCharts.find('c.available').length, 4, 'Finding by character and status.');
equal(seatCharts.find('c.able').length, 0, 'Finding by character and invalid status.');
equal(seatCharts.find('P.availble').length, 0, 'Finding by invalid character and status.');
equal(seatCharts.get(['2_1', '3_2', '5_5', '5_3', '4_2', '2_3']).find('b.available').length, 2, 'Finding in set by character and status.');
equal(seatCharts.get(['2_1', '3_2', '5_5', '5_3', '4_2', '2_3']).find('X.available').length, 0, 'Finding in set by invalid character and status.');
equal(seatCharts.get(['2_1', '3_2', '5_5', '5_3', '4_2', '2_3']).find('c.invalid-status').length, 0, 'Finding in set by character and invalid status.');
equal(seatCharts.get(['9_12', '', '4_53']).find('b').length, 0, 'Finding in empty set.');
equal(seatCharts.find(/^1_.*/).length, 4, 'Finding first row seats using a regexp.');
equal(seatCharts.find(/^[0-9]+_3/).length, 4, 'Finding third column seats using a regexp.');
});
test('Testing .node method', function () {
expect(6);
var $seatCharts = methodsMapSetup(),
seatCharts = $seatCharts.seatCharts();
seatCharts.get(['2_2', '5_4']).status('unavailable');
ok(seatCharts.get('1_4').node() instanceof jQuery, '.node returns a jQuery object.');
equal(seatCharts.get('2_3').node().length, 1, '.node for one seat returns set with 1 element.');
equal(seatCharts.get(['2_3', '4_2']).node().length, 2, '.node for two seats returns set with 2 elements.');
equal(seatCharts.find('c.available').node().length, 4, '.node returns jQuery set with all objects matching .find query.');
equal(seatCharts.get('1_4').node()[0], $('#1_4')[0], 'The same node returned by .get and jQuery selector.');
equal(seatCharts.get(['2_2', '3_5']).node()[1], $('#3_5')[0], 'The same nodes returned by .get and jQuery selector.');
});
test('Testing .each method', function () {
expect(4);
var $seatCharts = methodsMapSetup(),
seatCharts = $seatCharts.seatCharts(),
executions1 = 0,
executions2 = 0,
executions3 = 0;
seatCharts.get(['5_2', '5_1']).status('selected');
seatCharts.find('c.available').each(function () {
executions1 += 1;
});
equal(executions1, 3, '.each callback should be called for each element of the set.');
seatCharts.find('c').each(function () {
executions2 += 1;
return false; //break
});
equal(executions2, 1, 'Returning false should break .each loop.');
seatCharts.find('Z').each(function() {
executions3 += 1;
});
equal(executions3, 0, '.each should not be called when the set is empty.');
seatCharts.find('a').each(function () {
equal(typeof this.data, 'function', 'Seat is used as the context.');
return false;
});
});
test('Testing .data method', function () {
expect(4);
var $seatCharts = methodsMapSetup(),
seatCharts = $seatCharts.seatCharts();
propEqual(seatCharts.get('1_2').data(), {
classes : 'a1-seat-class a2-seat-class',
price : 45,
anObject : {
aProperty: 'testing'
}
}, 'a seat has correct properties.');
propEqual(seatCharts.get('3_4').data(), {
classes : ['b1-seat-class', 'b2-seat-class'],
price : 25,
anObject2: {
aProperty2: 23
}
}, 'b seat has correct properties.');
propEqual(seatCharts.get('5_2').data(), {}, 'c seat has correct properties.');
seatCharts.get('1_2').data().price = '75';
equal(seatCharts.get('1_1').data().price, '75', 'All seat of the same character share the reference to the same object');
});
test('Testing .char method', function () {
var $seatCharts = methodsMapSetup(),
seatCharts = $seatCharts.seatCharts();
equal(seatCharts.get('5_5').char(), 'c', 'Correct character returned 1.');
equal(seatCharts.get('2_3').char(), 'a', 'Correct character returned 2.');
equal(seatCharts.get('4_4').char(), 'b', 'Correct character returned 3.');
});
})(jQuery);

View File

@@ -0,0 +1,57 @@
(function ($) {
module('multiple');
//testing multiple maps on page to ensure there are no conflicts
function multipleMapSetup(params) {
multipleMapSetup.counter = multipleMapSetup.counter || 1;
var $fixture = $('#qunit-fixture'),
$div = $('<div id="seat-map-'+(multipleMapSetup.counter++)+'">');
$fixture.append($div);
$div.seatCharts(
$.extend(true, {}, {
map: [
'aa_aa',
'bbbbb',
'bbbbb'
],
seats: {
a: {
classes : 'a1-seat-class a2-seat-class'
},
b: {
classes : ['b1-seat-class', 'b2-seat-class']
}
}
}, params)
);
return $div;
}
test('Testing selectors for multi maps', function () {
var $seatCharts1 = multipleMapSetup(),
seatCharts1 = $seatCharts1.seatCharts(),
$seatCharts2 = multipleMapSetup({
map: [
'eeeeeeeee',
'baaabaaaa',
'bbbbb____'
],
}),
seatCharts2 = $seatCharts2.seatCharts();
seatCharts1.find('a.available').status('unavailable');
equal(seatCharts1.find('unavailable').length, 4, 'Status has been changed correctly');
equal(seatCharts2.find('unavailable').length, 0, 'Status has not been changed for the other map.');
});
})(jQuery);