1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

Added test for the FeatureToggleStore

This commit is contained in:
ivaosthu 2015-03-23 17:35:58 +01:00 committed by Ivar Conradi Østhus
parent 920712f8fe
commit 1cd22badfa
3 changed files with 83 additions and 3 deletions

View File

@ -75,7 +75,8 @@
"jest": {
"scriptPreprocessor": "<rootDir>/jest-preprocessor.js",
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react"
"<rootDir>/node_modules/react",
"<rootDir>/node_modules/reflux"
],
"moduleFileExtensions": [
"jsx",

View File

@ -0,0 +1,81 @@
jest.autoMockOff()
jest.dontMock('../../stores/FeatureToggleActions');
jest.dontMock('../../stores/FeatureToggleStore');
describe('FeatureToggleStore', function() {
var Actions, Store, toggles;
beforeEach(function() {
Actions = require('../../stores/FeatureToggleActions');
Store = require('../../stores/FeatureToggleStore');
toggles = [
{name: "app.feature", enabled: true, strategy: "default"}
];
});
it('should be an empty store', function() {
expect(Store.getFeatureToggles().length).toBe(0);
});
it('should inititialize the store', function() {
Actions.init.completed(toggles);
jest.runAllTimers();
expect(Store.getFeatureToggles().length).toBe(1);
expect(Store.getFeatureToggles()[0].name).toEqual("app.feature");
});
it('should add a another toggle', function() {
Actions.init.completed(toggles);
var newToggle = {name: "app.featureB", enabled: true, strategy: "default"};
Actions.create.completed(newToggle);
jest.runAllTimers();
expect(Store.getFeatureToggles().length).toBe(2);
expect(Store.getFeatureToggles()[1].name).toEqual("app.featureB");
});
it('should archive toggle', function() {
Actions.init.completed(toggles);
Actions.archive.completed(toggles[0]);
jest.runAllTimers();
expect(Store.getFeatureToggles().length).toBe(0);
});
it('should keep toggles in sorted order', function() {
Actions.init.completed([
{name: "A"},
{name: "B"},
{name: "C"}
]);
Actions.create.completed({name: "AA"});
jest.runAllTimers();
expect(Store.getFeatureToggles()[0].name).toEqual("A");
expect(Store.getFeatureToggles()[1].name).toEqual("AA");
expect(Store.getFeatureToggles()[3].name).toEqual("C");
});
it('should update toggle', function() {
Actions.init.completed(toggles);
var toggle = toggles[0];
toggle.enabled = false;
Actions.update.completed(toggle);
jest.runAllTimers();
expect(Store.getFeatureToggles()[0].enabled).toEqual(false);
});
});

View File

@ -6,9 +6,7 @@ var findIndex = require('lodash/array/findIndex');
var _featureToggles = [];
// Creates a DataStore
var FeatureStore = Reflux.createStore({
//The store should be split in two: toggleStore && archivedToggleStore!
// Initial setup
init: function() {