forked from michalsnik/aos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for animatedClassName, initClassName, useClassNames, mirror…
… and js events
- Loading branch information
1 parent
e5f3252
commit 71296f8
Showing
7 changed files
with
242 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
describe('JS Events', function() { | ||
context('default events', function() { | ||
let aosInStub; | ||
let aosOutStub; | ||
|
||
before(() => { | ||
aosInStub = cy.stub(); | ||
aosOutStub = cy.stub(); | ||
cy | ||
.visit('/') | ||
.document() | ||
.then(document => { | ||
document.addEventListener('aos:in', aosInStub); | ||
document.addEventListener('aos:out', aosOutStub); | ||
}) | ||
.initAOS(); | ||
}); | ||
|
||
it('Should trigger custom events', function() { | ||
expect(aosInStub).to.have.callCount(6); | ||
expect(aosOutStub).to.be.not.called; | ||
|
||
cy.scrollTo(0, 800); | ||
cy.wait(0, () => { | ||
expect(aosInStub).to.have.callCount(15); | ||
}); | ||
|
||
cy.scrollTo('top'); | ||
cy.wait(0, () => { | ||
expect(aosInStub).to.have.callCount(15); | ||
expect(aosOutStub).to.have.callCount(9); | ||
}); | ||
}); | ||
}); | ||
|
||
context('custom events', function() { | ||
let aosInStub; | ||
let aosOutStub; | ||
|
||
before(() => { | ||
aosInStub = cy.stub(); | ||
aosOutStub = cy.stub(); | ||
cy | ||
.visit('/') | ||
.document() | ||
.then(document => { | ||
document.addEventListener('aos:in:super-duper', aosInStub); | ||
document.addEventListener('aos:out:super-duper', aosOutStub); | ||
}) | ||
.initAOS(); | ||
}); | ||
|
||
it('Should trigger custom events', function() { | ||
expect(aosInStub).to.be.not.called; | ||
expect(aosOutStub).to.be.not.called; | ||
|
||
cy.scrollTo(0, 350); | ||
cy.wait(0, () => { | ||
expect(aosInStub).to.be.calledOnce; | ||
}); | ||
|
||
cy.scrollTo('top'); | ||
cy.wait(0, () => { | ||
expect(aosOutStub).to.be.calledOnce; | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
describe('setting: animatedClassName', function() { | ||
context('with: "rawr"', function() { | ||
before(() => { | ||
cy.visit('/'); | ||
cy.initAOS({ | ||
animatedClassName: 'rawr' | ||
}); | ||
}); | ||
|
||
it('Should set proper class names on AOS elements', function() { | ||
cy.get('.aos-animate').should('have.length', 0); | ||
cy.get('.rawr').should('have.length', 6); | ||
|
||
cy.scrollTo(0, 800); | ||
cy.get('.aos-animate').should('have.length', 0); | ||
cy.get('.rawr').should('have.length', 15); | ||
}); | ||
}); | ||
|
||
context('with: null', function() { | ||
before(() => { | ||
cy.visit('/'); | ||
cy.initAOS({ | ||
animatedClassName: null | ||
}); | ||
}); | ||
|
||
it('Should not set class names on AOS elements on scroll', function() { | ||
cy.get('.aos-animate').should('have.length', 0); | ||
cy.scrollTo(0, 800); | ||
cy.get('.aos-animate').should('have.length', 0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
describe('setting: initClassName', function() { | ||
context('with: "rawr"', function() { | ||
before(() => { | ||
cy.visit('/'); | ||
cy.initAOS({ | ||
initClassName: 'rawr' | ||
}); | ||
}); | ||
|
||
it('Should set proper class names on AOS elements', function() { | ||
cy.get('.aos-init').should('have.length', 0); | ||
cy.get('.rawr').should('have.length', 24); | ||
}); | ||
}); | ||
|
||
context('with: null', function() { | ||
before(() => { | ||
cy.visit('/'); | ||
cy.initAOS({ | ||
initClassName: null | ||
}); | ||
}); | ||
|
||
it('Should not set initial class name on AOS elements', function() { | ||
cy.get('.aos-init').should('have.length', 0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
describe('setting: mirror', function() { | ||
before(() => { | ||
cy.visit('/'); | ||
cy.viewport(1280, 650); | ||
cy.initAOS({ | ||
mirror: true, | ||
offset: 50 | ||
}); | ||
}); | ||
|
||
it('Should animate in and out', function() { | ||
cy.get('.aos-animate').should('have.length', 6); | ||
|
||
cy.scrollTo(0, 50); | ||
cy.get('.aos-animate').should('have.length', 9); | ||
cy | ||
.get('.aos-init') | ||
.eq(0) | ||
.should('have.class', 'aos-animate'); | ||
|
||
cy.scrollTo(0, 300); | ||
cy.get('.aos-animate').should('have.length', 6); | ||
cy | ||
.get('.aos-init') | ||
.eq(0) | ||
.should('not.have.class', 'aos-animate'); | ||
|
||
cy.scrollTo(0, 350); | ||
cy.get('.aos-animate').should('have.length', 9); | ||
cy | ||
.get('.aos-init') | ||
.eq(3) | ||
.should('have.class', 'aos-animate'); | ||
|
||
cy.scrollTo(0, 600); | ||
cy.get('.aos-animate').should('have.length', 6); | ||
cy | ||
.get('.aos-init') | ||
.eq(3) | ||
.should('not.have.class', 'aos-animate'); | ||
|
||
cy.scrollTo(0, 650); | ||
cy.get('.aos-animate').should('have.length', 9); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
describe('setting: useClassNames', function() { | ||
context('just useClassNames', function() { | ||
before(() => { | ||
cy.visit('/animatecss.html'); | ||
cy.initAOS({ | ||
useClassNames: true | ||
}); | ||
}); | ||
|
||
it('Should set proper custom class names on AOS elements', function() { | ||
cy.get('.aos-animate').should('have.length', 6); | ||
cy.get('.fadeInUp').should('have.length', 6); | ||
|
||
cy.scrollTo(0, 800); | ||
cy.get('.aos-animate').should('have.length', 15); | ||
cy.get('.fadeInUp').should('have.length', 15); | ||
}); | ||
}); | ||
|
||
context('with animatedClassName and initClassName', function() { | ||
before(() => { | ||
cy.visit('/animatecss.html'); | ||
cy.initAOS({ | ||
useClassNames: true, | ||
initClassName: false, | ||
animatedClassName: 'animate' | ||
}); | ||
}); | ||
|
||
it('Should set proper custom class names on AOS elements', function() { | ||
cy.get('.aos-init').should('have.length', 0); | ||
cy.get('.aos-animate').should('have.length', 0); | ||
|
||
cy.get('.animate').should('have.length', 6); | ||
cy.get('.fadeInUp').should('have.length', 6); | ||
|
||
cy.scrollTo(0, 800); | ||
cy.get('.aos-animate').should('have.length', 0); | ||
cy.get('.animate').should('have.length', 15); | ||
cy.get('.fadeInUp').should('have.length', 15); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters