Skip to content

Commit

Permalink
menu.spec.js tests path corrected and running
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendy-Alejandra committed Mar 19, 2024
1 parent 5e4f7fd commit 88c1292
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions test/menu.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//Testing tool used to test the DOM
import { fireEvent } from "@testing-library/dom";
import { fireEvent } from "@testing-library/dom"; //Testing tool used to test the DOM
import { Menu } from "./../src/components/Menu.js";
import { navigateTo } from "./../src/router.js";
import { getApiKey } from "./../src/lib/apiStorage.js";

//Simulates our navigateTo router
jest.mock("./../src/router.js", () => ({
Expand All @@ -20,18 +20,23 @@ describe('Menu component', () => {
document.body.removeChild(menu);
});
it('renders all necessary elements', () => {
//To check all the elements exist and that they were created in the DOM
// Checks all the elements exist and that they were created in the DOM
expect(menu.querySelector('select[data-testid="select-filter"]')).toBeTruthy();
expect(menu.querySelector('select[data-testid="select-sort"]')).toBeTruthy();
expect(menu.querySelector('select[data-testid="select-sort-price"]')).toBeTruthy();
expect(menu.querySelector('button[data-testid="statistics"]')).toBeTruthy();
expect(menu.querySelector('button[data-testid="grupal-chat"]')).toBeTruthy();
expect(menu.querySelector('button[data-testid="button-clear"]')).toBeTruthy();
});

it('Clicking on group chat button should navigate to "/groupChat"', () => {
const chatGrupalButton = menu.querySelector('button[data-testid="grupal-chat"]');
//fireEvent simulates DOM events
fireEvent.click(chatGrupalButton);
expect(navigateTo).toHaveBeenCalledWith('/groupChat');
const apiKeySave = getApiKey();
fireEvent.click(chatGrupalButton); //fireEvent simulates DOM events
if (apiKeySave !== null) {
expect(navigateTo).toHaveBeenCalledWith('/groupChat', { id: null });
} else {
expect(navigateTo).toHaveBeenCalledWith('/ApiKey', { id: null });
}
});
});

0 comments on commit 88c1292

Please sign in to comment.