Skip to content

Commit

Permalink
♻️ refacto: Use fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed Feb 8, 2022
1 parent aa891d0 commit 1673510
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 91 deletions.
31 changes: 2 additions & 29 deletions src/components/Container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { fab } from "@fortawesome/free-brands-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
import * as search from "../utils/search";
import { Node } from "../utils/types";
import { origin, forks } from "../utils/fixtures";
import Container from "./Container";

library.add(fab, fas);
Expand All @@ -19,35 +20,7 @@ test("search forks", (done) => {
render(<Container />);
const searchInput = screen.getByPlaceholderText(/github.com/);
const submitButton = screen.getByRole("button");
const forkId = "django-nonrel/django";
const origin = {
nameWithOwner: "django/django",
stargazerCount: 54393,
forkCount: 23386,
defaultBranchRef: {
target: {
committedDate: "2020-12-18T08:23:22Z",
history: {
totalCount: 29060,
},
},
},
};
const forks = [
{
nameWithOwner: forkId,
stargazerCount: 214,
forkCount: 84,
defaultBranchRef: {
target: {
committedDate: "2020-08-29T14:23:26Z",
history: {
totalCount: 13990,
},
},
},
},
];
const forkId = forks[0].nameWithOwner;
const searchResult = [...[origin], ...forks];
const spy = jest
.spyOn(search, "searchPopularForks")
Expand Down
49 changes: 4 additions & 45 deletions src/components/ResultTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,14 @@ import { library } from "@fortawesome/fontawesome-svg-core";
import { fab } from "@fortawesome/free-brands-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
import ResultTable from "./ResultTable";
import { originAndForks as forks } from "../utils/fixtures";

library.add(fab, fas);

const forks = [
{
nameWithOwner: "django-nonrel/django",
stargazerCount: 214,
forkCount: 84,
defaultBranchRef: {
target: {
committedDate: "2020-08-29T14:23:26Z",
history: {
totalCount: 13990,
},
},
},
},
{
nameWithOwner: "django/django",
stargazerCount: 54330,
forkCount: 23377,
defaultBranchRef: {
target: {
committedDate: "2020-12-07:14:12Z",
history: {
totalCount: 29000,
},
},
},
},
{
nameWithOwner: "FlipperPA/django-mssql-backend",
stargazerCount: 18,
forkCount: 2,
defaultBranchRef: {
target: {
committedDate: "2020-01-13:11:12Z",
history: {
totalCount: 28017,
},
},
},
},
];

test("renders", () => {
const spy = jest
.spyOn(Date, "now")
.mockImplementation(() => new Date("2020-12-08T19:18:03.135Z").valueOf());
.mockImplementation(() => new Date("2020-12-18T19:18:03.135Z").valueOf());
const tree = renderer
.create(
<ResultTable
Expand All @@ -77,8 +36,8 @@ test("sorting", () => {
/>
);
// sorted by stargazerCount default
expect(screen.getByText(forks[1].nameWithOwner)).toBeInTheDocument();
expect(screen.queryByText(forks[0].nameWithOwner)).not.toBeInTheDocument();
expect(screen.getByText(forks[0].nameWithOwner)).toBeInTheDocument();
expect(screen.queryByText(forks[1].nameWithOwner)).not.toBeInTheDocument();
expect(screen.queryByText(forks[2].nameWithOwner)).not.toBeInTheDocument();
const repoTableHeader = screen.getByText("Repo");
// let's sort by repo name
Expand Down
8 changes: 4 additions & 4 deletions src/components/__snapshots__/ResultTable.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,16 @@ Array [
</a>
</td>
<td>
54330
54393
</td>
<td>
23377
23386
</td>
<td>
29000
29060
</td>
<td>
1 days ago
10 hours ago
</td>
</tr>
<tr>
Expand Down
46 changes: 46 additions & 0 deletions src/utils/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const origin = {
nameWithOwner: "django/django",
stargazerCount: 54393,
forkCount: 23386,
defaultBranchRef: {
target: {
committedDate: "2020-12-18T08:23:22Z",
history: {
totalCount: 29060,
},
},
},
};

const forks = [
{
nameWithOwner: "django-nonrel/django",
stargazerCount: 214,
forkCount: 84,
defaultBranchRef: {
target: {
committedDate: "2020-08-29T14:23:26Z",
history: {
totalCount: 13990,
},
},
},
},
{
nameWithOwner: "FlipperPA/django-mssql-backend",
stargazerCount: 18,
forkCount: 2,
defaultBranchRef: {
target: {
committedDate: "2020-01-13:11:12Z",
history: {
totalCount: 28017,
},
},
},
},
];

const originAndForks = [origin, ...forks];

export { origin, forks, originAndForks };
14 changes: 1 addition & 13 deletions src/utils/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,13 @@ import { ApolloQueryResult, ApolloError } from "@apollo/client";
import { searchPopularForks } from "./search";
import { Node } from "./types";
import { client } from "./graphql";
import { origin } from "./fixtures";

test("basic case", (done) => {
const url = "https://github.com/django/django";
const forks = {
nodes: [],
};
const origin = {
nameWithOwner: "django/django",
stargazerCount: 54393,
forkCount: 23386,
defaultBranchRef: {
target: {
committedDate: "2020-12-18T08:23:22Z",
history: {
totalCount: 29060,
},
},
},
};
const repository = {
...origin,
forks,
Expand Down

0 comments on commit 1673510

Please sign in to comment.