Skip to content

Commit

Permalink
Refactor Cypress tests (#32 from 1-Harshit/test)
Browse files Browse the repository at this point in the history
Refactor Cypress tests
  • Loading branch information
1-Harshit authored Nov 17, 2023
2 parents 9bb12d4 + c0c4530 commit 0417478
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 40 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cypress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
record: true
parallel: true
component: true
browser: chrome
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import EditorHome from "./index";
import { wordCount } from "../../variables/editorPlaceholder";
import EditorHome from "../views/editor/index";
import { wordCount } from "../variables/editorPlaceholder";
import { ChakraProvider } from "@chakra-ui/react";
import theme from "../../theme/theme";
import theme from "../theme/theme";

beforeEach(() => {
cy.viewport(1920, 1080);
Expand All @@ -13,14 +13,10 @@ beforeEach(() => {
</ChakraProvider>,
);

// focus on editor-area
cy.get("#editor-main").click();

// count number words in defaultData whihc is jsx element rendering
cy.get("#word-count").should("have.text", wordCount);

// clear editor
// click on cy.get('#menu-button-24')
cy.get("#menu-button-24").click();
cy.get("#menu-list-24-menuitem-22 > .css-70qvj9 > .chakra-text").click();

Expand All @@ -30,9 +26,6 @@ beforeEach(() => {
// add text to editor
cy.get("#editor-main").type("Ed Eater Testing");

// count number words in editor
cy.get("#word-count").should("have.text", "3");

// select text
cy.get("#editor-main").type("{selectall}");
});
Expand All @@ -42,7 +35,7 @@ describe("<EditorHome Align-Left />", () => {
// text align - left
cy.get("#align-left-button").click();
// the html formatting must be empty as text-align: left is default
cy.get("#editor-main").should("contain.html", 'Ed Eater Testing')
cy.get("#editor-main").should("contain.html", "Ed Eater Testing");
});
});

Expand All @@ -51,20 +44,23 @@ describe("<EditorHome Align-Right />", () => {
// text align - right
cy.get("#align-right-button").click();
// the html formatting must be text-align:right as set by the button
cy.get("#editor-main").should("contain.html", '<div style="text-align: right;">');
cy.get("#editor-main").should(
"contain.html",
'<div style="text-align: right;">',
);
});
});

describe("<EditorHome Align-Left-After-Right />", () => {
it("renders", () => {
// text align -right
cy.get("#align-right-button").click();
// select all text
cy.get("#editor-main").type("{selectall}");
// text align -right
cy.get("#align-right-button").click();
// select all text
cy.get("#editor-main").type("{selectall}");
// text align - left
cy.get("#align-left-button").click();
// the html formatting must be empty as text-align:right is removed when
cy.get("#editor-main").should("contain.html", 'Ed Eater Testing')
// the html formatting must be empty as text-align:right is removed when
cy.get("#editor-main").should("contain.html", "Ed Eater Testing");
});
});

Expand All @@ -73,7 +69,10 @@ describe("<EditorHome Align-Center />", () => {
// text align - right
cy.get("#align-center-button").click();
// the html formatting must be text-align:center as set by the button
cy.get("#editor-main").should("contain.html", '<div style="text-align: center;">');
cy.get("#editor-main").should(
"contain.html",
'<div style="text-align: center;">',
);
});
});

Expand All @@ -82,6 +81,9 @@ describe("<EditorHome Align-Justify />", () => {
// text align - right
cy.get("#align-justify-button").click();
// the html formatting must be text-align:justify as set by the button
cy.get("#editor-main").should("contain.html", '<div style="text-align: justify;">');
cy.get("#editor-main").should(
"contain.html",
'<div style="text-align: justify;">',
);
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import EditorHome from "./index";
import { wordCount } from "../../variables/editorPlaceholder";
import EditorHome from "../views/editor/index";
import { wordCount } from "../variables/editorPlaceholder";
import { ChakraProvider } from "@chakra-ui/react";
import theme from "../../theme/theme";
import theme from "../theme/theme";

beforeEach(() => {
cy.viewport(1920, 1080);
Expand All @@ -13,14 +13,10 @@ beforeEach(() => {
</ChakraProvider>,
);

// focus on editor-area
cy.get("#editor-main").click();

// count number words in defaultData whihc is jsx element rendering
cy.get("#word-count").should("have.text", wordCount);

// clear editor
// click on cy.get('#menu-button-24')
cy.get("#menu-button-24").click();
cy.get("#menu-list-24-menuitem-22 > .css-70qvj9 > .chakra-text").click();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import EditorHome from "./index";
import { wordCount } from "../../variables/editorPlaceholder";
import EditorHome from "../views/editor/index";
import { wordCount } from "../variables/editorPlaceholder";
import { ChakraProvider } from "@chakra-ui/react";
import theme from "../../theme/theme";
import theme from "../theme/theme";

beforeEach(() => {
cy.viewport(1920, 1080);
Expand All @@ -13,9 +13,6 @@ beforeEach(() => {
</ChakraProvider>,
);

// focus on editor-area
cy.get("#editor-main").click();

// count number words in defaultData whihc is jsx element rendering
cy.get("#word-count").should("have.text", wordCount);

Expand All @@ -24,6 +21,8 @@ beforeEach(() => {
cy.get("#menu-button-24").click();
cy.get("#menu-list-24-menuitem-22 > .css-70qvj9 > .chakra-text").click();

cy.get("#word-count").should("have.text", 0);

// editor should be empty
cy.get("#editor-main").should("have.text", "");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import EditorHome from "./index";
import { wordCount } from "../../variables/editorPlaceholder";
import EditorHome from "../views/editor/index";
import { wordCount } from "../variables/editorPlaceholder";
import { ChakraProvider } from "@chakra-ui/react";
import theme from "../../theme/theme";
import theme from "../theme/theme";

describe("<EditorHome />", () => {
it("renders", () => {
Expand All @@ -14,17 +14,16 @@ describe("<EditorHome />", () => {
</ChakraProvider>,
);

// focus on editor-area
cy.get("#editor-main").click();

// count number words in defaultData whihc is jsx element rendering
cy.get("#word-count").should("have.text", wordCount);

// clear editor
// click on cy.get('#menu-button-24')
cy.get("#menu-button-24").click();
cy.get("#menu-list-24-menuitem-22 > .css-70qvj9 > .chakra-text").click();

// word count should be 0
cy.get("#word-count").should("have.text", 0);

// editor should be empty
cy.get("#editor-main").should("have.text", "");

Expand Down

0 comments on commit 0417478

Please sign in to comment.