<commit_before>/* global sinon, SPAPort, Server, TalkillaSPA, expect */
/* jshint unused:false */
"use strict";

describe("TalkillaSPA", function() {
  var sandbox, port, server, spa;

  beforeEach(function() {
    sandbox = sinon.sandbox.create();
    port = new SPAPort();
    server = new Server();
    spa = new TalkillaSPA(port, server, {capabilities: ["call", "move"]});
  });

  describe("#constructor", function() {
    it("should accept capabilities", function() {
      expect(spa.capabilities).to.be.a("array");
      expect(spa.capabilities).eql(["call", "move"]);
    });

  });

  describe("#_onServerEvent", function() {

    it("should post a connect event to the port", function() {
      spa.email = "foo";
      sandbox.stub(spa.port, "post");

      spa.server.trigger("connected");

      sinon.assert.calledOnce(spa.port.post);
      sinon.assert.calledWithExactly(
        spa.port.post, "connected", {
          addresses: [{type: "email", value: "foo"}],
          capabilities: ["call", "move"]
        }
      );
    });

    it("should post a reconnection event to the port", function() {
      var event = {timeout: 42, attempt: 2};
      sandbox.stub(spa.port, "post");

      spa.server.trigger("reconnection", event);

      sinon.assert.calledOnce(spa.port.post);
      sinon.assert.calledWithExactly(
        spa.port.post, "reconnection", event);<commit_msg>Test that a reconnection payload is sent<commit_after>/* global sinon, SPAPort, Server, TalkillaSPA, expect, payloads */
/* jshint unused:false */
"use strict";

describe("TalkillaSPA", function() {
  var sandbox, port, server, spa;

  beforeEach(function() {
    sandbox = sinon.sandbox.create();
    port = new SPAPort();
    server = new Server();
    spa = new TalkillaSPA(port, server, {capabilities: ["call", "move"]});
  });

  describe("#constructor", function() {
    it("should accept capabilities", function() {
      expect(spa.capabilities).to.be.a("array");
      expect(spa.capabilities).eql(["call", "move"]);
    });

  });

  describe("#_onServerEvent", function() {

    it("should post a connect event to the port", function() {
      spa.email = "foo";
      sandbox.stub(spa.port, "post");

      spa.server.trigger("connected");

      sinon.assert.calledOnce(spa.port.post);
      sinon.assert.calledWithExactly(
        spa.port.post, "connected", {
          addresses: [{type: "email", value: "foo"}],
          capabilities: ["call", "move"]
        }
      );
    });

    it("should post a reconnection event to the port", function() {
      var event = {timeout: 42, attempt: 2};
      sandbox.stub(spa.port, "post");

      spa.server.trigger("reconnection", event);

      sinon.assert.calledOnce(spa.port.post);
      sinon.assert.calledWithExactly(
        spa.port.post, "reconnection", new payloads.Reconnection(event));
{'fraction_non_alphanumeric': 0.16982456140350877, 'fraction_numerical': 0.002105263157894737, 'mean_word_length': 3.1926470588235296, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5202180', 'n_tokens_mistral': 930, 'n_tokens_neox': 899, 'n_words': 197}