1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-08-04 20:37:29 +02:00

Cypress integrated with some tests

This commit is contained in:
Arnab Sen
2022-04-16 00:31:32 +05:30
parent 432143ba3e
commit f6cf7766f3
13 changed files with 269 additions and 1 deletions

View File

@@ -0,0 +1,64 @@
/// <reference types="cypress" />
const consoleAssert = (prompt, expected) => {
cy.get('#consolePromptEl').type(`${prompt}{enter}`);
// append the prompt at the beginning of the expected items
expected.unshift(`"> ${prompt}"`);
cy.get('ul[data-testid=consoleItems] li').should(
'have.length',
expected.length
);
expected.forEach((expectedValue, index) => {
cy.get('ul[data-testid=consoleItems] li').eq(index).contains(expectedValue);
});
};
describe('Console checks', () => {
beforeEach(() => {
cy.init();
cy.get('a[data-testid=toggleConsole]').click();
});
it('Simple arithmetic addition', () => {
consoleAssert('4+5', ['9']);
});
it('Simple arithmetic subtraction', () => {
consoleAssert('4-5', ['-1']);
});
it('Simple arithmetic multiplication', () => {
consoleAssert('4*5', ['20']);
});
it('Simple arithmetic division', () => {
consoleAssert('4/5', ['0.8']);
});
it('Division by Zero', () => {
consoleAssert('4/0', ['Infinity']);
});
it('Console log a message', () => {
consoleAssert("console.log('hello')", ['hello', 'undefined']);
});
it('Equality check', () => {
consoleAssert("100 == '100'", ['true']);
});
it('Strict-Equality check', () => {
consoleAssert("100 === '100'", ['false']);
});
it.only('Minimizing console', () => {
cy.get('#consoleEl').should('not.have.class', 'is-minimized');
cy.wait(200); // wait for animation to complete
cy.get('a[data-testid=toggleConsole]').click();
cy.get('#consoleEl').should('have.class', 'is-minimized');
});
});

View File

@@ -0,0 +1,94 @@
/// <reference types="cypress" />
describe('Pressing the layout buttons should change the layouts accordingly', () => {
before(() => {
cy.init();
cy.viewport(1270, 720);
});
const getLayoutBtnId = index => `#layoutBtn${index}`;
it('Default Layout', () => {
cy.get('body').should('have.class', 'layout-1');
cy.get('#js-code-side').should('be.visible');
cy.get('#js-demo-side').should('be.visible');
cy.get('#js-code-side').should(
'have.attr',
'style',
'width: calc(50% - 3px);'
);
cy.get('#js-code-side').should('have.attr', 'direction', 'vertical');
cy.get('#js-demo-side').should(
'have.attr',
'style',
'width: calc(50% - 3px);'
);
});
it('Layout 2', () => {
cy.get(getLayoutBtnId(2)).click();
cy.get('body').should('have.class', 'layout-2');
cy.get('#js-code-side').should('be.visible');
cy.get('#js-demo-side').should('be.visible');
cy.get('#js-code-side').should(
'have.attr',
'style',
'height: calc(50% - 3px);'
);
cy.get('#js-code-side').should('have.attr', 'direction', 'horizontal');
cy.get('#js-demo-side').should(
'have.attr',
'style',
'height: calc(50% - 3px);'
);
});
it('Layout 3', () => {
cy.get(getLayoutBtnId(3)).click();
cy.get('body').should('have.class', 'layout-3');
cy.get('#js-code-side').should('be.visible');
cy.get('#js-demo-side').should('be.visible');
cy.get('#js-code-side').should(
'have.attr',
'style',
'width: calc(50% - 3px);'
);
cy.get('#js-code-side').should('have.attr', 'direction', 'vertical');
cy.get('#js-demo-side').should(
'have.attr',
'style',
'width: calc(50% - 3px);'
);
});
it('Layout 4', () => {
cy.get(getLayoutBtnId(4)).click();
cy.get('body').should('have.class', 'layout-4');
cy.get('#js-code-side').should('not.be.visible');
cy.get('#js-demo-side').should('be.visible');
});
it('Layout 5', () => {
cy.get(getLayoutBtnId(5)).click();
cy.get('body').should('have.class', 'layout-5');
cy.get('#js-code-side').should('be.visible');
cy.get('#js-demo-side').should('be.visible');
cy.get('#js-code-side').should('have.attr', 'direction', 'horizontal');
});
});

View File

@@ -0,0 +1,27 @@
/// <reference types="cypress" />
describe('Modals pop-up when header btns are pressed', () => {
beforeEach(() => {
cy.init();
});
// Selectors for each button
const ADD_LIBRARY_SEL = '[data-event-action=addLibraryButtonClick]';
const NEW_SEL = '[aria-label="Start a new creation"]';
const LOGIN_SEL = '[data-event-action=loginButtonClick]';
it('Add Library', () => {
cy.get(ADD_LIBRARY_SEL).click();
cy.get('.modal__content').should('be.visible');
});
it('+ New', () => {
cy.get(NEW_SEL).click();
cy.get('.modal__content').should('be.visible');
});
it('Login/SignUp', () => {
cy.get(LOGIN_SEL).click();
cy.get('.modal__content').should('be.visible');
});
});