DinisCruz / Book_Practical_AngularJS

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

Add example of manipulating Scope from test #32

Open DinisCruz opened 8 years ago

DinisCruz commented 8 years ago
  it 'should keep input value inSync with scope', ->

    $scope. metadata.team.assert_Is 'Team BSIMM'
    element.find('input').val().assert_Is 'Team BSIMM'

    element.find('input').val('AAAAA').triggerHandler('input')
    $scope. $digest()
    element.find('input').val().assert_Is 'AAAAA'
    $scope .metadata.team.assert_Is 'AAAAA'

    $scope .metadata.team = 'BBBBB'
    $scope .$digest()
    element.find('input').val().assert_Is 'BBBBB'
DinisCruz commented 8 years ago

here is an example of accessing this via jsdom

  it 'check page contents', ()->
    using jsDom, ->
      table_Headers = (@.$(th).html() for th in @.$('table th'))
      table_Headers.size().assert_Is 20
      table_Headers.assert_Contains ['ID', 'Yes', 'No', 'NA','Maybe']

      all_Rows  = @.$('table tr')
      all_Cells = @.$('table td')

      all_Rows.length.assert_Is  120
      all_Cells.length.assert_Is 560

      @.$('#save-data').html().assert_Is 'save'         # save button
      @.$('#team-name').val() .assert_Is 'Team A'       # team name input fie
      @.$('#message'  ).html().assert_Is 'data loaded'  # status message
      @.$('#domain'   ).text().assert_Is 'Governance'   # save button

      using @.$('tr[id="SM.1.1"] td'),->
        @.length.assert_Is 5
        @.eq(0).html().assert_Is 'SM.1.1'
        @.eq(1).html().assert_Is '<input type="radio" ng-name="key" ng-model="data[key]" value="Yes" class="ng-pristine ng-untouched ng-valid ng-not-empty" name="26">'
        @.eq(1).find('input').val().assert_Is 'Yes'
        @.eq(2).find('input').val().assert_Is 'No'
        @.eq(3).find('input').val().assert_Is 'NA'
        @.eq(4).find('input').val().assert_Is 'Maybe'
DinisCruz commented 8 years ago

here is how to trigger a click in JsDom

  it 'Check save message', (done)->
    using jsDom, ->
      @.$('#message').html().assert_Is 'data loaded'                       # message before save      
      @.window.angular.element(@.$('#save-data')).triggerHandler('click')  # this is what triggers the .click() event    
      @.wait_No_Http_Requests =>                                           # wait for http requests
        @.$('#message'  ).html().assert_Is 'file saved ok'                 # message after save
        done()