From 713ea8168f34e7921e30321ad32b1089901b38a8 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Thu, 28 Oct 2021 11:54:24 -0300 Subject: [PATCH] fix: Unable to select None for Alert's log retention --- .../CRUD/alert/AlertReportModal.test.tsx | 42 +++++++++++++++++++ .../src/views/CRUD/alert/AlertReportModal.tsx | 6 ++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 superset-frontend/src/views/CRUD/alert/AlertReportModal.test.tsx diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.test.tsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.test.tsx new file mode 100644 index 0000000000000..8eeea3d45bcd8 --- /dev/null +++ b/superset-frontend/src/views/CRUD/alert/AlertReportModal.test.tsx @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React from 'react'; +import { render, screen, waitFor } from 'spec/helpers/testing-library'; +import userEvent from '@testing-library/user-event'; +import AlertReportModal from 'src/views/CRUD/alert/AlertReportModal'; + +test('allows change to None in log retention', async () => { + render(, { useRedux: true }); + // open the log retention select + userEvent.click(screen.getByText('90 days')); + // change it to 30 days + userEvent.click(await screen.findByText('30 days')); + // open again + userEvent.click(screen.getAllByText('30 days')[0]); + // change it to None + userEvent.click(await screen.findByText('None')); + // get the selected item + const selectedItem = await waitFor(() => + screen + .getAllByLabelText('Log retention')[0] + .querySelector('.ant-select-selection-item'), + ); + // check if None is selected + expect(selectedItem).toHaveTextContent('None'); +}); diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx index c8c4df66a5dd3..0436cac5726f2 100644 --- a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx +++ b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx @@ -1220,7 +1220,11 @@ const AlertReportModal: FunctionComponent = ({ ariaLabel={t('Log retention')} placeholder={t('Log retention')} onChange={onLogRetentionChange} - value={currentAlert?.log_retention || DEFAULT_RETENTION} + value={ + typeof currentAlert?.log_retention === 'number' + ? currentAlert?.log_retention + : DEFAULT_RETENTION + } options={RETENTION_OPTIONS} sortComparator={propertyComparator('value')} />