Skip to content

Commit

Permalink
refactor: Shorten cypress selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Sep 29, 2022
1 parent b4b019e commit 8fe93d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("Filters", () => {
);
waitForChartToBeLoaded();

selectors.edition.findConfiguratorFilters(cy).within(() => {
selectors.edition.configFilters(cy).within(() => {
cy.findByText("1. production region");
cy.findByText("2. stand structure");
cy.findByText("3. evaluation type");
Expand Down
10 changes: 8 additions & 2 deletions cypress/integration/search.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import selectors from "./selectors";

Cypress.on("uncaught:exception", (err) => {
if (err.message.includes("> ResizeObserver loop")) {
return false;
Expand All @@ -11,7 +13,11 @@ describe("Searching for charts", () => {
);
cy.waitForNetworkIdle(1000);

cy.get("#datasetSearch").should("have.attr", "value", "category");
cy.get("#dataset-include-drafts").should("have.attr", "checked");
selectors.search.searchInput(cy).should("have.attr", "value", "category");
selectors.search.draftsCheckbox(cy).should("have.attr", "checked");
});

it("should have coherent numbers between the side panel and the filtered results", () => {
cy.visit(`/en/browse`);
});
});
15 changes: 8 additions & 7 deletions cypress/integration/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ type Cy = Cypress.Chainable;

const selectors = {
search: {
findSearchInput: (cy: Cy) => cy.get("#datasetSearch"),
findIncludeDraftsCheckbox: (cy: Cy) => cy.get("#dataset-include-drafts"),
searchInput: (cy: Cy) => cy.get("#datasetSearch"),
draftsCheckbox: (cy: Cy) => cy.get("#dataset-include-drafts"),
},
panels: {
left: (cy: Cy) => cy.get('[data-name="panel-left"]'),
right: (cy: Cy) => cy.get('[data-name="panel-right"]'),
},
edition: {
findLeftPanel: (cy: Cy) => cy.get('[data-name="panel-left"]'),
findRightPanel: (cy: Cy) => cy.get('[data-name="panel-right"]'),
findConfiguratorFilters: (cy: Cy) =>
cy.findByTestId("configurator-filters"),
findChartFiltersList: (cy: Cy) => cy.findByTestId("chart-filters-list"),
configFilters: (cy: Cy) => cy.findByTestId("configurator-filters"),
chartFilters: (cy: Cy) => cy.findByTestId("chart-filters-list"),
},
};

Expand Down

0 comments on commit 8fe93d9

Please sign in to comment.