bulma/docs/cypress/integration/elements/button.spec.js
Jeremy Thomas 0ce084170a
Setup cypress (#3436)
* Setup Cypress tests for box and button

* Add container tests

* Add Cypress workflow

* Use npm install

* Update Cypress workflow

* Add Jekyll build

* Test other action

* Test custom setup

* Use other ruby action

* Test without flag

* Move cypress to docs folder

* Record runs

* Add Content, Icon, Image specs

* Add Notification specs

* Add Progress and Table specs

* Add Tags specs

* Add Title specs

* Add breadcrumb specs

* Add more specs

* Add media specs

* Add menu specs

* Add modal specs

* Add navbar specs

* Add pagination specs

* Add panel specs

* Add tabs specs, Add form checkbox radio specs

* Add utils

* Add file specs

* Add input textarea specs

* Add select specs

* Add form tools specs

* Add other elements specs

* Add footer and hero specs

* Add Hero specs

* Add section specs

* Add grid specs

* Add column sizes specs

* Add tiles specs

* Add generic specs

* Fix generic tests

* Make font family test looser

* Remove system-ui test

* Remove important flag

* Fix disabled select color
2022-05-08 13:55:16 +01:00

125 lines
4.6 KiB
JavaScript

describe("Elements/Button", () => {
beforeEach(() => {
cy.visit("http://127.0.0.1:4000/cyp/elements/button/");
});
it("has a Button", () => {
cy.get(".button").should("exist");
});
it("has a correct Button", () => {
cy.get("#button-default").then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.backgroundColor).to.equal(Cypress.env("white"));
expect(cs.borderColor).to.equal(Cypress.env("grey-lighter"));
expect(cs.borderRadius).to.equal("4px");
expect(cs.color).to.equal(Cypress.env("grey-darker"));
expect(cs.height).to.equal("40px");
expect(cs.lineHeight).to.equal("24px");
expect(cs.padding).to.equal("7px 16px");
});
});
// States
it("has a correct hover Button", () => {
cy.get("#button-hover").then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.backgroundColor).to.equal(Cypress.env("white"));
expect(cs.borderColor).to.equal(Cypress.env("grey-light"));
expect(cs.borderRadius).to.equal("4px");
expect(cs.color).to.equal(Cypress.env("grey-darker"));
expect(cs.height).to.equal("40px");
expect(cs.lineHeight).to.equal("24px");
expect(cs.padding).to.equal("7px 16px");
});
});
it("has a correct focus Button", () => {
cy.get("#button-focus").then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.backgroundColor).to.equal(Cypress.env("white"));
expect(cs.borderColor).to.equal(Cypress.env("blue"));
expect(cs.borderRadius).to.equal("4px");
expect(cs.boxShadow).to.equal(
`rgba${Cypress.env("blue").slice(3, -1)}, 0.25) 0px 0px 0px 2px`
);
expect(cs.color).to.equal(Cypress.env("grey-darker"));
expect(cs.height).to.equal("40px");
expect(cs.lineHeight).to.equal("24px");
expect(cs.padding).to.equal("7px 16px");
});
});
// Colors
it(`has correct color Buttons`, () => {
for (let i = 0; i < Cypress.env("color-names").length; i++) {
const name = Cypress.env("color-names")[i];
const baseColor = Cypress.env(name);
const invertColor = Cypress.env(`${name}-invert`);
const lightColor = Cypress.env(`${name}-light`);
const darkColor = Cypress.env(`${name}-dark`);
cy.get(`#button-${name}`).then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.backgroundColor).to.equal(baseColor);
expect(cs.borderColor).to.equal(Cypress.env("transparent"));
expect(cs.color).to.equal(invertColor);
});
cy.get(`#button-${name}-hover`).then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.borderColor).to.equal(Cypress.env("transparent"));
expect(cs.color).to.equal(invertColor);
});
cy.get(`#button-${name}-focus`).then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.boxShadow).to.equal(
`rgba${baseColor.slice(3, -1)}, 0.25) 0px 0px 0px 2px`
);
expect(cs.borderColor).to.equal(Cypress.env("transparent"));
expect(cs.color).to.equal(invertColor);
});
cy.get(`#button-${name}-active`).then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.borderColor).to.equal(Cypress.env("transparent"));
expect(cs.color).to.equal(invertColor);
});
cy.get(`#button-${name}-inverted`).then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.backgroundColor).to.equal(invertColor);
expect(cs.color).to.equal(baseColor);
});
cy.get(`#button-${name}-outlined`).then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.backgroundColor).to.equal(Cypress.env("transparent"));
expect(cs.borderColor).to.equal(baseColor);
expect(cs.color).to.equal(baseColor);
});
cy.get(`#button-${name}-outlined-hover`).then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.backgroundColor).to.equal(baseColor);
expect(cs.borderColor).to.equal(baseColor);
expect(cs.color).to.equal(invertColor);
});
cy.get(`#button-${name}-inverted-outlined`).then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.backgroundColor).to.equal(Cypress.env("transparent"));
expect(cs.borderColor).to.equal(invertColor);
expect(cs.color).to.equal(invertColor);
});
cy.get(`#button-${name}-light`).then(($) => {
const cs = window.getComputedStyle($[0]);
expect(cs.backgroundColor).to.equal(lightColor);
expect(cs.color).to.equal(darkColor);
});
}
});
});