BigW Consortium Gitlab

right_sidebar_spec.js.coffee 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#= require right_sidebar
#= require jquery
#= require jquery.cookie

@sidebar    = null
$aside      = null
$toggle     = null
$icon       = null
$page       = null
$labelsIcon = null


assertSidebarState = (state) ->

  shouldBeExpanded  = state is 'expanded'
  shouldBeCollapsed = state is 'collapsed'

  expect($aside.hasClass('right-sidebar-expanded')).toBe shouldBeExpanded
  expect($page.hasClass('right-sidebar-expanded')).toBe shouldBeExpanded
  expect($icon.hasClass('fa-angle-double-right')).toBe shouldBeExpanded

  expect($aside.hasClass('right-sidebar-collapsed')).toBe shouldBeCollapsed
  expect($page.hasClass('right-sidebar-collapsed')).toBe shouldBeCollapsed
  expect($icon.hasClass('fa-angle-double-left')).toBe shouldBeCollapsed


describe 'RightSidebar', ->

  fixture.preload 'right_sidebar.html'

  beforeEach ->
    fixture.load 'right_sidebar.html'

    @sidebar    = new Sidebar
    $aside      = $ '.right-sidebar'
    $page       = $ '.page-with-sidebar'
    $icon       = $aside.find 'i'
    $toggle     = $aside.find '.js-sidebar-toggle'
    $labelsIcon = $aside.find '.sidebar-collapsed-icon'


  it 'should expand the sidebar when arrow is clicked', ->

    $toggle.click()
    assertSidebarState 'expanded'


  it 'should collapse the sidebar when arrow is clicked', ->

    $toggle.click()
    assertSidebarState 'expanded'

    $toggle.click()
    assertSidebarState 'collapsed'


  it 'should float over the page and when sidebar icons clicked', ->

    $labelsIcon.click()
    assertSidebarState 'expanded'


  it 'should collapse when the icon arrow clicked while it is floating on page', ->

    $labelsIcon.click()
    assertSidebarState 'expanded'

    $toggle.click()
    assertSidebarState 'collapsed'