/*
 *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree.
 */

/* More information about these options at jshint.com/docs/options */

/* globals AppController, describe, expect, it, beforeEach, afterEach,
   UI_CONSTANTS, $, RoomSelection:true, Call:true */

'use strict';

describe('AppControllerTest', function() {
  var MockCall;
  var MockRoomSelection;
  var roomSelectionBackup_;
  var callBackup_;
  var loadingParams_;
  var mainElem;

  MockRoomSelection = function() {};
  MockRoomSelection.RecentlyUsedList = function() {
    return {
      pushRecentRoom: function() {}
    };
  };
  MockRoomSelection.matchRandomRoomPattern = function() {
    return false;
  };

  MockCall = function() {};
  MockCall.prototype.start = function() {};
  MockCall.prototype.hangup = function() {};

  beforeEach(function(done) {
    roomSelectionBackup_ = RoomSelection;
    RoomSelection = MockRoomSelection;
    callBackup_ = Call;
    Call = MockCall;
    loadingParams_ = {
      mediaConstraints: {
        audio: true, video: true
      }
    };

    // Insert mock DOM elements.
    mainElem = document.createElement('div');
    document.body.insertBefore(mainElem, document.body.firstChild);
    for (var key in UI_CONSTANTS) {
      var elem;
      if (key.toLowerCase().includes('button')) {
        elem = document.createElement('button');
      } else {
        elem = document.createElement('div');
      }
      elem.id = UI_CONSTANTS[key].substr(1);
      mainElem.appendChild(elem);
    }

    loadingParams_.roomId = 'myRoom';
    new AppController(loadingParams_);

    // Needed due to a race where the textContent node is not updated in the div
    //  before testing it.
    $(UI_CONSTANTS.confirmJoinRoomSpan)
      .addEventListener('DOMSubtreeModified', function() {
        done();
      });
  });

  afterEach(function() {
    RoomSelection = roomSelectionBackup_;
    Call = callBackup_;
  });

  it('Confirm to join', function() {
    // Verifies that the confirm-to-join UI is visible and the text matches the
    // room.
    expect($(UI_CONSTANTS.confirmJoinRoomSpan).textContent)
        .toEqual(' "' + loadingParams_.roomId + '"');
    expect($(UI_CONSTANTS.confirmJoinDiv).classList.contains('hidden'))
        .toBeFalsy();
  });

  it('Hide UI after clicking the join button', function(done) {
    // Verifies that the UI is hidden after clicking the button.
    // Need to wait a few seconds for the element to update it's class list.
    setTimeout(function() {
      $(UI_CONSTANTS.confirmJoinButton).addEventListener('click', function() {
        expect($(UI_CONSTANTS.confirmJoinDiv).classList.contains('hidden'))
          .toBeTruthy();
        done();
      });
      $(UI_CONSTANTS.confirmJoinButton).click();
    }, 2000);
  });
});

@@ -2552,17 +2552,95 @@
 %0A    // 
-N
+There seems to be a delay for the beforeEach() to update the DOM tree,%0A    // n
 eed to w
@@ -2661,49 +2661,141 @@
 nds 
+be
 for
- the element to update it's class list
+e clicking the button as it calls upon%0A    // a method that adds a 'hidden' class to an element which we then try to%0A    // find
 .%0A  

Add more context to the comment