mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
FeatureForm should support viewing deleted strategies
This commit is contained in:
parent
c16f4a1867
commit
c82e45b148
@ -1,8 +1,8 @@
|
||||
/** @jsx React.DOM */
|
||||
|
||||
jest.dontMock("../components/Menu");
|
||||
jest.dontMock("../../components/Menu");
|
||||
|
||||
var Menu = require("../components/Menu");
|
||||
var Menu = require("../../components/Menu");
|
||||
var React = require("react/addons");
|
||||
var TestUtils = React.addons.TestUtils;
|
||||
|
47
public/js/__tests__/components/feature/FeatureForm-test.js
Normal file
47
public/js/__tests__/components/feature/FeatureForm-test.js
Normal file
@ -0,0 +1,47 @@
|
||||
jest.dontMock("../../../components/feature/FeatureForm");
|
||||
|
||||
var React = require("react/addons");
|
||||
var TestUtils = React.addons.TestUtils;
|
||||
var FeatureForm = require("../../../components/feature/FeatureForm");
|
||||
var strategyStore = require("../../../stores/StrategyStore");
|
||||
|
||||
describe("FeatureForm", function () {
|
||||
var Component;
|
||||
beforeEach(function() {
|
||||
strategyStore.getStrategies.mockImplementation(function() {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return callback({
|
||||
strategies: [
|
||||
{ name: "default"}
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
React.unmountComponentAtNode(document.body);
|
||||
});
|
||||
|
||||
describe("new", function () {
|
||||
it("should render empty form", function() {
|
||||
Component = TestUtils .renderIntoDocument(<FeatureForm />);
|
||||
var name = Component.getDOMNode().querySelectorAll("input");
|
||||
expect(name[0].value).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe("edit", function () {
|
||||
var feature = {name: "Test", strategy: "unknown"};
|
||||
|
||||
it("should show unknown strategy as deleted", function () {
|
||||
Component = TestUtils .renderIntoDocument(<FeatureForm feature={feature} />);
|
||||
|
||||
var strategySelect = Component.getDOMNode().querySelector("select");
|
||||
expect(strategySelect.value).toEqual("unknown (deleted)");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@ -1,5 +1,5 @@
|
||||
var React = require('react');
|
||||
var TextInput = require('../form/TextInput');
|
||||
var TextInput = require('../form/TextInput');
|
||||
var strategyStore = require('../../stores/StrategyStore');
|
||||
|
||||
var FeatureForm = React.createClass({
|
||||
@ -36,20 +36,30 @@ var FeatureForm = React.createClass({
|
||||
},
|
||||
|
||||
setSelectedStrategy: function(name) {
|
||||
var selected = this.state.strategyOptions.filter(function(strategy) {
|
||||
var selectedStrategy = this.state.strategyOptions.filter(function(strategy) {
|
||||
return strategy.name === name;
|
||||
});
|
||||
})[0];
|
||||
|
||||
if(selectedStrategy) {
|
||||
if(selectedStrategy.parametersTemplate) {
|
||||
this.setStrategyParams(selectedStrategy);
|
||||
}
|
||||
} else {
|
||||
var updatedStrategyName = name + " (deleted)";
|
||||
this.setState({
|
||||
currentStrategy: updatedStrategyName,
|
||||
strategyOptions: this.state.strategyOptions.concat([{name: updatedStrategyName}])
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
setStrategyParams: function(strategy) {
|
||||
var requiredParams = [];
|
||||
var key;
|
||||
|
||||
if(selected[0] && selected[0].parametersTemplate) {
|
||||
for(key in selected[0].parametersTemplate) {
|
||||
requiredParams.push({name: key, value: this.getParameterValue(key)});
|
||||
}
|
||||
for(key in strategy.parametersTemplate) {
|
||||
requiredParams.push({name: key, value: this.getParameterValue(key)});
|
||||
}
|
||||
this.setState({requiredParams: requiredParams});
|
||||
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
Loading…
Reference in New Issue
Block a user