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

test: Functional RTL for email report modal II #16148

Merged
merged 12 commits into from
Aug 20, 2021
38 changes: 38 additions & 0 deletions superset-frontend/spec/fixtures/mockReportState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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 dashboardInfo from './mockDashboardInfo';
import { user } from '../javascripts/sqllab/fixtures';

export default {
active: true,
creation_method: 'dashboards',
crontab: '0 12 * * 1',
dashboard: dashboardInfo.id,
name: 'Weekly Report',
owners: [user.userId],
recipients: [
{
recipient_config_json: {
target: user.email,
},
type: 'Email',
},
],
type: 'Report',
};
46 changes: 46 additions & 0 deletions superset-frontend/spec/fixtures/mockStateWithoutUser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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 datasources from 'spec/fixtures/mockDatasource';
import messageToasts from 'spec/javascripts/messageToasts/mockMessageToasts';
import {
nativeFiltersInfo,
mockDataMaskInfo,
} from 'spec/javascripts/dashboard/fixtures/mockNativeFilters';
import chartQueries from 'spec/fixtures/mockChartQueries';
import { dashboardLayout } from 'spec/fixtures/mockDashboardLayout';
import dashboardInfo from 'spec/fixtures/mockDashboardInfo';
import { emptyFilters } from 'spec/fixtures/mockDashboardFilters';
import dashboardState from 'spec/fixtures/mockDashboardState';
import { sliceEntitiesForChart } from 'spec/fixtures/mockSliceEntities';
import reports from 'spec/fixtures/mockReportState';

export default {
datasources,
sliceEntities: sliceEntitiesForChart,
charts: chartQueries,
nativeFilters: nativeFiltersInfo,
dataMask: mockDataMaskInfo,
dashboardInfo,
dashboardFilters: emptyFilters,
dashboardState,
dashboardLayout,
messageToasts,
impressionId: 'mock_impression_id',
reports,
};
2 changes: 2 additions & 0 deletions superset-frontend/spec/helpers/reducerIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import saveModal from 'src/explore/reducers/saveModalReducer';
import explore from 'src/explore/reducers/exploreReducer';
import sqlLab from 'src/SqlLab/reducers/sqlLab';
import localStorageUsageInKilobytes from 'src/SqlLab/reducers/localStorageUsage';
import reports from 'src/reports/reducers/reports';

const impressionId = (state = '') => state;

Expand All @@ -53,5 +54,6 @@ export default {
explore,
sqlLab,
localStorageUsageInKilobytes,
reports,
common: () => common,
};

This file was deleted.

25 changes: 23 additions & 2 deletions superset-frontend/src/components/ReportModal/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ describe('Email Report Modal', () => {
(featureFlag: FeatureFlag) => featureFlag === FeatureFlag.ALERT_REPORTS,
);
});

beforeEach(() => {
render(<ReportModal {...defaultProps} />, { useRedux: true });
});

afterAll(() => {
// @ts-ignore
isFeatureEnabledMock.restore();
});
it('inputs respond correctly', () => {
render(<ReportModal {...defaultProps} />, { useRedux: true });

it('inputs respond correctly', () => {
// ----- Report name textbox
// Initial value
const reportNameTextbox = screen.getByTestId('report-name-test');
Expand All @@ -86,4 +90,21 @@ describe('Email Report Modal', () => {
const crontabInputs = screen.getAllByRole('combobox');
expect(crontabInputs).toHaveLength(5);
});

it('does not allow user to create a report without a name', () => {
// Grab name textbox and add button
const reportNameTextbox = screen.getByTestId('report-name-test');
const addButton = screen.getByRole('button', { name: /add/i });

// Add button should be enabled while name textbox has text
expect(reportNameTextbox).toHaveDisplayValue('Weekly Report');
expect(addButton).toBeEnabled();

// Clear the text from the name textbox
userEvent.clear(reportNameTextbox);

// Add button should now be disabled, blocking user from creation
expect(reportNameTextbox).toHaveDisplayValue('');
expect(addButton).toBeDisabled();
});
});
2 changes: 1 addition & 1 deletion superset-frontend/src/components/ReportModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
StyledRadioGroup,
} from './styles';

interface ReportObject {
export interface ReportObject {
id?: number;
active: boolean;
crontab: string;
Expand Down
Loading