Skip to content

Commit

Permalink
tests for sidenav with menuservice
Browse files Browse the repository at this point in the history
  • Loading branch information
shanzi committed Apr 13, 2015
1 parent d2a0548 commit 47a6ea6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
Expand Up @@ -13,10 +13,10 @@ class Sidenav extends Directive

class _Sidenav extends Controller

items: []

constructor: (@$scope, @$attrs, @menuService) ->
@items = @menuService.getItems()
constructor: (@$scope, @menuService) ->

isHighlighted: (name) ->
return name == @menuService.getCurrent()

getItems: ->
return @menuService.getItems()
@@ -1,21 +1,25 @@
beforeEach module 'app'

describe 'MD: Sidebar directive', ->
$rootScope = $compile = $httpBackend = null
$rootScope = $compile = $httpBackend = _menuServiceProvider = null

injected = ($injector) ->
$compile = $injector.get('$compile')
$rootScope = $injector.get('$rootScope')
$httpBackend = $injector.get('$httpBackend')
decorateHttpBackend($httpBackend)

beforeEach(inject(injected))
beforeEach module (menuServiceProvider) ->
_menuServiceProvider = menuServiceProvider
return null
beforeEach inject injected

afterEach ->
$httpBackend.verifyNoOutstandingExpectation()
$httpBackend.verifyNoOutstandingRequest()

it 'should displays nav items', ->
_menuServiceProvider.items = []
$httpBackend.expectGETSVGIcons()
element = $compile('<div><sidenav items="items" current="current"></sidenav></div>')($rootScope)
$rootScope.$digest()
Expand All @@ -31,12 +35,12 @@ describe 'MD: Sidebar directive', ->
expect(content.children().length).toBe(0)

# adding items
$rootScope.items = (
for n in [1..3]
for n in [1..3]
_menuServiceProvider.addItem
name: 'testitem' + n
title: 'test item ' + n
caption: 'test item ' + n
icon: 'test-icon-' + n
)
order: n

$rootScope.$digest()

Expand All @@ -50,7 +54,7 @@ describe 'MD: Sidebar directive', ->

# testing highlight
for i in [i..3]
$rootScope.current = 'testitem' + i
_menuServiceProvider.current = 'testitem' + i
$rootScope.$digest()

for n in [1..3]
Expand Down
Expand Up @@ -7,7 +7,7 @@ md-sidenav.md-whiteframe-z1(
md-content.nav-item-container(flex)
md-button.nav-item(
ui-sref="{{ item.name }}",
ng-repeat="item in sidenav.items|orderBy:'order'",
ng-repeat="item in sidenav.getItems()|orderBy:'order'",
ng-class="{highlighted: sidenav.isHighlighted(item.name)}",
)
md-icon(md-svg-icon="{{ item.icon }}")
Expand Down
6 changes: 6 additions & 0 deletions www/md_base/src/app/common/services/menu/menu.service.coffee
Expand Up @@ -26,3 +26,9 @@ class GlMenu extends Provider
# nested items will be supported no longer

@menuServiceProvider.addItem group

$get: ->
# this method should never be used
# but we will return the same result of menuServiceProvider

return @menuServiceProvider.$get()
2 changes: 1 addition & 1 deletion www/md_base/src/app/index.jade
Expand Up @@ -13,7 +13,7 @@ html(ng-app="app", ng-controller="appController as app")
link(rel='stylesheet', href='https://fonts.googleapis.com/css?family=RobotoDraft:300,400,500,700,400italic')

body(ng-cloak, flex, layout="row")
sidenav(items="app.navitems", current="app.current")
sidenav
div(layout="column", role="main", flex)
md-toolbar.topbar
div.md-toolbar-tools
Expand Down

0 comments on commit 47a6ea6

Please sign in to comment.