mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
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:
@@ -36,7 +36,7 @@ const AlertManagerInput = observer(
|
||||
onChange = action((newValue, actionMeta) => {
|
||||
const { silenceFormStore } = this.props;
|
||||
|
||||
silenceFormStore.data.alertmanagers = newValue;
|
||||
silenceFormStore.data.alertmanagers = newValue || [];
|
||||
});
|
||||
|
||||
componentDidUpdate() {
|
||||
|
||||
@@ -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([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user