Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Add repo test
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad committed Nov 7, 2023
1 parent 227c3da commit eb235f0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import { ProjectHealthView, ProjectSettingsInput } from "gql/generated/types";
import {
ProjectHealthView,
ProjectSettingsInput,
RepoSettingsInput,
} from "gql/generated/types";
import { data } from "../testData";
import { ProjectType } from "../utils";
import { formToGql, gqlToForm } from "./transformers";
import { ViewsFormState } from "./types";

const { projectBase } = data;
const { projectBase, repoBase } = data;

describe("repo data", () => {
it("correctly converts from GQL to a form", () => {
expect(
gqlToForm(repoBase, { projectType: ProjectType.Repo })
).toStrictEqual(repoForm);
});

it("correctly converts from a form to GQL", () => {
expect(formToGql(repoForm, "repo")).toStrictEqual(repoResult);
});
});

describe("project data", () => {
it("correctly converts from GQL to a form", () => {
Expand All @@ -18,6 +34,30 @@ describe("project data", () => {
});
});

const repoForm: ViewsFormState = {
parsleyFilters: [
{
displayTitle: "repo-filter",
expression: "repo-filter",
caseSensitive: false,
exactMatch: false,
},
],
};

const repoResult: Pick<RepoSettingsInput, "projectRef"> = {
projectRef: {
id: "repo",
parsleyFilters: [
{
expression: "repo-filter",
caseSensitive: false,
exactMatch: false,
},
],
},
};

const projectForm: ViewsFormState = {
parsleyFilters: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ export const gqlToForm = ((data, { projectType }) => {
};
}) satisfies GqlToFormFunction<Tab>;

export const formToGql = ((formState, id) => ({
export const formToGql = (({ parsleyFilters, view }, id) => ({
projectRef: {
id,
parsleyFilters: formState.parsleyFilters.map(
parsleyFilters: parsleyFilters.map(
({ caseSensitive, exactMatch, expression }) => ({
expression,
caseSensitive,
exactMatch,
})
),
...("view" in formState && {
projectHealthView: formState.view.projectHealthView,
...(view && {
projectHealthView: view.projectHealthView,
}),
},
})) satisfies FormToGqlFunction<Tab>;
7 changes: 7 additions & 0 deletions src/pages/projectSettings/tabs/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ const repoBase: RepoSettingsQuery["repoSettings"] = {
nextRunTime: new Date("2022-03-30T17:07:10.942Z"),
},
],
parsleyFilters: [
{
expression: "repo-filter",
caseSensitive: false,
exactMatch: false,
},
],
},
vars: {
vars: { repo_name: "repo_value" },
Expand Down

0 comments on commit eb235f0

Please sign in to comment.