Skip to content

Commit

Permalink
Fix dashboard tests (oof, these were bad) (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
benvinegar authored Feb 1, 2024
1 parent 86e6514 commit 7e4e561
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions app/routes/dashboard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// @vitest-environment jsdom
import { json } from "@remix-run/node";
import { test, describe, beforeAll } from "vitest";
import { test, describe, beforeAll, expect } from "vitest";
import 'vitest-dom/extend-expect';

import { createRemixStub } from "@remix-run/testing";
import {
render
render,
screen,
waitFor
} from "@testing-library/react";

import Dashboard from "./dashboard";
Expand Down Expand Up @@ -44,6 +46,10 @@ describe("Dashboard route", () => {
]);

render(<RemixStub />);

// wait until the rows render in the document
await waitFor(() => screen.findByText("Country"));
expect(screen.getByText('Country')).toBeInTheDocument();
});

test("renders with data", async () => {
Expand All @@ -54,7 +60,7 @@ describe("Dashboard route", () => {
sites: ['example'],
views: 100,
visits: 80,
visitors: 60,
visitors: 33, // made intentionally unique for test assertions
countByPath: [
['/', 100],
['/about', 80],
Expand All @@ -66,9 +72,9 @@ describe("Dashboard route", () => {
['Firefox', 60],
],
countByCountry: [
['United States', 100],
['Canada', 80],
['United Kingdom', 60],
['US', 100],
['CA', 80],
['UK', 60],
],
countByReferrer: [
['google.com', 100],
Expand Down Expand Up @@ -104,5 +110,16 @@ describe("Dashboard route", () => {
]);

render(<RemixStub />);

// wait until the rows render in the document
await waitFor(() => screen.findByText("Chrome"));

// assert some of the data we mocked actually rendered into the document
expect(screen.getByText('33')).toBeInTheDocument();
expect(screen.getByText('/about')).toBeInTheDocument();
expect(screen.getByText('Chrome')).toBeInTheDocument();
expect(screen.getByText('google.com')).toBeInTheDocument();
expect(screen.getByText('Canada')).toBeInTheDocument(); // assert converted CA -> Canada
expect(screen.getByText('Mobile')).toBeInTheDocument();
});
});

0 comments on commit 7e4e561

Please sign in to comment.