Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test - DictionaryView #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions com-dict-client/src/components/DictionaryView/word_summary.test.js
Original file line number Diff line number Diff line change
@@ -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(<Word data={data} />);
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();
});
});
15 changes: 15 additions & 0 deletions com-dict-client/src/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}))
});
});