Permalink
Browse files

even more pulldown tests

  • Loading branch information...
1 parent 77869b3 commit fdb391f6bd1781aac9ef51680ccfa00da71f582c @jamesstrate jamesstrate committed Mar 28, 2013
Showing with 128 additions and 42 deletions.
  1. +128 −42 test/pulldown.js
View
@@ -4,41 +4,32 @@ $(document).ready(function() {
Backbone.UI.setMobile(false);
- test("withoutDataBinding", function(){
+ var regions = new Backbone.Collection([{
+ name: 'Americas',
+ notes: 'Bright'
+ }, {
+ name: 'Africa',
+ notes: 'Fruity'
+ }]);
- var regions = new Backbone.Collection([{
- name: 'Americas',
- notes: 'Bright'
- }, {
- name: 'Africa',
- notes: 'Fruity'
- }]);
+ test("withoutDataBinding", function(){
var pulldown = new Backbone.UI.Pulldown({
content: 'test',
alternatives: regions,
altLabelContent: 'name'
}).render();
- $(pulldown.el).find('input').click();
+ pulldown.$('.pulldown_button').click();
$(pulldown._menu.el).find('li a').eq(0).click();
equal($(pulldown.el).find('.label').text(),'Americas');
-
});
test("withDataBinding", function(){
- var regions = new Backbone.Collection([{
- name: 'Americas',
- notes: 'Bright'
- }, {
- name: 'Africa',
- notes: 'Fruity'
- }]);
-
var coffee = new Backbone.Model({
roaster: 'Counter Culture',
name: 'Baroida',
@@ -54,22 +45,45 @@ $(document).ready(function() {
altLabelContent: 'name'
}).render();
- $(pulldown.el).find('input').click();
+ pulldown.$('.pulldown_button').click();
$(pulldown._menu.el).find('li a').eq(1).click();
equal(coffee.get('region').get('name'),'Africa');
});
- test("emptyItem", function(){
+ test("onMenuShow", function() {
+
+ var coffee = new Backbone.Model({
+ roaster: 'Counter Culture',
+ name: 'Baroida',
+ roastedOn: new Date(2012, 2, 28, 6, 30),
+ acidic: true,
+ region: regions.at(0)
+ });
+
+ var changeEvents = 0;
+
+ var pulldown = new Backbone.UI.Pulldown({
+ model: coffee,
+ content: 'region',
+ alternatives: regions,
+ altLabelContent: 'name',
+ onMenuShow: function () {
+ changeEvents++;
+ }
+ }).render();
- var regions = new Backbone.Collection([{
- name: 'Americas',
- notes: 'Bright'
- }, {
- name: 'Africa',
- notes: 'Fruity'
- }]);
+ //click pulldown
+ pulldown.$('.pulldown_button').click();
+
+ //check if menu show was called
+ equal(changeEvents, 1);
+
+ pulldown._menu.$('.content a').eq(1).click();
+ });
+
+ test("placeholder", function(){
var coffee = new Backbone.Model({
roaster: 'Counter Culture',
@@ -84,27 +98,47 @@ $(document).ready(function() {
content: 'region',
alternatives: regions,
altLabelContent: 'name',
- emptyItem: true
+ placeholder: "Select a region..."
}).render();
- //select emptyItem
- $(pulldown.el).find('input').click();
- $(pulldown._menu.el).find('li a').eq(0).click();
-
- //check if selection is empty
- equal(coffee.get('region'),null);
+ //check the label on pulldown
+ equal($(pulldown.el).find('.label').text(),"Select a region...");
});
- test("triggers the onChange callback", function() {
+ test("onMenuHide", function() {
- var regions = new Backbone.Collection([{
- name: 'Americas',
- notes: 'Bright'
- }, {
- name: 'Africa',
- notes: 'Fruity'
- }]);
+ var coffee = new Backbone.Model({
+ roaster: 'Counter Culture',
+ name: 'Baroida',
+ roastedOn: new Date(2012, 2, 28, 6, 30),
+ acidic: true,
+ region: regions.at(0)
+ });
+
+ var changeEvents = 0;
+
+ var pulldown = new Backbone.UI.Pulldown({
+ model: coffee,
+ content: 'region',
+ alternatives: regions,
+ altLabelContent: 'name',
+ onMenuHide: function () {
+ changeEvents++;
+ }
+ }).render();
+
+ //click pulldown
+ pulldown.$('.pulldown_button').click();
+ //make selection to hide menu
+ pulldown._menu.$('.content a').eq(1).click();
+
+ //check if menu hide was called
+ equal(changeEvents, 1);
+
+ });
+
+ test("onChange", function() {
var coffee = new Backbone.Model({
roaster: 'Counter Culture',
@@ -133,4 +167,56 @@ $(document).ready(function() {
equal(changeEvents, 1);
equal(itemClicked, regions.at(1));
});
+
+ test("emptyItem", function(){
+
+ var coffee = new Backbone.Model({
+ roaster: 'Counter Culture',
+ name: 'Baroida',
+ roastedOn: new Date(2012, 2, 28, 6, 30),
+ acidic: true,
+ region: regions.at(0)
+ });
+
+ var pulldown = new Backbone.UI.Pulldown({
+ model : coffee,
+ content: 'region',
+ alternatives: regions,
+ altLabelContent: 'name',
+ emptyItem: true
+ }).render();
+
+ //select emptyItem
+ pulldown.$('.pulldown_button').click();
+ $(pulldown._menu.el).find('li a').eq(0).click();
+
+ //check if selection is empty
+ equal(coffee.get('region'),null);
+
+ });
+
+ test("alignRight", function(){
+
+ var coffee = new Backbone.Model({
+ roaster: 'Counter Culture',
+ name: 'Baroida',
+ roastedOn: new Date(2012, 2, 28, 6, 30),
+ acidic: true,
+ region: regions.at(0)
+ });
+
+ var pulldown = new Backbone.UI.Pulldown({
+ model : coffee,
+ content: 'region',
+ alternatives: regions,
+ altLabelContent: 'name',
+ alignRight : true
+ }).render();
+
+ //click to display menu
+ pulldown.$('.pulldown_button').click();
+ //check the label on pulldown
+ equal($(pulldown._menu.el).css('left'),'-80px');
+
+ });
});

0 comments on commit fdb391f

Please sign in to comment.