Skip to content

Commit

Permalink
Run prettier on cypress folder (#4510)
Browse files Browse the repository at this point in the history
* Run prettier on cypress folder

* Test Restyled

* Revert "Test Restyled"

This reverts commit 13d4396.
  • Loading branch information
gabrieldutra authored and arikfr committed Dec 30, 2019
1 parent 329e859 commit 29582e3
Show file tree
Hide file tree
Showing 39 changed files with 1,278 additions and 1,217 deletions.
7 changes: 6 additions & 1 deletion client/app/pages/dashboards/useDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ function getAffectedWidgets(widgets, updatedParameters = []) {
? widgets.filter(widget =>
Object.values(widget.getParameterMappings())
.filter(({ type }) => type === "dashboard-level")
.some(({ mapTo }) => includes(updatedParameters.map(p => p.name), mapTo))
.some(({ mapTo }) =>
includes(
updatedParameters.map(p => p.name),
mapTo
)
)
)
: widgets;
}
Expand Down
27 changes: 15 additions & 12 deletions client/app/services/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,22 @@ function WidgetFactory($http, $location, Query) {
const queryParams = $location.search();

const localTypes = [WidgetService.MappingType.WidgetLevel, WidgetService.MappingType.StaticValue];
return map(filter(params, param => localTypes.indexOf(mappings[param.name].type) >= 0), param => {
const mapping = mappings[param.name];
const result = param.clone();
result.title = mapping.title || param.title;
result.locals = [param];
result.urlPrefix = `p_w${this.id}_`;
if (mapping.type === WidgetService.MappingType.StaticValue) {
result.setValue(mapping.value);
} else {
result.fromUrlParams(queryParams);
return map(
filter(params, param => localTypes.indexOf(mappings[param.name].type) >= 0),
param => {
const mapping = mappings[param.name];
const result = param.clone();
result.title = mapping.title || param.title;
result.locals = [param];
result.urlPrefix = `p_w${this.id}_`;
if (mapping.type === WidgetService.MappingType.StaticValue) {
result.setValue(mapping.value);
} else {
result.fromUrlParams(queryParams);
}
return result;
}
return result;
});
);
}

getParameterMappings() {
Expand Down
6 changes: 3 additions & 3 deletions client/cypress/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module.exports = {
extends: ["plugin:cypress/recommended"],
plugins: ["cypress", "chai-friendly"],
env: {
"cypress/globals": true
"cypress/globals": true,
},
rules: {
"func-names": ["error", "never"],
"no-unused-expressions": 0,
"chai-friendly/no-unused-expressions": 2
}
"chai-friendly/no-unused-expressions": 2,
},
};
56 changes: 28 additions & 28 deletions client/cypress/cypress.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
/* eslint-disable import/no-extraneous-dependencies, no-console */
const atob = require('atob');
const { execSync } = require('child_process');
const { post } = require('request').defaults({ jar: true });
const { seedData } = require('./seed-data');
const atob = require("atob");
const { execSync } = require("child_process");
const { post } = require("request").defaults({ jar: true });
const { seedData } = require("./seed-data");

const baseUrl = process.env.CYPRESS_baseUrl || 'http://localhost:5000';
const baseUrl = process.env.CYPRESS_baseUrl || "http://localhost:5000";

function seedDatabase(seedValues) {
const request = seedValues.shift();
const data = request.type === 'form' ? { formData: request.data } : { json: request.data };
const data = request.type === "form" ? { formData: request.data } : { json: request.data };

post(baseUrl + request.route, data, (err, response) => {
const result = response ? response.statusCode : err;
console.log('POST ' + request.route + ' - ' + result);
console.log("POST " + request.route + " - " + result);
if (seedValues.length) {
seedDatabase(seedValues);
}
});
}

function startServer() {
console.log('Starting the server...');
console.log("Starting the server...");

execSync('docker-compose -p cypress build --build-arg skip_ds_deps=true', { stdio: 'inherit' });
execSync('docker-compose -p cypress up -d', { stdio: 'inherit' });
execSync('docker-compose -p cypress run server create_db', { stdio: 'inherit' });
execSync("docker-compose -p cypress build --build-arg skip_ds_deps=true", { stdio: "inherit" });
execSync("docker-compose -p cypress up -d", { stdio: "inherit" });
execSync("docker-compose -p cypress run server create_db", { stdio: "inherit" });
}

function stopServer() {
console.log('Stopping the server...');
execSync('docker-compose -p cypress down', { stdio: 'inherit' });
console.log("Stopping the server...");
execSync("docker-compose -p cypress down", { stdio: "inherit" });
}

function runCypressCI() {
Expand All @@ -40,7 +40,7 @@ function runCypressCI() {
CIRCLE_REPOSITORY_URL,
} = process.env;

if (CIRCLE_REPOSITORY_URL && CIRCLE_REPOSITORY_URL.includes('getredash/redash')) {
if (CIRCLE_REPOSITORY_URL && CIRCLE_REPOSITORY_URL.includes("getredash/redash")) {
if (PERCY_TOKEN_ENCODED) {
process.env.PERCY_TOKEN = atob(`${PERCY_TOKEN_ENCODED}`);
}
Expand All @@ -53,39 +53,39 @@ function runCypressCI() {
}

execSync(
'docker-compose run cypress ./node_modules/.bin/percy exec -t 300 -- ./node_modules/.bin/cypress run --record',
{ stdio: 'inherit' },
"docker-compose run cypress ./node_modules/.bin/percy exec -t 300 -- ./node_modules/.bin/cypress run --record",
{ stdio: "inherit" }
);
}

const command = process.argv[2] || 'all';
const command = process.argv[2] || "all";

switch (command) {
case 'start':
case "start":
startServer();
break;
case 'db-seed':
case "db-seed":
seedDatabase(seedData);
break;
case 'run':
execSync('cypress run', { stdio: 'inherit' });
case "run":
execSync("cypress run", { stdio: "inherit" });
break;
case 'open':
execSync('cypress open', { stdio: 'inherit' });
case "open":
execSync("cypress open", { stdio: "inherit" });
break;
case 'run-ci':
case "run-ci":
runCypressCI();
break;
case 'stop':
case "stop":
stopServer();
break;
case 'all':
case "all":
startServer();
seedDatabase(seedData);
execSync('cypress run', { stdio: 'inherit' });
execSync("cypress run", { stdio: "inherit" });
stopServer();
break;
default:
console.log('Usage: npm run cypress [start|db-seed|open|run|stop]');
console.log("Usage: npm run cypress [start|db-seed|open|run|stop]");
break;
}
26 changes: 14 additions & 12 deletions client/cypress/integration/alert/create_alert_spec.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { createQuery } from '../../support/redash-api';
import { createQuery } from "../../support/redash-api";

describe('Create Alert', () => {
describe("Create Alert", () => {
beforeEach(() => {
cy.login();
});

it('renders the initial page and takes a screenshot', () => {
cy.visit('/alerts/new');
cy.getByTestId('QuerySelector').should('exist');
cy.percySnapshot('Create Alert initial screen');
it("renders the initial page and takes a screenshot", () => {
cy.visit("/alerts/new");
cy.getByTestId("QuerySelector").should("exist");
cy.percySnapshot("Create Alert initial screen");
});

it('selects query and takes a screenshot', () => {
createQuery({ name: 'Create Alert Query' }).then(({ id: queryId }) => {
cy.visit('/alerts/new');
cy.getByTestId('QuerySelector').click().type('Create Alert Query');
it("selects query and takes a screenshot", () => {
createQuery({ name: "Create Alert Query" }).then(({ id: queryId }) => {
cy.visit("/alerts/new");
cy.getByTestId("QuerySelector")
.click()
.type("Create Alert Query");
cy.get(`.query-selector-result[data-test="QueryId${queryId}"]`).click();
cy.getByTestId('Criteria').should('exist');
cy.percySnapshot('Create Alert second screen');
cy.getByTestId("Criteria").should("exist");
cy.percySnapshot("Create Alert second screen");
});
});
});
38 changes: 19 additions & 19 deletions client/cypress/integration/alert/edit_alert_spec.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import { createAlert, createQuery } from '../../support/redash-api';
import { createAlert, createQuery } from "../../support/redash-api";

describe('Edit Alert', () => {
describe("Edit Alert", () => {
beforeEach(() => {
cy.login();
});

it('renders the page and takes a screenshot', () => {
createQuery({ query: 'select 1 as col_name' })
.then(({ id: queryId }) => createAlert(queryId, { column: 'col_name' }))
it("renders the page and takes a screenshot", () => {
createQuery({ query: "select 1 as col_name" })
.then(({ id: queryId }) => createAlert(queryId, { column: "col_name" }))
.then(({ id: alertId }) => {
cy.visit(`/alerts/${alertId}/edit`);
cy.getByTestId('Criteria').should('exist');
cy.percySnapshot('Edit Alert screen');
cy.getByTestId("Criteria").should("exist");
cy.percySnapshot("Edit Alert screen");
});
});

it('edits the notification template and takes a screenshot', () => {
it("edits the notification template and takes a screenshot", () => {
createQuery()
.then(({ id: queryId }) => createAlert(queryId, { custom_subject: 'FOO', custom_body: 'BAR' }))
.then(({ id: queryId }) => createAlert(queryId, { custom_subject: "FOO", custom_body: "BAR" }))
.then(({ id: alertId }) => {
cy.visit(`/alerts/${alertId}/edit`);
cy.getByTestId('AlertCustomTemplate').should('exist');
cy.percySnapshot('Alert Custom Template screen');
cy.getByTestId("AlertCustomTemplate").should("exist");
cy.percySnapshot("Alert Custom Template screen");
});
});

it('previews rendered template correctly', () => {
it("previews rendered template correctly", () => {
const options = {
value: '123',
op: '==',
custom_subject: '{{ ALERT_CONDITION }}',
custom_body: '{{ ALERT_THRESHOLD }}',
value: "123",
op: "==",
custom_subject: "{{ ALERT_CONDITION }}",
custom_body: "{{ ALERT_THRESHOLD }}",
};

createQuery()
.then(({ id: queryId }) => createAlert(queryId, options))
.then(({ id: alertId }) => {
cy.visit(`/alerts/${alertId}/edit`);
cy.get('.alert-template-preview').click();
cy.getByTestId('CustomSubject').should('have.value', options.op);
cy.getByTestId('CustomBody').should('have.value', options.value);
cy.get(".alert-template-preview").click();
cy.getByTestId("CustomSubject").should("have.value", options.op);
cy.getByTestId("CustomBody").should("have.value", options.value);
});
});
});
Loading

0 comments on commit 29582e3

Please sign in to comment.