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

Improve frontend test mocks #2827

Draft
wants to merge 10 commits into
base: development
Choose a base branch
from
Draft
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
528 changes: 525 additions & 3 deletions frontend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"husky": "^9.0.11",
"jsdom": "^26.0.0",
"lodash": "^4.17.21",
"msw": "^2.7.0",
"postcss-preset-mantine": "^1.14.4",
"postcss-simple-vars": "^7.0.1",
"prettier": "^3.2.5",
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/App/app.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { http } from "msw";
import { HttpResponse } from "msw";
import { describe, it } from "vitest";
import { render } from "@/tests";
import server from "@/tests/mocks/node";
import App from ".";

describe("App", () => {
it("should render without crash", () => {
server.use(
http.get("/api/system/searches", () => {
return HttpResponse.json({});
}),
);

render(<App />);
});
});
72 changes: 72 additions & 0 deletions frontend/src/pages/Blacklist/Movies/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* eslint-disable camelcase */
import { http } from "msw";
import { HttpResponse } from "msw";
import { render, screen, waitFor } from "@/tests";
import server from "@/tests/mocks/node";
import BlacklistMoviesView from ".";

describe("Blacklist Movies", () => {
it("should render with blacklisted movies", async () => {
server.use(
http.get("/api/system/settings", () => {
return HttpResponse.json({
general: {
theme: "auto",
},
});
}),
);

server.use(
http.get("/api/movies/blacklist", () => {
// TODO: Replace with Factory
return HttpResponse.json({
data: [
{
title: "Batman vs Teenage Mutant Ninja Turtles",
radarrId: 50,
provider: "yifysubtitles",
subs_id:
"https://yifysubtitles.ch/subtitles/batman-vs-teenage-mutant-ninja-turtles-2019-english-yify-19252",
language: {
name: "English",
code2: "en",
code3: "eng",
forced: false,
hi: false,
},
timestamp: "28 seconds ago",
parsed_timestamp: "01/23/25 05:39:36",
},
],
});
}),
);

render(<BlacklistMoviesView />);

await waitFor(() => {
expect(screen.getByText("yifysubtitles")).toBeInTheDocument();
});
});

it("should render without blacklisted movies", async () => {
server.use(
http.get("/api/movies/blacklist", () => {
return HttpResponse.json({
data: [],
});
}),
);

render(<BlacklistMoviesView />);

await waitFor(() => {
expect(
screen.getByText("No blacklisted movies subtitles"),
).toBeInTheDocument();
});

server.resetHandlers();
});
});
62 changes: 62 additions & 0 deletions frontend/src/pages/Blacklist/Series/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* eslint-disable camelcase */
import { http } from "msw";
import { HttpResponse } from "msw";
import { render, screen, waitFor } from "@/tests";
import server from "@/tests/mocks/node";
import BlacklistSeriesView from ".";

describe("Blacklist Series", () => {
it("should render without blacklisted series", async () => {
server.use(
http.get("/api/episodes/blacklist", () => {
return HttpResponse.json({
data: [],
});
}),
);

render(<BlacklistSeriesView />);

await waitFor(() => {
expect(
screen.getByText("No blacklisted series subtitles"),
).toBeInTheDocument();
});
});

it("should render with blacklisted series", async () => {
server.use(
http.get("/api/episodes/blacklist", () => {
// TODO: Replace with Factory
return HttpResponse.json({
data: [
{
seriesTitle: "Dragon Ball DAIMA",
episode_number: "1x14",
episodeTitle: "Taboo",
sonarrSeriesId: 56,
provider: "animetosho",
subs_id:
"https://animetosho.org/storage/attach/0022fd50/2293072.xz",
language: {
name: "English",
code2: "en",
code3: "eng",
forced: false,
hi: false,
},
timestamp: "now",
parsed_timestamp: "01/24/25 01:38:03",
},
],
});
}),
);

render(<BlacklistSeriesView />);

await waitFor(() => {
expect(screen.getByText("animetosho")).toBeInTheDocument();
});
});
});
16 changes: 0 additions & 16 deletions frontend/src/pages/Blacklist/blacklist.test.tsx

This file was deleted.

33 changes: 33 additions & 0 deletions frontend/src/pages/History/Movies/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { http } from "msw";
import { HttpResponse } from "msw";
import { render } from "@/tests";
import server from "@/tests/mocks/node";
import MoviesHistoryView from ".";

describe("History Movies", () => {
it("should render with movies", async () => {
server.use(
http.get("/api/movies/history", () => {
return HttpResponse.json({
data: [],
});
}),
);
server.use(
http.get("/api/providers", () => {
return HttpResponse.json({
data: [],
});
}),
);
server.use(
http.get("/api/system/languages", () => {
return HttpResponse.json({});
}),
);

render(<MoviesHistoryView />);

// TODO: Assert
});
});
21 changes: 21 additions & 0 deletions frontend/src/pages/History/Series/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { http } from "msw";
import { HttpResponse } from "msw";
import { render } from "@/tests";
import server from "@/tests/mocks/node";
import SeriesHistoryView from ".";

describe("History Series", () => {
it("should render with series", async () => {
server.use(
http.get("/api/episodes/history", () => {
return HttpResponse.json({
data: [],
});
}),
);

render(<SeriesHistoryView />);

// TODO: Assert
});
});
37 changes: 37 additions & 0 deletions frontend/src/pages/History/Statistics/HistoryStats.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { http } from "msw";
import { HttpResponse } from "msw";
import { render } from "@/tests";
import server from "@/tests/mocks/node";
import HistoryStats from "./HistoryStats";

describe("History Stats", () => {
it("should render without stats", async () => {
server.use(
http.get("/api/providers", () => {
return HttpResponse.json({
data: [],
});
}),
);
server.use(
http.get("/api/system/languages", () => {
return HttpResponse.json({});
}),
);
server.use(
http.get("/api/history/stats", () => {
return HttpResponse.json({
series: [],
});
}),
);

server.use(
http.get("/api/system/providers", () => {
return HttpResponse.json({});
}),
);

render(<HistoryStats />);
});
});
21 changes: 0 additions & 21 deletions frontend/src/pages/History/history.test.tsx

This file was deleted.

34 changes: 32 additions & 2 deletions frontend/src/pages/Movies/movies.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
import { describe } from "vitest";
import { render } from "@/tests";
import { http } from "msw";
import { HttpResponse } from "msw";
import { beforeEach, describe, it } from "vitest";
import { render, screen } from "@/tests";
import server from "@/tests/mocks/node";
import MovieMassEditor from "./Editor";
import MovieView from ".";

describe("Movies page", () => {
beforeEach(() => {
server.use(
http.get("/api/movies", () => {
return HttpResponse.json({
data: [],
});
}),
);
});

it("should render", () => {
render(<MovieView />);
});
});

describe("Movies editor page", () => {
beforeEach(() => {
server.use(
http.get("/api/movies", () => {
return HttpResponse.json({
data: [],
});
}),
);
server.use(
http.get("/api/system/languages/profiles", () => {
return HttpResponse.json([]);
}),
);
});

it("should render", () => {
render(<MovieMassEditor />);

expect(screen.getByText("Actions")).toBeInTheDocument();
});
});
30 changes: 29 additions & 1 deletion frontend/src/pages/Series/series.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
import { describe } from "vitest";
import { http } from "msw";
import { HttpResponse } from "msw";
import { beforeEach, describe, it } from "vitest";
import { render } from "@/tests";
import server from "@/tests/mocks/node";
import SeriesMassEditor from "./Editor";
import SeriesView from ".";

describe("Series page", () => {
beforeEach(() => {
server.use(
http.get("/api/series", () => {
return HttpResponse.json({
data: [],
});
}),
);
});

it("should render", () => {
render(<SeriesView />);
});
});

describe("Series editor page", () => {
beforeEach(() => {
server.use(
http.get("/api/series", () => {
return HttpResponse.json({
data: [],
});
}),
);
server.use(
http.get("/api/system/languages/profiles", () => {
return HttpResponse.json([]);
}),
);
});

it("should render", () => {
render(<SeriesMassEditor />);
});
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/Settings/components/Section.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Section } from "./Section";

describe("Settings section", () => {
const header = "Section Header";

it("should show header", () => {
render(<Section header="Section Header"></Section>);

Expand Down
Loading
Loading