|
|
|
@ -78,7 +78,7 @@ const ui = { |
|
|
|
|
confirmButton: byRole('button', { name: /Yes, reset configuration/ }), |
|
|
|
|
resetButton: byRole('button', { name: /Reset configuration/ }), |
|
|
|
|
saveButton: byRole('button', { name: /Save/ }), |
|
|
|
|
configInput: byLabelText<HTMLTextAreaElement>(/Configuration/), |
|
|
|
|
configInput: byLabelText(/Code editor container/), |
|
|
|
|
readOnlyConfig: byTestId('readonly-config'), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -107,37 +107,29 @@ describe('Admin config', () => { |
|
|
|
|
expect(ui.confirmButton.query()).not.toBeInTheDocument(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('Edit and save alertmanager config', async () => { |
|
|
|
|
it('Editable alertmanager config', async () => { |
|
|
|
|
let savedConfig: AlertManagerCortexConfig | undefined = undefined; |
|
|
|
|
|
|
|
|
|
const defaultConfig = { |
|
|
|
|
template_files: { |
|
|
|
|
foo: 'bar', |
|
|
|
|
template_files: {}, |
|
|
|
|
alertmanager_config: { |
|
|
|
|
route: { |
|
|
|
|
receiver: 'old one', |
|
|
|
|
}, |
|
|
|
|
alertmanager_config: {}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const newConfig = { |
|
|
|
|
template_files: { |
|
|
|
|
bar: 'baz', |
|
|
|
|
}, |
|
|
|
|
alertmanager_config: {}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
mocks.api.fetchConfig.mockImplementation(() => Promise.resolve(savedConfig ?? defaultConfig)); |
|
|
|
|
mocks.api.updateAlertManagerConfig.mockResolvedValue(); |
|
|
|
|
renderAdminPage(dataSources.alertManager.name); |
|
|
|
|
const input = await ui.configInput.find(); |
|
|
|
|
expect(input.value).toEqual(JSON.stringify(defaultConfig, null, 2)); |
|
|
|
|
await userEvent.clear(input); |
|
|
|
|
// What is this regex replace doing? in userEvent v13, '{' and '[' are special characters.
|
|
|
|
|
// To get the literal character, you have to escape them by typing '{{' or '[['.
|
|
|
|
|
// See https://github.com/testing-library/user-event/issues/584.
|
|
|
|
|
await userEvent.type(input, JSON.stringify(newConfig, null, 2).replace(/[{[]/g, '$&$&')); |
|
|
|
|
|
|
|
|
|
await ui.configInput.find(); |
|
|
|
|
await userEvent.click(ui.saveButton.get()); |
|
|
|
|
|
|
|
|
|
await waitFor(() => expect(mocks.api.updateAlertManagerConfig).toHaveBeenCalled()); |
|
|
|
|
expect(mocks.api.updateAlertManagerConfig.mock.lastCall).toMatchSnapshot(); |
|
|
|
|
|
|
|
|
|
await waitFor(() => expect(mocks.api.fetchConfig).toHaveBeenCalledTimes(3)); |
|
|
|
|
expect(input.value).toEqual(JSON.stringify(newConfig, null, 2)); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('Read-only when using Prometheus Alertmanager', async () => { |
|
|
|
@ -148,7 +140,6 @@ describe('Admin config', () => { |
|
|
|
|
renderAdminPage(dataSources.promAlertManager.name); |
|
|
|
|
|
|
|
|
|
await ui.readOnlyConfig.find(); |
|
|
|
|
expect(ui.configInput.query()).not.toBeInTheDocument(); |
|
|
|
|
expect(ui.resetButton.query()).not.toBeInTheDocument(); |
|
|
|
|
expect(ui.saveButton.query()).not.toBeInTheDocument(); |
|
|
|
|
|
|
|
|
|