Skip to content

Commit

Permalink
Progress on cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
Staijn1 committed Jun 2, 2024
1 parent 78269ef commit d2e56ab
Show file tree
Hide file tree
Showing 9 changed files with 3,119 additions and 39 deletions.
12 changes: 12 additions & 0 deletions aos/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: "http://127.0.0.1:5173",
viewportWidth: 1280,
viewportHeight: 720,
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
73 changes: 73 additions & 0 deletions aos/cypress/e2e/aos.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
describe('AOS', function() {
beforeEach(() => {
cy.visit('http://localhost:5173');
// cy.initAOS();
});

it('Should be defined', function() {
cy
.window()
.its('AOS')
.should('exist');
});

it('Should have init method', function() {
cy
.window()
.its('AOS.init')
.should('exist');
});

it('Should have refresh method', function() {
cy
.window()
.its('AOS.refresh')
.should('exist');
});

it('Should have refreshHard method', function() {
cy
.window()
.its('AOS.refreshHard')
.should('exist');
});

it('Should add aos-init class on all elements', function() {
cy.get('.aos-init').should('have.length', 24);
});

it('Should add aos-animate class on all visible elements', () => {
cy.get('.aos-animate').should('have.length', 6);
});

it('Should add or remove aos-animate classes regarding to their visibility after scroll', () => {
cy.scrollTo(0, 200);
cy.get('.aos-animate').should('have.length', 9);

cy.scrollTo(0, 800);
cy.get('.aos-animate').should('have.length', 15);

cy.scrollTo('top');
cy.get('.aos-animate').should('have.length', 6);
});

it('Should refresh on window resize and orientation change', () => {
cy.viewport('iphone-6');
cy.get('.aos-animate').should('have.length', 2);

cy.scrollTo(0, 100);
cy.get('.aos-animate').should('have.length', 2);

cy.viewport('iphone-6', 'landscape');
cy.get('.aos-animate').should('have.length', 4);

cy.scrollTo(0, 450);
cy.get('.aos-animate').should('have.length', 6);

cy.scrollTo('top');
cy.get('.aos-animate').should('have.length', 2);

cy.viewport(1280, 720);
cy.get('.aos-animate').should('have.length', 6);
});
});
5 changes: 5 additions & 0 deletions aos/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
53 changes: 53 additions & 0 deletions aos/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }

Cypress.Commands.add('initAOS', settings => {
cy.window().then((window) => {
console.log(window);
window.AOS.init(settings);
});
});

Cypress.Commands.add('dispatchEvent', (eventName, times = 1) => {
cy.window().then(window => {
const event = new Event(eventName);
for (let i = 0; i < times; i++) {
window.document.dispatchEvent(event);
}
});
});
20 changes: 20 additions & 0 deletions aos/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
23 changes: 11 additions & 12 deletions aos/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@
import AOS from '../src/js/aos.js';

document.querySelector('html').classList.remove('no-js');
if (!window.Cypress) {
const scrollCounter = document.querySelector('.js-scroll-counter');

AOS.init({
mirror: true
});
const scrollCounter = document.querySelector('.js-scroll-counter');

document.addEventListener('aos:in', function (e) {
console.log('in!', e.detail);
});
AOS.init({
mirror: true
});

window.addEventListener('scroll', function () {
scrollCounter.innerHTML = window.pageYOffset;
});
}
document.addEventListener('aos:in', function (e) {
console.log('in!', e.detail);
});

window.addEventListener('scroll', function () {
scrollCounter.innerHTML = window.pageYOffset;
});
</script>
</body>
</html>
Loading

0 comments on commit d2e56ab

Please sign in to comment.