Permalink
Browse files

adding tests

  • Loading branch information...
1 parent 5452bd9 commit 5a2b9ffda407ded25bbaa26f5765193b3764b2b1 @anutron committed Jan 11, 2011
Showing with 62 additions and 8 deletions.
  1. +60 −7 Specs/1.3/Interface/HtmlTable.Select.js
  2. +2 −1 Specs/Configuration.js
@@ -1,16 +1,69 @@
describe('HtmlTable.Select', function(){
- it('should clear selections when emptying a table', function(){
- var SelectableTable = new HtmlTable({
+ var getTable = function(){
+ return new HtmlTable({
selectable: true,
- useKeyboard: false,
+ useKeyboard: true,
rows: [[0],[1],[2]]
});
+ };
+
+ it('should clear selections when emptying a table', function(){
+ var table = getTable();
+
+ var row = table.body.getChildren()[0];
+ table.selectRow(row);
+ table.empty();
+ expect(table.isSelected(row)).toEqual(false);
+ });
- var row = SelectableTable.body.getChildren()[0];
- SelectableTable.selectRow(row);
- SelectableTable.empty();
- expect(SelectableTable.isSelected(row)).toEqual(false);
+ it('keyboard events should change selection', function(){
@fat
fat Jan 26, 2011

the cool thing about the it keyword is that it's suppose to make the sentence readable... like:
it("should do foo")

as it's a test i think it's a good practice to make all the spec start with it should.
so this would become something like:

it('should change selection')

antoher cool jasmine thing is you can do nested describes...

so if you're describing keyboard events within html table you could do:

describe("keyboard events", function(){
    it("should change selection", function(){
    });
});

not sure if you already knew that, but just thought i would bring it up :)

also it should probably be more explicit if possible... like it should change selection when..

@anutron
anutron Jan 26, 2011 Owner

updated in this branch.

+ var table = getTable().inject(document.body);
+
+ var rows = table.body.getChildren();
+
+ Syn.type('[down]', table.toElement());
+
+ expect(table.isSelected(rows[0])).toEqual(true);
+ Syn.type('[down]', table.toElement());
+ expect(table.isSelected(rows[0])).toEqual(false);
+ expect(table.isSelected(rows[1])).toEqual(true);
+ Syn.type('[shift][up]', table.toElement());
+ expect(table.isSelected(rows[0])).toEqual(true);
+ expect(table.isSelected(rows[1])).toEqual(true);
+ table.dispose();
});
+ it('table should enable its keyboard', function(){
+ var table1 = getTable().inject(document.body);
+ var table2 = getTable().inject(document.body);
+ table1.toElement().id = 'one';
+ table2.toElement().id = 'two';
+
+ var t1rows = table1.body.getChildren();
+ var t2rows = table2.body.getChildren();
+
+ Syn.type('[down]', table2.toElement());
+
+ expect(table2.isSelected(t2rows[0])).toEqual(true);
+
+ //can't get the click to work for some reason...
+ //Syn.click({}, table1.toElement());
+ //works fine if I activate it manually
+ table1.keyboard.activate();
+
+ Syn.type('[down]', table1.toElement());
+ expect(table1.isSelected(t1rows[0])).toEqual(true);
+
+ //and this should be deactivated, so no change
+ Syn.type('[down]', table2.toElement());
+ expect(table2.isSelected(t2rows[0])).toEqual(true);
+
+ table1.dispose();
+ table2.dispose();
+
+
+ });
+
+
});
@@ -55,7 +55,7 @@ Configuration.sets = {
'Element/Element.Forms', 'Element/Element.Measure', 'Element/Elements.From', 'Element/Element.Shortcuts',
'Element/Element.Event.Pseudos', 'Element/Element.Event.Pseudos.Keys', 'Element/Element.Delegation',
'Types/URI', 'Types/URI.Relative',
- 'Interface/Keyboard', 'Interface/HtmlTable', 'Interface/HtmlTable.Sort', 'Interface/Htmltable.Select',
+ 'Interface/Keyboard', 'Interface/Keyboard.Extras', 'Interface/HtmlTable', 'Interface/HtmlTable.Sort', 'Interface/Htmltable.Select',
'Forms/Form.Validator',
'Fx/Fx.Reveal',
'Request/Request.JSONP',
@@ -177,6 +177,7 @@ Configuration.source = {
'Types/URI.Relative',
'Interface/Keyboard',
+ 'Interface/Keyboard.Extras',
'Interface/HtmlTable',
'Interface/HtmlTable.Sort',
'Interface/HtmlTable.Select',

0 comments on commit 5a2b9ff

Please sign in to comment.