Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/Components/SilenceModal/AlertManagerInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const AlertManagerInput = observer(
onChange = action((newValue, actionMeta) => {
const { silenceFormStore } = this.props;

silenceFormStore.data.alertmanagers = newValue;
silenceFormStore.data.alertmanagers = newValue || [];
});

componentDidUpdate() {
Expand Down
15 changes: 15 additions & 0 deletions ui/src/Components/SilenceModal/AlertManagerInput/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});
});