Skip to content

Commit

Permalink
chore: E2E Dashboards Cross-references (#21805)
Browse files Browse the repository at this point in the history
  • Loading branch information
geido authored Oct 21, 2022
1 parent 40f8254 commit 2fe68a3
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 22 deletions.
20 changes: 12 additions & 8 deletions superset-frontend/cypress-base/cypress/fixtures/charts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,38 @@
"owners": [1],
"viz_type": "line",
"cache_timeout": 1000,
"datasource_id": 1,
"datasource_type": "table"
"datasource_id": 2,
"datasource_type": "table",
"params": "{\"viz_type\":\"line\",\"metrics\":[\"count\"]}"
},
{
"slice_name": "2 - Sample chart",
"description": "chart description",
"owners": [1],
"viz_type": "line",
"cache_timeout": 1000,
"datasource_id": 1,
"datasource_type": "table"
"datasource_id": 2,
"datasource_type": "table",
"params": "{\"viz_type\":\"line\",\"metrics\":[\"count\"]}"
},
{
"slice_name": "3 - Sample chart",
"description": "chart description",
"owners": [1],
"viz_type": "line",
"cache_timeout": 1000,
"datasource_id": 1,
"datasource_type": "table"
"datasource_id": 2,
"datasource_type": "table",
"params": "{\"viz_type\":\"line\",\"metrics\":[\"count\"]}"
},
{
"slice_name": "4 - Sample chart",
"description": "chart description",
"owners": [1],
"viz_type": "line",
"cache_timeout": 1000,
"datasource_id": 1,
"datasource_type": "table"
"datasource_id": 2,
"datasource_type": "table",
"params": "{\"viz_type\":\"line\",\"metrics\":[\"count\"]}"
}
]
28 changes: 28 additions & 0 deletions superset-frontend/cypress-base/cypress/fixtures/dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,33 @@
{
"dashboard_title": "4 - Sample dashboard",
"slug": "4-sample-dashboard"
},
{
"dashboard_title": "5 - Sample dashboard",
"slug": "5-sample-dashboard"
},
{
"dashboard_title": "6 - Sample dashboard",
"slug": "6-sample-dashboard"
},
{
"dashboard_title": "7 - Sample dashboard",
"slug": "7-sample-dashboard"
},
{
"dashboard_title": "8 - Sample dashboard",
"slug": "8-sample-dashboard"
},
{
"dashboard_title": "9 - Sample dashboard",
"slug": "9-sample-dashboard"
},
{
"dashboard_title": "10 - Sample dashboard",
"slug": "10-sample-dashboard"
},
{
"dashboard_title": "11 - Sample dashboard",
"slug": "11-sample-dashboard"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import {
interceptBulkDelete,
interceptUpdate,
interceptDelete,
visitSampleChartFromList,
saveChartToDashboard,
interceptFiltering,
} from '../explore/utils';
import { interceptGet as interceptDashboardGet } from '../dashboard/utils';

function orderAlphabetical() {
setFilter('Sort', 'Alphabetical');
Expand All @@ -43,14 +47,69 @@ function confirmDelete() {
cy.getBySel('modal-confirm-button').click();
}

function visitChartList() {
interceptFiltering();
cy.visit(CHART_LIST);
cy.wait('@filtering');
}

describe('Charts list', () => {
beforeEach(() => {
cy.preserveLogin();
});

describe('Cross-referenced dashboards', () => {
beforeEach(() => {
visitChartList();
});

before(() => {
cy.createSampleDashboards([0, 1, 2, 3]);
cy.createSampleCharts([0]);
});

it('should show the cross-referenced dashboards in the table cell', () => {
interceptDashboardGet();
cy.getBySel('table-row')
.first()
.find('[data-test="table-row-cell"]')
.find('[data-test="crosslinks"]')
.should('be.empty');
cy.getBySel('table-row')
.eq(10)
.find('[data-test="table-row-cell"]')
.find('[data-test="crosslinks"]')
.contains('Supported Charts Dashboard')
.invoke('removeAttr', 'target')
.click();
cy.wait('@get');
});

it('should show the newly added dashboards in a tooltip', () => {
interceptDashboardGet();
visitSampleChartFromList('1 - Sample chart');
saveChartToDashboard('1 - Sample dashboard');
saveChartToDashboard('2 - Sample dashboard');
saveChartToDashboard('3 - Sample dashboard');
saveChartToDashboard('4 - Sample dashboard');
visitChartList();
cy.getBySel('count-crosslinks').should('be.visible');
cy.getBySel('crosslinks')
.first()
.trigger('mouseover')
.then(() => {
cy.get('.ant-tooltip')
.contains('4 - Sample dashboard')
.invoke('removeAttr', 'target')
.click();
cy.wait('@get');
});
});
});

describe('list mode', () => {
before(() => {
cy.visit(CHART_LIST);
visitChartList();
setGridMode('list');
});

Expand Down Expand Up @@ -94,7 +153,7 @@ describe('Charts list', () => {

describe('card mode', () => {
before(() => {
cy.visit(CHART_LIST);
visitChartList();
setGridMode('card');
});

Expand Down Expand Up @@ -126,8 +185,8 @@ describe('Charts list', () => {

describe('common actions', () => {
beforeEach(() => {
cy.createSampleCharts();
cy.visit(CHART_LIST);
cy.createSampleCharts([0, 1, 2, 3]);
visitChartList();
});

it('should allow to favorite/unfavorite', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { interceptFav, interceptUnfav } from './utils';

describe('Dashboard actions', () => {
beforeEach(() => {
cy.createSampleDashboards();
cy.createSampleDashboards([0]);
cy.visit(SAMPLE_DASHBOARD_1);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ describe('Dashboard edit', () => {

describe('Edit properties', () => {
before(() => {
cy.createSampleDashboards();
cy.createSampleDashboards([0]);
visitEdit();
});

Expand Down Expand Up @@ -700,7 +700,7 @@ describe('Dashboard edit', () => {

describe('Edit mode', () => {
before(() => {
cy.createSampleDashboards();
cy.createSampleDashboards([0]);
visitEdit();
});

Expand Down Expand Up @@ -737,7 +737,7 @@ describe('Dashboard edit', () => {

describe('Components', () => {
before(() => {
cy.createSampleDashboards();
cy.createSampleDashboards([0]);
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('Native filters', () => {

describe('Nativefilters tests initial state required', () => {
beforeEach(() => {
cy.createSampleDashboards();
cy.createSampleDashboards([0]);
});

it('Verify that default value is respected after revisit', () => {
Expand Down Expand Up @@ -379,7 +379,7 @@ describe('Native filters', () => {

describe('Nativefilters basic interactions', () => {
before(() => {
cy.createSampleDashboards();
cy.createSampleDashboards([0]);
visitDashboard();
});

Expand Down Expand Up @@ -437,7 +437,7 @@ describe('Native filters', () => {

describe('Nativefilters initial state not required', () => {
beforeEach(() => {
cy.createSampleDashboards();
cy.createSampleDashboards([0]);
});

it("User can check 'Filter has default value'", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('Dashboards list', () => {

describe('common actions', () => {
beforeEach(() => {
cy.createSampleDashboards();
cy.createSampleDashboards([0, 1, 2, 3]);
cy.visit(DASHBOARD_LIST);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,113 @@
* specific language governing permissions and limitations
* under the License.
*/
import { CHART_LIST } from 'cypress/utils/urls';
import { interceptGet as interceptDashboardGet } from 'cypress/integration/dashboard/utils';
import { FORM_DATA_DEFAULTS, NUM_METRIC } from './visualizations/shared.helper';
import {
interceptFiltering,
saveChartToDashboard,
visitSampleChartFromList,
} from './utils';

// SEARCH_THRESHOLD is 10. We need to add at least 11 dashboards to show search
const SAMPLE_DASHBOARDS_INDEXES = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

function openDashboardsAddedTo() {
cy.getBySel('actions-trigger').click();
cy.get('.ant-dropdown-menu-submenu-title')
.contains('Dashboards added to')
.trigger('mouseover');
}

function closeDashboardsAddedTo() {
cy.get('.ant-dropdown-menu-submenu-title')
.contains('Dashboards added to')
.trigger('mouseout');
cy.getBySel('actions-trigger').click();
}

function verifyDashboardsSubmenuItem(dashboardName) {
cy.get('.ant-dropdown-menu-submenu-popup').contains(dashboardName);
closeDashboardsAddedTo();
}

function verifyDashboardSearch() {
openDashboardsAddedTo();
cy.get('.ant-dropdown-menu-submenu-popup').trigger('mouseover');
cy.get('.ant-dropdown-menu-submenu-popup')
.find('input[placeholder="Search"]')
.type('1');
cy.get('.ant-dropdown-menu-submenu-popup').contains('1 - Sample dashboard');
cy.get('.ant-dropdown-menu-submenu-popup')
.find('input[placeholder="Search"]')
.type('Blahblah');
cy.get('.ant-dropdown-menu-submenu-popup').contains('No results found');
cy.get('.ant-dropdown-menu-submenu-popup')
.find('[aria-label="close-circle"]')
.click();
closeDashboardsAddedTo();
}

function verifyDashboardLink() {
interceptDashboardGet();
openDashboardsAddedTo();
cy.get('.ant-dropdown-menu-submenu-popup').trigger('mouseover');
cy.get('.ant-dropdown-menu-submenu-popup a')
.first()
.invoke('removeAttr', 'target')
.click();
cy.wait('@get');
}

function verifyMetabar(text) {
cy.getBySel('metadata-bar').contains(text);
}

function saveAndVerifyDashboard(number) {
saveChartToDashboard(`${number} - Sample dashboard`);
verifyMetabar(`Added to ${number} dashboard(s)`);
openDashboardsAddedTo();
verifyDashboardsSubmenuItem(`${number} - Sample dashboard`);
}

describe('Cross-referenced dashboards', () => {
beforeEach(() => {
interceptFiltering();

cy.preserveLogin();
cy.visit(CHART_LIST);
cy.wait('@filtering');
});

before(() => {
cy.createSampleDashboards(SAMPLE_DASHBOARDS_INDEXES);
cy.createSampleCharts([0]);
});

it('should show the cross-referenced dashboards', () => {
visitSampleChartFromList('1 - Sample chart');

cy.getBySel('metadata-bar').contains('Not added to any dashboard');
openDashboardsAddedTo();
verifyDashboardsSubmenuItem('None');

saveAndVerifyDashboard('1');
saveAndVerifyDashboard('2');
saveAndVerifyDashboard('3');
saveAndVerifyDashboard('4');
saveAndVerifyDashboard('5');
saveAndVerifyDashboard('6');
saveAndVerifyDashboard('7');
saveAndVerifyDashboard('8');
saveAndVerifyDashboard('9');
saveAndVerifyDashboard('10');
saveAndVerifyDashboard('11');

verifyDashboardSearch();
verifyDashboardLink();
});
});

describe('No Results', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,23 @@ export function setFilter(filter: string, option: string) {

cy.wait('@filtering');
}

export function saveChartToDashboard(dashboardName: string) {
cy.getBySel('query-save-button').click();
cy.get(
'[data-test="save-chart-modal-select-dashboard-form"] [aria-label="Select a dashboard"]',
)
.first()
.click();
cy.get(
'.ant-select-selection-search-input[aria-label="Select a dashboard"]',
).type(dashboardName);
cy.get(`.ant-select-item-option[title="${dashboardName}"]`).click();
cy.getBySel('btn-modal-save').click();
}

export function visitSampleChartFromList(chartName: string) {
cy.getBySel('table-row').contains(chartName).click();
cy.intercept('POST', '/superset/explore_json/**').as('getJson');
cy.wait(500);
}
Loading

0 comments on commit 2fe68a3

Please sign in to comment.