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

[SIP-4] replace chart ajax calls with SupersetClient #5875

Merged
merged 18 commits into from
Oct 15, 2018
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
[cypress] add readResponseBlob helper, fix broken fetch-based tests
williaster committed Oct 15, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit b8ba1eb9dd196e3a4358080f30e0f316ea17f77b
6 changes: 4 additions & 2 deletions superset/assets/cypress/integration/dashboard/load.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import readResponseBlob from '../../utils/readResponseBlob';
import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';

export default () => describe('load', () => {
@@ -24,9 +25,10 @@ export default () => describe('load', () => {
it('should load dashboard', () => {
// wait and verify one-by-one
cy.wait(aliases).then((requests) => {
requests.forEach((xhr) => {
requests.forEach(async (xhr) => {
expect(xhr.status).to.eq(200);
expect(xhr.response.body).to.have.property('error', null);
const responseBody = await readResponseBlob(xhr.response.body);
expect(responseBody).to.have.property('error', null);
cy.get(`#slice-container-${xhr.response.body.form_data.slice_id}`);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FORM_DATA_DEFAULTS, NUM_METRIC } from './shared.helper';
import readResponseBlob from '../../../utils/readResponseBlob';

// Big Number Total

@@ -42,10 +43,12 @@ export default () => describe('Big Number Total', () => {
const formData = { ...BIG_NUMBER_DEFAULTS, metric: NUM_METRIC, groupby: ['state'] };

cy.visitChartByParams(JSON.stringify(formData));
cy.wait(['@getJson']).then((data) => {
cy.verifyResponseCodes(data);
cy.wait(['@getJson']).then(async (xhr) => {
cy.verifyResponseCodes(xhr);
cy.verifySliceContainer();
expect(data.response.body.query).not.contains(formData.groupby[0]);

const responseBody = await readResponseBlob(xhr.response.body);
expect(responseBody.query).not.contains(formData.groupby[0]);
});
});
});
20 changes: 13 additions & 7 deletions superset/assets/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

import readResponseBlob from '../utils/readResponseBlob';

const BASE_EXPLORE_URL = '/superset/explore/?form_data=';

Cypress.Commands.add('login', () => {
@@ -50,11 +52,14 @@ Cypress.Commands.add('visitChartByParams', (params) => {
cy.visit(`${BASE_EXPLORE_URL}${params}`);
});

Cypress.Commands.add('verifyResponseCodes', (data) => {
Cypress.Commands.add('verifyResponseCodes', async (xhr) => {
// After a wait response check for valid response
expect(data.status).to.eq(200);
if (data.response.body.error) {
expect(data.response.body.error).to.eq(null);
expect(xhr.status).to.eq(200);

const responseBody = await readResponseBlob(xhr.response.body);

if (responseBody.error) {
expect(responseBody.error).to.eq(null);
}
});

@@ -72,11 +77,12 @@ Cypress.Commands.add('verifySliceContainer', (chartSelector) => {
});

Cypress.Commands.add('verifySliceSuccess', ({ waitAlias, querySubstring, chartSelector }) => {
cy.wait(waitAlias).then((data) => {
cy.verifyResponseCodes(data);
cy.wait(waitAlias).then(async (xhr) => {
cy.verifyResponseCodes(xhr);

const responseBody = await readResponseBlob(xhr.response.body);
if (querySubstring) {
expect(data.response.body.query).contains(querySubstring);
expect(responseBody.query).contains(querySubstring);
}

cy.verifySliceContainer(chartSelector);
9 changes: 6 additions & 3 deletions superset/assets/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -13,8 +13,11 @@
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
// The following is a workaround for Cypress not supporting fetch.
// By setting window.fetch = null, we force the fetch polyfill to fall back
// to xhr as described here https://github.com/cypress-io/cypress/issues/95
Cypress.on('window:before:load', (win) => {
win.fetch = null; // eslint-disable-line no-param-reassign
});
11 changes: 11 additions & 0 deletions superset/assets/cypress/utils/readResponseBlob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This function returns a promise that resolves to the value
// of the passed response blob. It assumes the blob should be read as text,
// and that the response can be parsed as JSON. This is needed to read
// the value of any fetch-based response.
export default function readResponseBlob(blob) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double check cypress doesn't add this in as a test? If you run tests just make sure this file doesn't show up. I had trouble adding helpers / utils because it kept picking them up as tests. I'm not sure if it will happen because this is outside of the integration folder, but if it does I added a setting to ignore any files with the pattern *.helper.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michellethomas thanks for bringing this up, it looks okay from the cypress UI

return new Promise((resolve) => {
const reader = new FileReader();
reader.onload = () => resolve(JSON.parse(reader.result));
reader.readAsText(blob);
});
}