Skip to content

Commit

Permalink
Enforce empty line before it and describe (metabase#48628)
Browse files Browse the repository at this point in the history
* Add eslint-plugin-jest-formatting

* Turn on jest formatting for unit.spec and cy.spec files

* Fix e2e test formatting

* Fix unit test formatting

* Fix formatting in frontend/test

* Remove commented out code

Co-authored-by: Kamil Mielnik <[email protected]>

* Fix more files

* Fix more lint

---------

Co-authored-by: Kamil Mielnik <[email protected]>
  • Loading branch information
romeovs and kamilmielnik authored Oct 14, 2024
1 parent 464902f commit 3b4a578
Show file tree
Hide file tree
Showing 155 changed files with 670 additions and 2 deletions.
10 changes: 8 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ module.exports = {
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:depend/recommended",
"plugin:storybook/recommended"
"plugin:storybook/recommended",
],
settings: {
"import/internal-regex": "^metabase/|^metabase-lib/",
Expand Down Expand Up @@ -235,8 +235,9 @@ module.exports = {
"plugin:jest/recommended",
"plugin:jest-dom/recommended",
"plugin:testing-library/react",
"plugin:jest-formatting/recommended",
],
plugins: ["jest", "jest-dom", "testing-library"],
plugins: ["jest", "jest-dom", "testing-library", "jest-formatting"],
files: [
"*.unit.spec.ts",
"*.unit.spec.tsx",
Expand All @@ -247,5 +248,10 @@ module.exports = {
"jest/valid-title": ["error", { ignoreTypeOfDescribeName: true }],
},
},
{
// Enable jest formatting for cypress tests too, the plugin logic just works
extends: ["plugin:jest-formatting/recommended"],
files: ["*.cy.spec.ts", "*.cy.spec.js"],
},
],
};
2 changes: 2 additions & 0 deletions e2e/test/scenarios/actions/actions-reproductions.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const viewports = [
[1024, 800],
[1440, 800],
];

describe("metabase#31587", () => {
viewports.forEach(([width, height]) => {
describe(`Testing on resolution ${width} x ${height}`, () => {
Expand All @@ -36,6 +37,7 @@ describe("metabase#31587", () => {
setActionsEnabledForDB(SAMPLE_DB_ID);
cy.viewport(width, height);
});

it("should not allow action buttons to overflow when editing dashboard", () => {
visitDashboard(ORDERS_DASHBOARD_ID);
editDashboard();
Expand Down
1 change: 1 addition & 0 deletions e2e/test/scenarios/admin-2/people.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ describeEE("issue 23689", () => {
cy.visit(`/admin/people/groups/${groupId}`);
cy.wait("@membership");
}

beforeEach(() => {
// TODO: remove the next line when this issue gets fixed
cy.skipOn(true);
Expand Down
2 changes: 2 additions & 0 deletions e2e/test/scenarios/admin-2/settings.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ describe.skip(
});
}
const nativeQuery = "select (random() * random() * random()), pg_sleep(2)";

beforeEach(() => {
cy.intercept("POST", "/api/dataset").as("dataset");
cy.intercept("POST", "/api/card/*/query").as("cardQuery");
Expand Down Expand Up @@ -708,6 +709,7 @@ describe("scenarios > admin > license and billing", () => {
status: "something",
});
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down
1 change: 1 addition & 0 deletions e2e/test/scenarios/admin-2/whitelabel.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ describeEE("formatting > whitelabel", () => {

describe("font", () => {
const font = "Open Sans";

beforeEach(() => {
cy.log("Change Application Font");
cy.signInAsAdmin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe("issue 18384", () => {

describe("issue 21984", () => {
const reviewsDataModelPage = `/admin/datamodel/database/${SAMPLE_DB_ID}/schema/${SAMPLE_DB_SCHEMA_ID}/table/${REVIEWS_ID}`;

beforeEach(() => {
cy.intercept("GET", "/api/table/*/query_metadata?**").as("tableMetadata");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ describe("scenarios > admin > performance > strategy form", () => {
["default policy", "Sample Database"].forEach(itemName => {
const model = itemName === "default policy" ? "root" : "database";
const expectedNumberOfOptions = itemName === "default policy" ? 4 : 5;

it(`there are ${expectedNumberOfOptions} policy options for ${itemName}`, () => {
openStrategyFormForDatabaseOrDefaultPolicy(itemName, "No caching");
cacheStrategyForm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
describe("issue 20911", () => {
const COLLECTION_ACCESS_PERMISSION_INDEX = 0;
const FIRST_COLLECTION = "First collection";

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down
2 changes: 2 additions & 0 deletions e2e/test/scenarios/collections/instance-analytics.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,14 @@ describe("question and dashboard links", () => {
popover().findByText("Usage insights").should("not.exist");
});
});

describe("oss", { tags: "@OSS" }, () => {
beforeEach(() => {
onlyOnOSS();
restore();
cy.signInAsAdmin();
});

it("should never appear in OSS", () => {
visitQuestion(ORDERS_QUESTION_ID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const { PRODUCTS, PRODUCTS_ID, ORDERS, ORDERS_ID, REVIEWS, REVIEWS_ID } =

describe.skip("issue 12445", { tags: "@external" }, () => {
const CC_NAME = "Abbr";

beforeEach(() => {
restore("mysql-8");
cy.signInAsAdmin();
Expand Down Expand Up @@ -79,6 +80,7 @@ describe.skip("issue 12445", { tags: "@external" }, () => {

describe("issue 13289", () => {
const CC_NAME = "Math";

beforeEach(() => {
cy.intercept("POST", "/api/dataset").as("dataset");

Expand Down Expand Up @@ -134,6 +136,7 @@ describe("issue 13289", () => {
describe("issue 13751", { tags: "@external" }, () => {
const CC_NAME = "C-States";
const PG_DB_NAME = "QA Postgres12";

beforeEach(() => {
restore("postgres-12");
cy.signInAsAdmin();
Expand Down Expand Up @@ -179,6 +182,7 @@ describe.skip(
// Ironically, both Prettier and Cypress remove escape characters from our code as well
// We're testing for the literal sting `(?<=\/\/)[^\/]*`, but we need to escape the escape characters to make it work
const ESCAPED_REGEX = "(?<=\\/\\/)[^\\/]*";

beforeEach(() => {
restore("postgres-12");
cy.signInAsAdmin();
Expand Down Expand Up @@ -216,6 +220,7 @@ describe("issue 14843", () => {
expressions: { [CC_NAME]: ["length", ["field", PEOPLE.CITY, null]] },
},
};

beforeEach(() => {
cy.intercept("POST", "/api/dataset").as("dataset");

Expand Down Expand Up @@ -258,6 +263,7 @@ describe("issue 18069", () => {
},
},
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -385,6 +391,7 @@ describe("issue 18814", () => {
},
},
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -717,6 +724,7 @@ describe("issue 23862", () => {
breakout: [["expression", "CC"]],
},
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -764,6 +772,7 @@ describe("issue 24922", () => {
name: "CustomColumn",
formula: 'case([OrdersSegment], "Segment", "Other")',
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -805,6 +814,7 @@ describe.skip("issue 25189", () => {
},
},
};

beforeEach(() => {
cy.intercept("POST", "/api/dataset").as("dataset");

Expand Down Expand Up @@ -920,6 +930,7 @@ describe("issue 32032", () => {
["expression", "Custom Reviewer", { "base-type": "type/Text" }],
],
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ describe(

describeWithSnowplow("scenarios > dashboards > filters > auto apply", () => {
const NUMBERS_OF_GOOD_SNOWPLOW_EVENTS_BEFORE_DISABLING_AUTO_APPLY_FILTERS = 2;

beforeEach(() => {
restore();
resetSnowplow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe("issue 12578", () => {
"source-table": ORDERS_ID,
},
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -254,6 +255,7 @@ describe("issue 13736", () => {
aggregation: [["count"]],
},
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -319,6 +321,7 @@ describe("issue 16559", () => {
const dashboardDetails = {
name: "16559 Dashboard",
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -873,6 +876,7 @@ describe("issue 31766", () => {
restore();
cy.signInAsAdmin();
});

it("should not corrupt dashboard data (metabase#31766)", () => {
const questionDetails = {
name: "Orders",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ describe("scenarios > embedding > dashboard parameters with defaults", () => {

describeEE("scenarios > embedding > dashboard appearance", () => {
const originalBaseUrl = Cypress.config("baseUrl");

beforeEach(() => {
// Reset the baseUrl to the default value
// needed because we do `Cypress.config("baseUrl", null);` in the iframe test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ describeEE("scenarios > embedding > questions > downloads", () => {
},
},
};

beforeEach(() => {
cy.intercept("PUT", "/api/card/*").as("publishChanges");
cy.intercept("GET", "/api/embed/card/**/query").as("dl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ describe("issues 20845, 25031", () => {
name: "25031",
parameters: [dashboardFilter],
};

beforeEach(() => {
cy.intercept("PUT", "/api/card/*").as("publishChanges");

Expand Down Expand Up @@ -673,6 +674,7 @@ describeEE("issue 30535", () => {
limit: 10,
},
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -747,6 +749,7 @@ describe("dashboard preview", () => {
type: "string/=",
sectionId: "string",
};

beforeEach(() => {
cy.intercept("GET", "/api/preview_embed/dashboard/**").as(
"previewDashboard",
Expand Down Expand Up @@ -947,6 +950,7 @@ describe("issue 40660", () => {
name: "long dashboard",
enable_embedding: true,
};

beforeEach(() => {
cy.intercept("GET", "/api/preview_embed/dashboard/**").as(
"previewDashboard",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ describe("issue 12720, issue 47172", () => {
},
},
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -371,6 +372,7 @@ describe("issue 12985 > dashboard filter dropdown/search", () => {
};

const dashboardDetails = { parameters: [categoryFilter] };

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -687,6 +689,7 @@ describe("issue 17211", () => {
const dashboardDetails = {
parameters: [filter],
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -840,6 +843,7 @@ describe("issue 17775", () => {
];

const dashboardDetails = { parameters };

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -923,6 +927,7 @@ describe("issue 19494", () => {
function checkAppliedFilter(name, value) {
cy.findByText(name).closest("fieldset").contains(value);
}

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -1624,6 +1629,7 @@ describe("issue 25322", () => {

cy.intercept(matcher, req => req.on("response", res => res.setDelay(100)));
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand Down Expand Up @@ -2455,6 +2461,7 @@ describe("issue 31662", () => {
name: "Dashboard",
parameters: [parameterDetails],
};

beforeEach(() => {
restore();
cy.signInAsAdmin();
Expand All @@ -2480,6 +2487,7 @@ describe("issue 31662", () => {
});
});
});

describe("issue 38245", () => {
function filterPanel() {
return cy.findByTestId("edit-dashboard-parameters-widget-container");
Expand All @@ -2506,6 +2514,7 @@ describe("issue 38245", () => {
slug: "filter-text",
type: "string/contains",
});

beforeEach(() => {
cy.intercept("POST", "/api/card/*/query").as("cardQuery");
restore();
Expand Down Expand Up @@ -2611,6 +2620,7 @@ describe("issue 43154", () => {
cy.button("Add filter").click();
});
}

beforeEach(() => {
restore();
cy.signInAsNormalUser();
Expand Down
Loading

0 comments on commit 3b4a578

Please sign in to comment.