DinisCruz / Book_Practical_AngularJS

Content for 'Practical AngularJS' book published at LeanPub
Apache License 2.0
18 stars 6 forks source link

add JsDom directive test example #29

Open DinisCruz opened 8 years ago

DinisCruz commented 8 years ago

as seen at https://twitter.com/DinisCruz/status/749019498632667137

JsDom_API  = require '../../../src/_Test_APIs/JsDom-API'

describe.only 'jsdom | directives | projects.page', ->

  project = 'bsimm'
  team    = 'team-A'
  jsDom   = null
  page    = "/view/#{project}/#{team}"

  before (done)->
    jsDom = new JsDom_API()
    jsDom.open page, ->
      jsDom.wait_No_Http_Requests ->
        done()

  it 'check jsdom loaded ok',->
    using jsDom, ->
      @.$app().length.assert_Is 1
      @.$.fn.jquery.assert_Is '3.0.0'
      @.$http().pendingRequests.size().assert_Is 0

  it 'check ng-view contents', ()->
    using jsDom, ->
      links = @.$('.sub-nav a')                               # get all navigation links

      test_Link = (text, url)=>                               # function to test links
        link = links[index++]                                 # get link to test
        link.text.assert_Is text                              # confirm link text is expected value
        link.click()                                          # click on link
        @.$location().url().assert_Is url                     # confirm location matches expected value

      index = 1                                               # this is a really weird timing bug since this check doesn't work here
      #test_Link 'bsimm', "/view/project/#{project}"
      test_Link 'view' , "/view/#{project}/#{team}"
      test_Link 'table', "/view/#{project}/#{team}/table"
      test_Link 'radar', "/view/#{project}/#{team}/radar"
      test_Link 'edit' , "/view/#{project}/#{team}/edit"
      index = 0                                               # but it works here
      test_Link 'bsimm', "/view/project/#{project}"