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

refactor: Refactor reports for Charts and Dashboards #19130

Merged
merged 50 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
703d9b2
bumping shillelagh
AAfghahi Apr 14, 2022
a17c357
Merge branch 'master' of ssh://github.com/apache/superset
AAfghahi Apr 18, 2022
6b3637b
pexdax refactor (#16333)
AAfghahi Aug 18, 2021
eef744a
refactor progress (#16339)
lyndsiWilliams Aug 19, 2021
d374c5a
fix: Header Actions test refactor (#16336)
AAfghahi Aug 19, 2021
18cd426
code dry (#16358)
AAfghahi Aug 20, 2021
f669bf9
Fetch bug fixed (#16376)
lyndsiWilliams Aug 20, 2021
03d8a56
continued refactoring (#16377)
AAfghahi Aug 20, 2021
ca3ce71
pexdax refactor (#16333)
AAfghahi Aug 18, 2021
88feac5
refactor progress (#16339)
lyndsiWilliams Aug 19, 2021
7a2a39f
fix: Header Actions test refactor (#16336)
AAfghahi Aug 19, 2021
7dcd07b
code dry (#16358)
AAfghahi Aug 20, 2021
70b1d36
Fetch bug fixed (#16376)
lyndsiWilliams Aug 20, 2021
e807bde
continued refactoring (#16377)
AAfghahi Aug 20, 2021
6966907
refactor: Arash/new state report (#16987)
AAfghahi Oct 28, 2021
046e3aa
refactor: Reports code clean 10-29 (#17424)
lyndsiWilliams Nov 19, 2021
e281462
fix(Explore): Remove changes to the properties on cancel (#17184)
geido Nov 2, 2021
44d3d68
fix(dashboard): don't show report modal for anonymous user (#17106)
mayurnewase Nov 11, 2021
e88e474
fix(explore): Metric control breaks when saved metric deleted from da…
kgabryje Nov 24, 2021
6168cf2
Add functionality is now working (#17578)
lyndsiWilliams Dec 7, 2021
1d5121e
Preset io ch28954 refactor reports (#19129)
AAfghahi Mar 11, 2022
2c4895e
deleted additional folder
AAfghahi Mar 11, 2022
586962f
fixing tests
AAfghahi Mar 11, 2022
8074f9c
all but styling
AAfghahi Apr 27, 2022
79c5ab8
Merge branch 'master' into refactorReports
AAfghahi Apr 29, 2022
05251eb
bumping shillelagh
AAfghahi Apr 14, 2022
85f0777
pexdax refactor (#16333)
AAfghahi Aug 18, 2021
847fbe5
refactor progress (#16339)
lyndsiWilliams Aug 19, 2021
5b0adc4
fix: Header Actions test refactor (#16336)
AAfghahi Aug 19, 2021
3e15c54
code dry (#16358)
AAfghahi Aug 20, 2021
f2be4bc
Fetch bug fixed (#16376)
lyndsiWilliams Aug 20, 2021
473c603
continued refactoring (#16377)
AAfghahi Aug 20, 2021
616a35d
pexdax refactor (#16333)
AAfghahi Aug 18, 2021
2a4b38d
refactor progress (#16339)
lyndsiWilliams Aug 19, 2021
49ec8e5
fix: Header Actions test refactor (#16336)
AAfghahi Aug 19, 2021
0a89c1b
code dry (#16358)
AAfghahi Aug 20, 2021
2eb5c8f
Fetch bug fixed (#16376)
lyndsiWilliams Aug 20, 2021
e8ec94d
continued refactoring (#16377)
AAfghahi Aug 20, 2021
3904e6b
refactor: Arash/new state report (#16987)
AAfghahi Oct 28, 2021
a355dfc
refactor: Reports code clean 10-29 (#17424)
lyndsiWilliams Nov 19, 2021
5844998
fix(Explore): Remove changes to the properties on cancel (#17184)
geido Nov 2, 2021
db6821a
fix(dashboard): don't show report modal for anonymous user (#17106)
mayurnewase Nov 11, 2021
0476b80
fix(explore): Metric control breaks when saved metric deleted from da…
kgabryje Nov 24, 2021
6b457e9
Add functionality is now working (#17578)
lyndsiWilliams Dec 7, 2021
3063cae
Preset io ch28954 refactor reports (#19129)
AAfghahi Mar 11, 2022
6f45dc7
deleted additional folder
AAfghahi Mar 11, 2022
0a5d8eb
fixing tests
AAfghahi Mar 11, 2022
e0dae4a
all but styling
AAfghahi Apr 27, 2022
b69390e
merge into master
AAfghahi May 9, 2022
18e51d9
fixed tests
AAfghahi May 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

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: 'admin@test.com',
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: 'admin@test.com',
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: 'admin@test.com',
},
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