Skip to content

Commit

Permalink
refactor: Refactor reports for Charts and Dashboards (apache#19130)
Browse files Browse the repository at this point in the history
* bumping shillelagh

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Arash/new state report (apache#16987)

* code dry (apache#16358)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor(reports): Arash/refactor reports (apache#16855)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Reports - ReportModal (apache#16622)

* refactoring progress

* removed consoles

* Working, but with 2 fetches

* report pickup

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* refactor(reports):  Arash/again refactor reports (apache#16872)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Reports - ReportModal (apache#16622)

* refactoring progress

* removed consoles

* Working, but with 2 fetches

* it is still not working

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* next changes

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* refactor: Reports code clean 10-29 (apache#17424)

* Add delete functionality

* Report schema restructure progress

* Fix lint

* Removed console.log

* fix(Explore): Remove changes to the properties on cancel (apache#17184)

* Remove on close

* Fix lint

* Add tests

* fix(dashboard): don't show report modal for anonymous user (apache#17106)

* Added sunburst echart

* fix(dashboard):Hide reports modal for anonymous users

* Address comments

* Make prettier happy

Co-authored-by: Mayur <[email protected]>

* fix(explore): Metric control breaks when saved metric deleted from dataset (apache#17503)

* Add functionality is now working (apache#17578)

* Preset io ch28954 refactor reports (apache#19129)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Arash/new state report (apache#16987)

* code dry (apache#16358)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor(reports): Arash/refactor reports (apache#16855)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Reports - ReportModal (apache#16622)

* refactoring progress

* removed consoles

* Working, but with 2 fetches

* report pickup

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* refactor(reports):  Arash/again refactor reports (apache#16872)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Reports - ReportModal (apache#16622)

* refactoring progress

* removed consoles

* Working, but with 2 fetches

* it is still not working

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* next changes

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* refactor: Reports code clean 10-29 (apache#17424)

* Add delete functionality

* Report schema restructure progress

* Fix lint

* Removed console.log

* fix(Explore): Remove changes to the properties on cancel (apache#17184)

* Remove on close

* Fix lint

* Add tests

* fix(dashboard): don't show report modal for anonymous user (apache#17106)

* Added sunburst echart

* fix(dashboard):Hide reports modal for anonymous users

* Address comments

* Make prettier happy

Co-authored-by: Mayur <[email protected]>

* fix(explore): Metric control breaks when saved metric deleted from dataset (apache#17503)

* Add functionality is now working (apache#17578)

* refactoring reports

* ready for review

* added testing

* removed user reducer

* elizabeth suggestions

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>
Co-authored-by: Geido <[email protected]>
Co-authored-by: Mayur <[email protected]>
Co-authored-by: Mayur <[email protected]>
Co-authored-by: Kamil Gabryjelski <[email protected]>

* deleted additional folder

* fixing tests

* all but styling

* bumping shillelagh

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Arash/new state report (apache#16987)

* code dry (apache#16358)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor(reports): Arash/refactor reports (apache#16855)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Reports - ReportModal (apache#16622)

* refactoring progress

* removed consoles

* Working, but with 2 fetches

* report pickup

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* refactor(reports):  Arash/again refactor reports (apache#16872)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Reports - ReportModal (apache#16622)

* refactoring progress

* removed consoles

* Working, but with 2 fetches

* it is still not working

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* next changes

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* refactor: Reports code clean 10-29 (apache#17424)

* Add delete functionality

* Report schema restructure progress

* Fix lint

* Removed console.log

* fix(Explore): Remove changes to the properties on cancel (apache#17184)

* Remove on close

* Fix lint

* Add tests

* fix(dashboard): don't show report modal for anonymous user (apache#17106)

* Added sunburst echart

* fix(dashboard):Hide reports modal for anonymous users

* Address comments

* Make prettier happy

Co-authored-by: Mayur <[email protected]>

* fix(explore): Metric control breaks when saved metric deleted from dataset (apache#17503)

* Add functionality is now working (apache#17578)

* Preset io ch28954 refactor reports (apache#19129)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Arash/new state report (apache#16987)

* code dry (apache#16358)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor(reports): Arash/refactor reports (apache#16855)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Reports - ReportModal (apache#16622)

* refactoring progress

* removed consoles

* Working, but with 2 fetches

* report pickup

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* refactor(reports):  Arash/again refactor reports (apache#16872)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Reports - ReportModal (apache#16622)

* refactoring progress

* removed consoles

* Working, but with 2 fetches

* it is still not working

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* next changes

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* refactor: Reports code clean 10-29 (apache#17424)

* Add delete functionality

* Report schema restructure progress

* Fix lint

* Removed console.log

* fix(Explore): Remove changes to the properties on cancel (apache#17184)

* Remove on close

* Fix lint

* Add tests

* fix(dashboard): don't show report modal for anonymous user (apache#17106)

* Added sunburst echart

* fix(dashboard):Hide reports modal for anonymous users

* Address comments

* Make prettier happy

Co-authored-by: Mayur <[email protected]>

* fix(explore): Metric control breaks when saved metric deleted from dataset (apache#17503)

* Add functionality is now working (apache#17578)

* refactoring reports

* ready for review

* added testing

* removed user reducer

* elizabeth suggestions

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>
Co-authored-by: Geido <[email protected]>
Co-authored-by: Mayur <[email protected]>
Co-authored-by: Mayur <[email protected]>
Co-authored-by: Kamil Gabryjelski <[email protected]>

* deleted additional folder

* fixing tests

* all but styling

* fixed tests

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>
Co-authored-by: Geido <[email protected]>
Co-authored-by: Mayur <[email protected]>
Co-authored-by: Mayur <[email protected]>
Co-authored-by: Kamil Gabryjelski <[email protected]>
7 people authored and philipher29 committed Jun 9, 2022
1 parent 14457af commit ea37284
Showing 25 changed files with 832 additions and 767 deletions.
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ describe('Dashboard edit action', () => {
.click()
.then(() => {
// assert that modal edit window has closed
cy.get('.ant-modal-body').should('not.be.visible');
cy.get('.ant-modal-body').should('not.exist');

// assert title has been updated
cy.get('.editable-title input').should('have.value', dashboardTitle);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/**
* 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 * as React from 'react';
import userEvent from '@testing-library/user-event';
import { render, screen, act } from 'spec/helpers/testing-library';
import * as featureFlags from '@superset-ui/core';
import HeaderReportDropdown, { HeaderReportProps } from '.';

let isFeatureEnabledMock: jest.MockInstance<boolean, [string]>;

const createProps = () => ({
dashboardId: 1,
useTextMenu: false,
isDropdownVisible: false,
setIsDropdownVisible: jest.fn,
setShowReportSubMenu: jest.fn,
});

const stateWithOnlyUser = {
explore: {
user: {
email: '[email protected]',
firstName: 'admin',
isActive: true,
lastName: 'admin',
permissions: {},
createdOn: '2022-01-12T10:17:37.801361',
roles: { Admin: [['menu_access', 'Manage']] },
userId: 1,
username: 'admin',
},
},
reports: {},
};

const stateWithUserAndReport = {
explore: {
user: {
email: '[email protected]',
firstName: 'admin',
isActive: true,
lastName: 'admin',
permissions: {},
createdOn: '2022-01-12T10:17:37.801361',
roles: { Admin: [['menu_access', 'Manage']] },
userId: 1,
username: 'admin',
},
},
reports: {
dashboards: {
1: {
id: 1,
result: {
active: true,
creation_method: 'dashboards',
crontab: '0 12 * * 1',
dashboard: 1,
name: 'Weekly Report',
owners: [1],
recipients: [
{
recipient_config_json: {
target: '[email protected]',
},
type: 'Email',
},
],
type: 'Report',
},
},
},
},
};

function setup(props: HeaderReportProps, initialState = {}) {
render(
<div>
<HeaderReportDropdown {...props} />
</div>,
{ useRedux: true, initialState },
);
}

describe('Header Report Dropdown', () => {
beforeAll(() => {
isFeatureEnabledMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
.mockImplementation(
(featureFlag: featureFlags.FeatureFlag) =>
featureFlag === featureFlags.FeatureFlag.ALERT_REPORTS,
);
});

afterAll(() => {
// @ts-ignore
isFeatureEnabledMock.restore();
});

it('renders correctly', () => {
const mockedProps = createProps();
act(() => {
setup(mockedProps, stateWithUserAndReport);
});
expect(screen.getByRole('button')).toBeInTheDocument();
});

it('renders the dropdown correctly', () => {
const mockedProps = createProps();
act(() => {
setup(mockedProps, stateWithUserAndReport);
});
const emailReportModalButton = screen.getByRole('button');
userEvent.click(emailReportModalButton);
expect(screen.getByText('Email reports active')).toBeInTheDocument();
expect(screen.getByText('Edit email report')).toBeInTheDocument();
expect(screen.getByText('Delete email report')).toBeInTheDocument();
});

it('opens an edit modal', async () => {
const mockedProps = createProps();
act(() => {
setup(mockedProps, stateWithUserAndReport);
});
const emailReportModalButton = screen.getByRole('button');
userEvent.click(emailReportModalButton);
const editModal = screen.getByText('Edit email report');
userEvent.click(editModal);
const textBoxes = await screen.findAllByText('Edit email report');
expect(textBoxes).toHaveLength(2);
});

it('opens a delete modal', () => {
const mockedProps = createProps();
act(() => {
setup(mockedProps, stateWithUserAndReport);
});
const emailReportModalButton = screen.getByRole('button');
userEvent.click(emailReportModalButton);
const deleteModal = screen.getByText('Delete email report');
userEvent.click(deleteModal);
expect(screen.getByText('Delete Report?')).toBeInTheDocument();
});

it('renders a new report modal if there is no report', () => {
const mockedProps = createProps();
act(() => {
setup(mockedProps, stateWithOnlyUser);
});
const emailReportModalButton = screen.getByRole('button');
userEvent.click(emailReportModalButton);
expect(screen.getByText('Schedule a new email report')).toBeInTheDocument();
});

it('renders Manage Email Reports Menu if textMenu is set to true and there is a report', () => {
let mockedProps = createProps();
mockedProps = {
...mockedProps,
useTextMenu: true,
isDropdownVisible: true,
};
act(() => {
setup(mockedProps, stateWithUserAndReport);
});
expect(screen.getByText('Email reports active')).toBeInTheDocument();
expect(screen.getByText('Edit email report')).toBeInTheDocument();
expect(screen.getByText('Delete email report')).toBeInTheDocument();
});

it('renders Schedule Email Reports if textMenu is set to true and there is a report', () => {
let mockedProps = createProps();
mockedProps = {
...mockedProps,
useTextMenu: true,
isDropdownVisible: true,
};
act(() => {
setup(mockedProps, stateWithOnlyUser);
});
expect(screen.getByText('Set up an email report')).toBeInTheDocument();
});
});
Loading

0 comments on commit ea37284

Please sign in to comment.