Skip to content

Commit

Permalink
Implemented Cypress tests and resolved package conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
BeNikk committed Feb 12, 2025
1 parent cfe01ec commit 4365e9b
Show file tree
Hide file tree
Showing 7 changed files with 5,755 additions and 2,559 deletions.
12 changes: 12 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
viewportWidth: 1400,
viewportHeight: 1000,
testIsolation: false
},
});
152 changes: 152 additions & 0 deletions cypress/e2e/main.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
Cypress.on("uncaught:exception", (err, runnable) => {
return false;
});

describe("MusicBlocks Application", () => {
before(() => {
cy.visit("http://localhost:3000");
});

afterEach(() => {
console.log("Next test running, no reload should happen");
});

describe("Loading and Initial Render", () => {
it("should display the loading animation and then the main content", () => {
cy.get("#loading-image-container").should("be.visible");
cy.contains("#loadingText", "Loading Complete!", { timeout: 20000 }).should("be.visible");
cy.wait(10000);
cy.get("#canvas", { timeout: 10000 }).should("be.visible");
});

it("should display the Musicblocks guide page", () => {
cy.get(".heading").contains("Welcome to Music Blocks");
});
});

describe("Audio Controls", () => {
it("should have a functional play button", () => {
cy.get("#play").should("be.visible").click();
cy.window().then((win) => {
const audioContext = win.Tone.context;
cy.wrap(audioContext.state).should("eq", "running");
});
});

it("should have a functional stop button", () => {
cy.get("#stop").should("be.visible").click();
});
});

describe("Toolbar and Navigation", () => {
it("should open the language selection dropdown", () => {
cy.get("#aux-toolbar").invoke("show");
cy.get("#languageSelectIcon").click({ force: true });
cy.get("#languagedropdown").should("be.visible");
});

it("should toggle full-screen mode", () => {
cy.get("#FullScreen").click();
cy.document().its("fullscreenElement").should("exist");
cy.get("#FullScreen").click();
cy.document().its("fullscreenElement").should("not.exist");
});

it("should toggle the toolbar menu", () => {
cy.get("#toggleAuxBtn").click();
cy.get("#aux-toolbar").should("be.visible");
cy.get("#toggleAuxBtn").click();
cy.get("#aux-toolbar").should("not.be.visible");
});
});

describe("File Operations", () => {
it("should open the file load modal", () => {
cy.get("#load").click();
cy.get("#myOpenFile").should("exist");
});

it("should open the save dropdown", () => {
cy.get("#saveButton").click();
cy.get("#saveddropdownbeg").should("be.visible");
});

it("should display file save options", () => {
cy.get("#saveButton").click();
cy.get("#saveddropdownbeg").should("be.visible");
cy.get("#save-html-beg").should("exist");
cy.get("#save-png-beg").should("exist");
});

it('should click the New File button and verify "New Project" appears', () => {
cy.get('#newFile > .material-icons')
.should('exist')
.and('be.visible');
cy.get('#newFile > .material-icons').click();
cy.wait(500);
cy.contains('New project').should('be.visible');
});
});

describe("UI Elements", () => {
it('should verify that bottom bar elements exist and are visible', () => {
const bottomBarElements = [
'#Home\\ \\[HOME\\] > img',
'#Show\\/hide\\ blocks > img',
'#Expand\\/collapse\\ blocks > img',
'#Decrease\\ block\\ size > img',
'#Increase\\ block\\ size > img'
];

bottomBarElements.forEach(selector => {
cy.get(selector).should('exist').and('be.visible');
});
});

it('should verify sidebar elements exist, are visible, and clickable', () => {
const sidebarElements = [
'thead > tr > :nth-child(1) > img',
'tr > :nth-child(2) > img',
'tr > :nth-child(3) > img'
];

sidebarElements.forEach(selector => {
cy.get(selector)
.should('exist')
.and('be.visible')
.click();
});
});

it('should verify that Grid, Clear, and Collapse elements exist and are visible', () => {
const elements = [
'#Grid > img',
'#Clear',
'#Collapse > img'
];
elements.forEach(selector => {
cy.get(selector).should('exist').and('be.visible');
});
});

it('should verify that all nth-child elements from 1 to 6 exist', () => {
for (let i = 1; i <= 6; i++) {
cy.get(`[width="126"] > tbody > :nth-child(${i})`)
.should('exist')
.and('be.visible');
}
});
});

describe("Planet Page Interaction", () => {
it('should load the Planet page and return to the main page when clicking the close button', () => {
cy.get('#planetIcon > .material-icons')
.should('exist')
.and('be.visible')
.click();
cy.get('#planet-iframe')
.should('be.visible');
});
});

});
5 changes: 5 additions & 0 deletions 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"
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js 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) => { ... })
17 changes: 17 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.js 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'
Loading

0 comments on commit 4365e9b

Please sign in to comment.