Skip to content

Commit

Permalink
chore: upgrade Cypress to 6.2.1 (#12605)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud authored Jan 25, 2021
1 parent 1b2611c commit 29ad78e
Show file tree
Hide file tree
Showing 54 changed files with 487 additions and 571 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { CHART_LIST } from './chart_list.helper';
describe('chart card view', () => {
beforeEach(() => {
cy.login();
cy.server();
cy.visit(CHART_LIST);
cy.get('[data-test="card-view"]').click();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { CHART_LIST } from './chart_list.helper';
describe('chart card view filters', () => {
beforeEach(() => {
cy.login();
cy.server();
cy.visit(CHART_LIST);
cy.get('[data-test="card-view"]').click();
});
Expand Down Expand Up @@ -89,7 +88,6 @@ describe('chart card view filters', () => {
describe('chart list view filters', () => {
beforeEach(() => {
cy.login();
cy.server();
cy.visit(CHART_LIST);
cy.get('[data-test="list-view"]').click();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { CHART_LIST } from './chart_list.helper';
describe('chart list view', () => {
beforeEach(() => {
cy.login();
cy.server();
cy.visit(CHART_LIST);
cy.get('[data-test="list-view"]').click();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,26 @@
* under the License.
*/
import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';
import readResponseBlob from '../../utils/readResponseBlob';
import {
getChartAliases,
isLegacyResponse,
DASHBOARD_CHART_ALIAS_PREFIX,
} from '../../utils/vizPlugins';

describe('Dashboard top-level controls', () => {
let mapId;
let aliases;
let mapId: string;
let aliases: string[];

beforeEach(() => {
cy.server();
cy.login();
cy.visit(WORLD_HEALTH_DASHBOARD);

cy.get('#app').then(data => {
const bootstrapData = JSON.parse(data[0].dataset.bootstrap);
const bootstrapData = JSON.parse(data[0].dataset.bootstrap || '');
const dashboard = bootstrapData.dashboard_data;
mapId = dashboard.slices.find(
slice => slice.form_data.viz_type === 'world_map',
(slice: { form_data: { viz_type: string }; slice_id: number }) =>
slice.form_data.viz_type === 'world_map',
).slice_id;
aliases = getChartAliases(dashboard.slices);
});
Expand All @@ -50,10 +49,11 @@ describe('Dashboard top-level controls', () => {
cy.get(`#slice_${mapId}-controls`).click();
cy.get(`[data-test="slice_${mapId}-menu"]`)
.find('[data-test="refresh-chart-menu-item"]')
.click({ force: true })
.then($el => {
cy.get($el).should('have.class', 'ant-dropdown-menu-item-disabled');
});
.click({ force: true });
cy.get('[data-test="refresh-chart-menu-item"]').should(
'have.class',
'ant-dropdown-menu-item-disabled',
);

cy.wait(`@${DASHBOARD_CHART_ALIAS_PREFIX}${mapId}`);
cy.get('[data-test="refresh-chart-menu-item"]').should(
Expand All @@ -63,7 +63,6 @@ describe('Dashboard top-level controls', () => {
});

it('should allow dashboard level force refresh', () => {
// wait the all dash finish loading.
cy.wait(aliases);
// when charts are not start loading, for example, under a secondary tab,
// should allow force refresh
Expand All @@ -80,14 +79,14 @@ describe('Dashboard top-level controls', () => {
);

// wait all charts force refreshed.
cy.wait(aliases, { responseTimeout: 15000 }).then(xhrs => {
xhrs.forEach(async xhr => {
const responseBody = await readResponseBlob(xhr.response.body);
cy.wait(aliases).then(xhrs => {
xhrs.forEach(async ({ response, request }) => {
const responseBody = response?.body;
const isCached = isLegacyResponse(responseBody)
? responseBody.is_cached
: responseBody.result[0].is_cached;
// request url should indicate force-refresh operation
expect(xhr.url).to.have.string('force=true');
expect(request.url).to.have.string('force=true');
// is_cached in response should be false
expect(isCached).to.equal(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { WORLD_HEALTH_DASHBOARD, drag } from './dashboard.helper';

describe('Dashboard edit mode', () => {
beforeEach(() => {
cy.server();
cy.login();
cy.visit(WORLD_HEALTH_DASHBOARD);
cy.get('[data-test="dashboard-header"]')
Expand All @@ -43,7 +42,7 @@ describe('Dashboard edit mode', () => {
// box plot should be gone
cy.get('[data-test="grid-container"]')
.find('.box_plot')
.should('not.be.visible');
.should('not.exist');
});

cy.get('[data-test="dashboard-builder-component-pane-tabs-navigation"]')
Expand Down Expand Up @@ -78,7 +77,7 @@ describe('Dashboard edit mode', () => {
// Box plot chart should be gone
cy.get('[data-test="grid-container"]')
.find('.box_plot')
.should('not.be.visible');
.should('not.exist');

// undo second step and expect initial items count
cy.get('[data-test="undo-action"]').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ function openDashboardEditProperties() {

describe('Dashboard edit action', () => {
beforeEach(() => {
cy.server();
cy.login();
cy.visit(WORLD_HEALTH_DASHBOARD);
cy.route(`/api/v1/dashboard/1`).as('dashboardGet');
cy.intercept(`/api/v1/dashboard/1`).as('dashboardGet');
cy.get('.dashboard-grid', { timeout: 50000 })
.should('be.visible') // wait for 50 secs to load dashboard
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ describe('Dashboard add to favorite', () => {
let isFavoriteDashboard = false;

beforeEach(() => {
cy.server();
cy.login();

cy.route(CHECK_DASHBOARD_FAVORITE_ENDPOINT).as('countFavStar');
cy.intercept(CHECK_DASHBOARD_FAVORITE_ENDPOINT).as('countFavStar');
cy.visit(WORLD_HEALTH_DASHBOARD);

cy.wait('@countFavStar').then(xhr => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';
import {
getChartAliases,
DASHBOARD_CHART_ALIAS_PREFIX,
isLegacyResponse,
} from '../../utils/vizPlugins';
import readResponseBlob from '../../utils/readResponseBlob';
parsePostForm,
} from 'cypress/utils';
import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';

interface Slice {
slice_id: number;
Expand All @@ -43,7 +43,6 @@ describe('Dashboard filter', () => {
const getAlias = (id: number) => `@${DASHBOARD_CHART_ALIAS_PREFIX}${id}`;

beforeEach(() => {
cy.server();
cy.login();

cy.visit(WORLD_HEALTH_DASHBOARD);
Expand Down Expand Up @@ -87,18 +86,17 @@ describe('Dashboard filter', () => {
cy.get('.filter_box button').click({ force: true });
cy.wait(aliases.filter(x => x !== getAlias(filterId))).then(requests =>
Promise.all(
requests.map(async xhr => {
expect(xhr.status).to.eq(200);
const responseBody = await readResponseBlob(xhr.response.body);
requests.map(async ({ response, request }) => {
const responseBody = response?.body;
let requestFilter;
if (isLegacyResponse(responseBody)) {
const requestFormData = xhr.request.body as FormData;
const requestFormData = parsePostForm(request.body);
const requestParams = JSON.parse(
requestFormData.get('form_data') as string,
requestFormData.form_data as string,
);
requestFilter = requestParams.extra_filters[0];
} else {
requestFilter = xhr.request.body.queries[0].filters[0];
requestFilter = request.body.queries[0].filters[0];
}
expect(requestFilter).deep.eq({
col: 'region',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
import readResponseBlob from '../../utils/readResponseBlob';
import {
getChartAliases,
isLegacyResponse,
Expand All @@ -28,7 +27,6 @@ describe('Dashboard load', () => {
let dashboard;
let aliases;
beforeEach(() => {
cy.server();
cy.login();

cy.visit(WORLD_HEALTH_DASHBOARD);
Expand All @@ -46,16 +44,15 @@ describe('Dashboard load', () => {
// wait and verify one-by-one
cy.wait(aliases).then(requests =>
Promise.all(
requests.map(async xhr => {
expect(xhr.status).to.eq(200);
const responseBody = await readResponseBlob(xhr.response.body);
requests.map(async ({ response, request }) => {
const responseBody = response?.body;
let sliceId;
if (isLegacyResponse(responseBody)) {
expect(responseBody).to.have.property('errors');
expect(responseBody.errors.length).to.eq(0);
sliceId = responseBody.form_data.slice_id;
} else {
sliceId = getSliceIdFromRequestUrl(xhr.url);
sliceId = getSliceIdFromRequestUrl(request.url);
responseBody.result.forEach(element => {
expect(element).to.have.property('error', null);
expect(element).to.have.property('status', 'success');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { TABBED_DASHBOARD, drag, resize } from './dashboard.helper';

describe('Dashboard edit markdown', () => {
beforeEach(() => {
cy.server();
cy.login();
cy.visit(TABBED_DASHBOARD);
});
Expand Down Expand Up @@ -85,6 +84,6 @@ describe('Dashboard edit markdown', () => {
cy.get('@component-background-first').click('right');
cy.get('[data-test="dashboard-component-chart-holder"]')
.find('.ace_content')
.should('not.be.visible');
.should('not.exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { TABBED_DASHBOARD } from './dashboard.helper';
describe('Nativefilters', () => {
beforeEach(() => {
cy.login();
cy.server();
cy.visit(TABBED_DASHBOARD);
});
it('should show filter bar and allow user to create filters ', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ function openDashboardEditProperties() {

describe('Dashboard save action', () => {
beforeEach(() => {
cy.server();
cy.login();
cy.visit(WORLD_HEALTH_DASHBOARD);
cy.get('#app').then(data => {
const bootstrapData = JSON.parse(data[0].dataset.bootstrap);
const dashboard = bootstrapData.dashboard_data;
const dashboardId = dashboard.id;
cy.route('POST', `/superset/copy_dash/${dashboardId}/`).as('copyRequest');
cy.intercept('POST', `/superset/copy_dash/${dashboardId}/`).as(
'copyRequest',
);

cy.get('[data-test="more-horiz"]').trigger('click', { force: true });
cy.get('[data-test="save-as-menu-item"]').trigger('click', {
Expand All @@ -56,35 +57,37 @@ describe('Dashboard save action', () => {
});

it('should save/overwrite dashboard', () => {
cy.get('[data-test="grid-row-background--transparent"]').within(() => {
cy.get('.box_plot', { timeout: 10000 }).should('be.visible');
});
// should load chart
cy.get('.dashboard-grid', { timeout: 50000 }); // wait for 50 secs
cy.get('.dashboard-grid', { timeout: 30000 });
cy.get('.box_plot').should('be.visible');

// remove box_plot chart from dashboard
cy.get('[data-test="edit-alt"]').click({ timeout: 5000 });
cy.get('[data-test="dashboard-delete-component-button"]')
.should('be.visible', { timeout: 10000 })
.last()
.trigger('click');
.trigger('moustenter')
.click();

cy.get('[data-test="grid-container"]')
.find('.box_plot')
.should('not.be.visible');
.should('not.exist');

cy.route('POST', '/superset/save_dash/**/').as('saveRequest');
cy.intercept('POST', '/superset/save_dash/**/').as('saveRequest');
cy.get('[data-test="dashboard-header"]')
.find('[data-test="header-save-button"]')
.contains('Save')
.trigger('click', { force: true });
.click();

// go back to view mode
cy.wait('@saveRequest');
cy.get('[data-test="dashboard-header"]')
.find('[data-test="edit-alt"]')
.click();

// deleted boxplot should still not exist
cy.get('[data-test="grid-container"]')
.find('.box_plot', { timeout: 20000 })
.should('not.be.visible');
.should('not.exist');
});

// TODO: Fix broken test
Expand Down
Loading

0 comments on commit 29ad78e

Please sign in to comment.