Skip to content

Commit

Permalink
fix: Unable to select None for Alert's log retention (#17268)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Nov 3, 2021
1 parent 33bcf82 commit 85a19a9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
42 changes: 42 additions & 0 deletions superset-frontend/src/views/CRUD/alert/AlertReportModal.test.tsx
Original file line number Diff line number Diff line change
@@ -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(<AlertReportModal show />, { 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');
});
6 changes: 5 additions & 1 deletion superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,11 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
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')}
/>
Expand Down

0 comments on commit 85a19a9

Please sign in to comment.