Skip to content

Commit 5af18fc

Browse files
Merge pull request #16 from LottieFiles/tests/cypress-tests
Added cypress tests
2 parents 9b07876 + 9616bd3 commit 5af18fc

25 files changed

+3698
-298
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
env:
4141
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4242

43+
- name: Build project and run tests
44+
run: yarn run run-tests
45+
4346
- name: Build project
4447
run: yarn build
4548

babel.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// babel.config.js
2+
const { CODE_COVERAGE } = process.env;
3+
const plugins = [];
4+
5+
if (CODE_COVERAGE === "true") plugins.push(['babel-plugin-istanbul', { extension: ['.js', '.vue'] }]);
6+
7+
module.exports = {
8+
presets: [
9+
'@vue/app'
10+
],
11+
plugins: plugins
12+
}

cypress.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"video": false,
3+
"screenshotOnRunFailure": false
4+
}

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright 2022 Design Barn Inc.
3+
*/
4+
5+
context("Player component DOM check", () => {
6+
beforeEach(() => {
7+
cy.visit("http://localhost:8080/load");
8+
});
9+
10+
it('Loads an animation on page.', () => {
11+
cy.get("#player-one").should("have.length", 1);
12+
});
13+
14+
it('Loads an animation with empty URL and spinner displays.', function () {
15+
cy.get("#player-two .lf-spinner")
16+
.should("have.class", "lf-spinner");
17+
});
18+
19+
it('Loads an animation with invalid url.', function () {
20+
cy.get("#player-three lottie-player")
21+
.shadow()
22+
.find(".error")
23+
.should("have.class", "error");
24+
});
25+
26+
it("Looks inside shadow-dom div for animation-container class", () => {
27+
cy.get("#player-one lottie-player")
28+
.shadow()
29+
.find("#animation-container")
30+
.should("have.class", "main");
31+
});
32+
33+
it("Looks inside shadow-dom for aria-label", () => {
34+
cy.get("#player-one lottie-player")
35+
.shadow()
36+
.find("#animation-container")
37+
.should("have.attr", "aria-label");
38+
});
39+
40+
it("Verifies controls", () => {
41+
cy.get("#player-one")
42+
.find("#lottie-controls")
43+
cy.get("#player-one")
44+
.find("#lottie-pause-button")
45+
cy.get("#player-one")
46+
.find("#lottie-speed-button")
47+
cy.get("#player-one")
48+
.find("#lottie-seeker-input")
49+
cy.get("#player-one")
50+
.find("#lottie-toogle-loop-button")
51+
cy.get("#player-one")
52+
.find("#lottie-bg-picker-button")
53+
cy.get("#player-four")
54+
.find("#lottie-play-button")
55+
});
56+
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Copyright 2022 Design Barn Inc.
3+
*/
4+
5+
context("Player controls", () => {
6+
beforeEach(() => {
7+
cy.visit("http://localhost:8080/controls");
8+
});
9+
10+
it("clicks on play button and verifies animation is playing", function (done) {
11+
cy.get("#player-one lottie-player").then(($el) => {
12+
const playerOne = $el.get(0);
13+
14+
playerOne.addEventListener("play", () => {
15+
expect(playerOne.currentState).to.eq("playing");
16+
done();
17+
}, { once: true });
18+
});
19+
20+
cy.get("#player-one").find("#lottie-play-button").click();
21+
});
22+
23+
it("clicks on pause button and verifies animation is paused", function (done) {
24+
cy.get("#player-two lottie-player").then(($el) => {
25+
const playerTwo = $el.get(0);
26+
27+
playerTwo.addEventListener("pause", () => {
28+
expect(playerTwo.currentState).to.eq("paused");
29+
done();
30+
});
31+
});
32+
cy.get("#player-two").find("#lottie-pause-button").click();
33+
});
34+
35+
it("clicks on stop button and verififes animation is stopped and at frame 0", function (done) {
36+
cy.get("#player-three lottie-player").then(($el) => {
37+
const playerThree = $el.get(0);
38+
39+
playerThree.addEventListener("stop", () => {
40+
expect(playerThree.currentState).to.eq("stopped");
41+
expect(playerThree.getLottie().currentFrame).to.eq(0);
42+
done();
43+
});
44+
});
45+
46+
cy.get("#player-three").find("#lottie-stop-button").click();
47+
});
48+
49+
it("clicks on loop button and verififes animation loops", function (done) {
50+
cy.get("#player-four #lottie-controls").find("#lottie-toogle-loop-button").click();
51+
cy.get("#player-four lottie-player").then(($el) => {
52+
const playerFour = $el.get(0);
53+
54+
expect(playerFour.loop).to.eq(true);
55+
done();
56+
});
57+
});
58+
59+
it("clicks on color background choice and verifies background color", function () {
60+
cy.get("#player-five #lottie-controls").find("#lottie-bg-picker-button").click();
61+
cy.get("#player-five #lottie-controls").find("#lottie-color-choice-4").click();
62+
cy.get("#player-five lottie-player")
63+
.should("have.css", "background-color")
64+
.and("eq", "rgb(58, 146, 218)");
65+
});
66+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright 2022 Design Barn Inc.
3+
*/
4+
5+
context("Player state", () => {
6+
beforeEach(() => {
7+
cy.visit("http://localhost:8080/methods");
8+
});
9+
10+
it("Player-one should have play toggled.", function (done) {
11+
cy.get("#player-one lottie-player").then(($el) => {
12+
const playerOne = $el.get(0);
13+
14+
playerOne.addEventListener("play", () => {
15+
expect(playerOne.currentState).to.eq("playing");
16+
done();
17+
});
18+
});
19+
});
20+
21+
it("Player-two should have loop toggled.", function (done) {
22+
cy.get("#player-two lottie-player").then(($el) => {
23+
const playerTwo = $el.get(0);
24+
25+
playerTwo.addEventListener("play", () => {
26+
expect(playerTwo.currentState).to.eq("playing");
27+
expect(playerTwo.loop).to.eq(true);
28+
done();
29+
});
30+
});
31+
});
32+
33+
it("Player-three should play at x5 the speed", function(done) {
34+
cy.get("#player-three lottie-player").then(($el) => {
35+
const playerThree = $el.get(0);
36+
37+
playerThree.addEventListener("play", () => {
38+
expect(playerThree.getLottie().playSpeed).to.eq(5);
39+
done();
40+
}, { once: true })
41+
});
42+
});
43+
44+
it("Player-four Should have a green background.", () => {
45+
cy.get("#player-four lottie-player")
46+
.should("have.css", "background-color")
47+
.and("eq", "rgb(0, 255, 107)");
48+
});
49+
50+
it("Player-five should be paused and loop false.", function (done) {
51+
cy.get("#player-five lottie-player").then(($el) => {
52+
const playerFive = $el.get(0);
53+
54+
playerFive.addEventListener("pause", () => {
55+
expect(playerFive.currentState).to.eq("paused");
56+
expect(playerFive.loop).to.eq(false);
57+
done();
58+
});
59+
});
60+
});
61+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright 2022 Design Barn Inc.
3+
*/
4+
5+
context("Player properties", () => {
6+
beforeEach(() => {
7+
cy.visit("http://localhost:8080/properties");
8+
});
9+
10+
it("Player-one Should have a green background.", () => {
11+
cy.get("#player-one lottie-player")
12+
.should("have.css", "background-color")
13+
.and("eq", "rgb(0, 255, 107)");
14+
});
15+
16+
it("Player-two should play at x5 the speed", () => {
17+
cy.get("#player-two lottie-player").then(($el) => {
18+
const playerTwo = $el.get(0);
19+
20+
expect(playerTwo.speed).to.eq(5);
21+
});
22+
});
23+
24+
it("Player-three should autoplay and loop", function (done) {
25+
cy.get("#player-three lottie-player").then(($el) => {
26+
const playerThree = $el.get(0);
27+
28+
playerThree.addEventListener("play", () => {
29+
expect(playerThree.loop).to.eq(true);
30+
done();
31+
});
32+
});
33+
});
34+
});

cypress/plugins/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
require("@cypress/code-coverage/task")(on, config);
21+
// include any other plugin code...
22+
23+
// It's IMPORTANT to return the config object
24+
// with any changed environment variables
25+
return config;
26+
};

cypress/support/commands.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add('login', (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

0 commit comments

Comments
 (0)