<commit_before>/**
 * Copyright (c) 2015 <NAME> (@localnerve), LocalNerve LLC
 * Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
 */
/* global describe, it, before, after, beforeEach */
'use strict';

var expect = require('chai').expect;

var createMockActionContext = require('fluxible/utils').createMockActionContext;
var MockService = require('fluxible-plugin-fetchr/utils/MockServiceManager');
var modelsResponse = require('../../fixtures/models-response');
var ModalStore = require('../../../stores/ModalStore');
var ContentStore = require('../../../stores/ContentStore');
var modalStartAction = require('../../../actions/modal').openModal;
var modalStopAction = require('../../../actions/modal').closeModal;
var serviceData = require('../../mocks/service-data');
var mockActionInterface = require('../../mocks').interface;

describe('modal action', function () {
  var context, params;

  before(function () {
    mockActionInterface.begin();
  });

  after(function () {
    mockActionInterface.end();
  });

  beforeEach(function () {
    params = JSON.parse(JSON.stringify(modelsResponse.Settings));
    context = createMockActionContext({
      stores: [ModalStore, ContentStore]
    });
    context.service = new MockService();
    context.service.setService('page', function (method, params, config, callback) {
      serviceData.fetch(params, callback);
    });
  });

  describe('start', function () {
    it('should update the ModalStore', function (done) {
      context.executeAction(modalStartAction, params, function (err) {
        if (err) {
          return done(err);
        }

        var modalStore = context.getStore(ModalStore),
            component = modalStore.getComponent(),
            props = modalStore.getProps(),
            isOpen = modalStore.getIsOpen();

        expect(isOpen).to.be.a('boolean').and.equal(true);
        expect(component).to.be.undefined;
        // this is content, models from service-data
        expect(props).to.be.an('object').with.property('content');

        done();
      });
    });

    it('should update the ContentStore', function (done) {
      context.executeAction(modalStartAction, params, function (err) {
        if (err) {
          return done(err);
        }

        var contentStore = context.getStore(ContentStore),
            content = contentStore.getCurrentPageContent(),
            models = contentStore.getCurrentPageModels();

        expect(content).to.exist.and.be.an('object');
        // this is models from fixture
        expect(models).to.eql(modelsResponse);

        done();
      });
    });
  });

  describe('stop', function () {
    it('should update the ModalStore', function (done) {
      context.executeAction(modalStopAction, params, function (err) {
        if (err) {
          return done(err);
        }

        var modalStore = context.getStore(ModalStore),
            isOpen = modalStore.getIsOpen();

        expect(isOpen).to.equal(false);
        done();
      });
    });
  });

  describe('update', function () {
    it.skip('should update props', function () {
    });

    it.skip('should update component', function () {
    });
  });
});<commit_msg>add modal component test<commit_after>/**
 * Copyright (c) 2015 <NAME> (@localnerve), LocalNerve LLC
 * Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
 */
/* global describe, it, before, after, beforeEach */
'use strict';

var expect = require('chai').expect;

var createMockActionContext = require('fluxible/utils').createMockActionContext;
var MockService = require('fluxible-plugin-fetchr/utils/MockServiceManager');
var modelsResponse = require('../../fixtures/models-response');
var ModalStore = require('../../../stores/ModalStore');
var ContentStore = require('../../../stores/ContentStore');
var modalStartAction = require('../../../actions/modal').openModal;
var modalStopAction = require('../../../actions/modal').closeModal;
var modalUpdateAction = require('../../../actions/modal').updateComponent;
var serviceData = require('../../mocks/service-data');
var mockActionInterface = require('../../mocks').interface;

describe('modal action', function () {
  var context, params;

  before(function () {
    mockActionInterface.begin();
  });

  after(function () {
    mockActionInterface.end();
  });

  beforeEach(function () {
    params = JSON.parse(JSON.stringify(modelsResponse.Settings));
    context = createMockActionContext({
      stores: [ModalStore, ContentStore]
    });
    context.service = new MockService();
    context.service.setService('page', function (method, params, config, callback) {
      serviceData.fetch(params, callback);
    });
  });

  describe('start', function () {
    it('should update the ModalStore', function (done) {
      context.executeAction(modalStartAction, params, function (err) {
        if (err) {
          return done(err);
        }

        var modalStore = context.getStore(ModalStore),
            component = modalStore.getComponent(),
            props = modalStore.getProps(),
            isOpen = modalStore.getIsOpen();

        expect(isOpen).to.be.a('boolean').and.equal(true);
        expect(component).to.be.undefined;
        // this is content, models from service-data
        expect(props).to.be.an('object').with.property('content');

        done();
      });
    });

    it('should update the ContentStore', function (done) {
      context.executeAction(modalStartAction, params, function (err) {
        if (err) {
          return done(err);
        }

        var contentStore = context.getStore(ContentStore),
            content = contentStore.getCurrentPageContent(),
            models = contentStore.getCurrentPageModels();

        expect(content).to.exist.and.be.an('object');
        // this is models from fixture
        expect(models).to.eql(modelsResponse);

        done();
      });
    });
  });

  describe('stop', function () {
    it('should update the ModalStore', function (done) {
      context.executeAction(modalStopAction, params, function (err) {
        if (err) {
          return done(err);
        }

        var modalStore = context.getStore(ModalStore),
            isOpen = modalStore.getIsOpen();

        expect(isOpen).to.equal(false);
        done();
      });
    });
  });

  describe('update', function () {
    beforeEach(function () {
      params = {
        resource: 'key',
        component: {
          test: 'hello'
        }
      };
    });

    it('should update component', function (done) {
      context.executeAction(modalUpdateAction, params, function (err) {
        if (err) {
          return done(err);
        }

        var component, modalStore = context.getStore(ModalStore);

        modalStore.modalStart({
          component: params.resource
        });

        component = modalStore.getComponent();

        expect(component).to.eql(params.component);
        done();
      });
    });
  });
});
{'fraction_non_alphanumeric': 0.15387906446092414, 'fraction_numerical': 0.0011409013120365088, 'mean_word_length': 2.8052088985349974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3488097', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1866, 'n_words': 399}