Skip to content

Instantly share code, notes, and snippets.

@sebald
Last active December 18, 2015 22:58
Show Gist options
  • Save sebald/5857918 to your computer and use it in GitHub Desktop.
Save sebald/5857918 to your computer and use it in GitHub Desktop.
describe('Element "Dropdown":', function () {
var scope, dropdownScope, element, $compile;
beforeEach( module('html.element.dropdown') );
beforeEach( module('html/element/dropdown.tpl.html') );
beforeEach( inject( function ( _$rootScope_, _$compile_ ) {
scope = _$rootScope_.$new();
$compile = _$compile_;
scope.list = [ 'All Coffee', 'Espresso', 'Americano', 'Cappuccino' ];
element = $compile( '<dropdown list="list"></dropdown>' )( scope );
dropdownScope = element.scope();
scope.$digest();
}));
it('should initialize relevant scope vars', function () {
// Just a test. Should be 2 but it is 0.
console.log(element.children().length);
expect( dropdownScope.list ).toBeDefined();
expect( dropdownScope.selected ).toBeDefined();
});
it('should select the first value in the list as', function () {
expect( dropdownScope.selected ).toEqual( scope.list[0] );
});
it('should open/close via the toggle function', function () {
expect( element.hasClass('active') ).not.toBeTruthy();
dropdownScope.toggle( $.Event( 'click' ) );
expect( element.hasClass('active') ).toBeTruthy();
});
it('should close when "action" is executed', function () {
expect( element.hasClass('active') ).not.toBeTruthy();
dropdownScope.toggle( $.Event( 'click' ) );
dropdownScope.action( scope.list[1] );
expect( element.hasClass('active') ).not.toBeTruthy();
})
// [..]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment