<commit_before><commit_msg>ActivityIframeView tests (#178)<commit_after>/**
 * Copyright 2017 The __PROJECT__ Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS-IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {ActivityIframeView} from './activity-iframe-view';
import {ActivityPorts, ActivityIframePort} from 'web-activities/activity-ports';
import {Dialog} from '../components/dialog';

describes.realWin('ActivityIframeView', {}, env => {
  let win;
  let src;
  let activityPorts;
  let activityIframePort;
  let activityIframeView;
  let dialog;

  beforeEach(() => {
    win = env.win;
    src = 'http://subscribe.sandbox.google.com/subscribewithgoogleclientui/offersiframe';
    dialog = new Dialog(win, {height: '100px'});
    activityPorts = new ActivityPorts(win);
    activityIframePort = new ActivityIframePort(dialog.getElement(), src);

    sandbox.stub(
        activityIframePort,
        'whenReady',
        () => Promise.resolve(true));

    sandbox.stub(
        activityPorts,
        'openIframe',
        () => Promise.resolve(activityIframePort));

    sandbox.stub(
        activityIframePort,
        'onResizeRequest',
        () => true);

    activityIframeView =
        new ActivityIframeView(win, activityPorts, src, {});
  });

  describe('ActivityIframeView', () => {
    it('should have activityIframeView constructed', () => {
      const activityIframe = activityIframeView.getElement();
      expect(activityIframe.nodeType).to.equal(1);
      expect(activityIframe.nodeName).to.equal('IFRAME');
      expect(activityIframe.getAttribute('frameborder')).to.equal('0');
    });

    it('should should initialize and open an iframe', function* () {
      const openedDialog = yield dialog.open();

      // The iframe should be inside DOM to call init().
      dialog.getContainer().appendChild(activityIframeView.getElement());

      const activityResponse = yield activityIframeView.init(openedDialog);
      expect(activityResponse).to.be.true;
      expect(activityPorts.openIframe).to.have.been.calledOnce;
      expect(activityIframePort.onResizeRequest).to.have.been.calledOnce;
      expect(activityIframePort.whenReady).to.have.been.calledOnce;
    });
  });
});
{'fraction_non_alphanumeric': 0.12001477104874446, 'fraction_numerical': 0.005908419497784343, 'mean_word_length': 3.736013986013986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '348163', 'n_tokens_mistral': 777, 'n_tokens_neox': 754, 'n_words': 190}