fix(ui): don't crash when removing last Alertmanager instance

Removing last value sets the value that's expected to be a list to null, which breaks some logic, ensure we always have a list there.

Fixes #826
This commit is contained in:
Łukasz Mierzwa
2019-07-14 21:49:51 +01:00
parent 5c990eee79
commit 6152067ce1
2 changed files with 16 additions and 1 deletions

View File

@@ -36,7 +36,7 @@ const AlertManagerInput = observer(
onChange = action((newValue, actionMeta) => {
const { silenceFormStore } = this.props;
silenceFormStore.data.alertmanagers = newValue;
silenceFormStore.data.alertmanagers = newValue || [];
});
componentDidUpdate() {

View File

@@ -174,4 +174,19 @@ describe("<AlertManagerInput />", () => {
const select = tree.find("StateManager");
expect(select.props().isDisabled).toBe(true);
});
it("removing last options sets silenceFormStore.data.alertmanagers to []", () => {
const tree = MountedAlertManagerInput();
expect(silenceFormStore.data.alertmanagers).toHaveLength(2);
tree
.find(".react-select__multi-value__remove")
.at(0)
.simulate("click");
expect(silenceFormStore.data.alertmanagers).toHaveLength(1);
tree.find(".react-select__multi-value__remove").simulate("click");
expect(silenceFormStore.data.alertmanagers).toHaveLength(0);
expect(silenceFormStore.data.alertmanagers).toEqual([]);
});
});