diff --git a/com-dict-client/src/components/DictionaryView/word_summary.test.js b/com-dict-client/src/components/DictionaryView/word_summary.test.js new file mode 100644 index 0000000..e81fa7c --- /dev/null +++ b/com-dict-client/src/components/DictionaryView/word_summary.test.js @@ -0,0 +1,54 @@ +import React from "react"; +import { render, screen } from "@testing-library/react"; +import Word from "./word_summary"; + +describe("Word_Summary", () => { + const data = { + dislikes: 0, + createdAt: 1596825000000, + trending_factor: 17, + head_term: "Strip Jenga", + word_of_the_day: "2023-03-21", + other_language_def: + "A term coined by Terrson to represent a form of Jenga where one removes an article of clothing whenever the tower falls.", + categories: "Internet", + uname: "Asitha Indrajith", + alphabatical: "S", + related_words: [], + user_id: "bs9J0Es5k4apyNl1XjzbiATr57v2", + other_language_term: "Strip Jenga", + example: + "It was a fearsome sight indeed after the tower fell for the last time, after that, strip jenga was forever banned in the lounge.", + other_language: "English", + word_classes: ["Noun"], + likes: 5, + pronunciation: null, + id: "T26vX5qQe1BPrUktFBtO", + }; + + test("renders correctly", () => { + render(); + const head_termElement = screen.getAllByText("Strip Jenga"); + expect(head_termElement[0]).toBeInTheDocument(); + expect(head_termElement[1]).toBeInTheDocument(); + + const other_languageElement = screen.getByText("English"); + expect(other_languageElement).toBeInTheDocument(); + + const word_classesElement = screen.getByText("Noun"); + expect(word_classesElement).toBeInTheDocument(); + + const other_language_defElement = screen.getByText( + "A term coined by Terrson to represent a form of Jenga where one removes an article of clothing whenever the tower falls." + ); + expect(other_language_defElement).toBeInTheDocument(); + + const exampleElement = screen.getByText( + "It was a fearsome sight indeed after the tower fell for the last time, after that, strip jenga was forever banned in the lounge." + ); + expect(exampleElement).toBeInTheDocument(); + + const unameElement = screen.getByText("Asitha Indrajith"); + expect(unameElement).toBeInTheDocument(); + }); +}); diff --git a/com-dict-client/src/setupTests.js b/com-dict-client/src/setupTests.js index 74b1a27..449100b 100644 --- a/com-dict-client/src/setupTests.js +++ b/com-dict-client/src/setupTests.js @@ -3,3 +3,18 @@ // expect(element).toHaveTextContent(/react/i) // learn more: https://github.com/testing-library/jest-dom import '@testing-library/jest-dom/extend-expect'; +beforeAll(() => { + Object.defineProperty(window, "matchMedia", { + writable: true, + value: jest.fn().mockImplementation(query => ({ + matches: false, + media: query, + onchange: null, + addListener: jest.fn(), // Deprecated + removeListener: jest.fn(), // Deprecated + addEventListener: jest.fn(), + removeEventListener: jest.fn(), + dispatchEvent: jest.fn(), + })) + }); +}); \ No newline at end of file