Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anutron committed Jan 11, 2011
1 parent 5452bd9 commit 5a2b9ff
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
67 changes: 60 additions & 7 deletions Specs/1.3/Interface/HtmlTable.Select.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(){

This comment has been minimized.

Copy link
@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..

This comment has been minimized.

Copy link
@anutron

anutron Jan 26, 2011

Author 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();


});


});
3 changes: 2 additions & 1 deletion Specs/Configuration.js
Expand Up @@ -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',
Expand Down Expand Up @@ -177,6 +177,7 @@ Configuration.source = {
'Types/URI.Relative',

'Interface/Keyboard',
'Interface/Keyboard.Extras',
'Interface/HtmlTable',
'Interface/HtmlTable.Sort',
'Interface/HtmlTable.Select',
Expand Down

0 comments on commit 5a2b9ff

Please sign in to comment.