2023-09-28 23:10:15 +02:00
|
|
|
import React from "react";
|
2023-09-29 20:25:24 +02:00
|
|
|
import '@testing-library/jest-dom';
|
2023-09-28 23:10:15 +02:00
|
|
|
import { render, screen } from "@testing-library/react";
|
|
|
|
import { ResponseRenderer } from "~/components/ResponseRenderer";
|
|
|
|
import { getMessage } from "./mocks/chrome.i18n";
|
|
|
|
|
|
|
|
describe("ResponseRenderer.tsx", () => {
|
|
|
|
beforeEach(() => {
|
2023-09-29 20:25:24 +02:00
|
|
|
const chrome: any = { i18n: { getMessage } };
|
2023-09-28 23:10:15 +02:00
|
|
|
global.chrome = chrome;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
global.chrome = undefined;
|
|
|
|
});
|
|
|
|
|
|
|
|
const defaultResponse = {
|
|
|
|
IPAddress: "89.222.123.45",
|
|
|
|
ISP: "FooBar Ltd",
|
|
|
|
City: "FooBar City",
|
|
|
|
Country: "United States of FooBar",
|
|
|
|
isTorExitNode: false
|
|
|
|
};
|
|
|
|
|
|
|
|
describe("when isTorExitNode is false", () => {
|
2023-09-29 20:25:24 +02:00
|
|
|
const response = { ...defaultResponse };
|
2023-09-28 23:10:15 +02:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
render(<ResponseRenderer response={response}/>);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("an IP address is rendered", () => {
|
|
|
|
expect(screen.getByText("IP Address")).toBeInTheDocument();
|
|
|
|
expect(screen.getByText(response.IPAddress)).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("an ISP is rendered", () => {
|
|
|
|
expect(screen.getByText("ISP")).toBeInTheDocument();
|
|
|
|
expect(screen.getByText(response.ISP)).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
2024-04-05 20:44:49 +02:00
|
|
|
test("a location is rendered", () => {
|
|
|
|
expect(screen.getByText("Location")).toBeInTheDocument();
|
|
|
|
expect(screen.getByText(`${response.City}, ${response.Country}`)).toBeInTheDocument();
|
2023-09-28 23:10:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test("isTorExitNode is rendered as No", () => {
|
|
|
|
expect(screen.getByText("Tor exit node")).toBeInTheDocument();
|
|
|
|
expect(screen.getByText("No")).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when isTorExitNode is true", () => {
|
2023-09-29 20:25:24 +02:00
|
|
|
const response = { ...defaultResponse, isTorExitNode: true };
|
2023-09-28 23:10:15 +02:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
render(<ResponseRenderer response={response}/>);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("isTorExitNode is rendered as Yes", () => {
|
|
|
|
expect(screen.getByText("Tor exit node")).toBeInTheDocument();
|
|
|
|
expect(screen.getByText("Yes")).toBeInTheDocument();
|
2023-09-29 20:25:24 +02:00
|
|
|
});
|
2023-09-28 23:10:15 +02:00
|
|
|
});
|
|
|
|
});
|