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

477 update data format to string - back #552

Merged
merged 12 commits into from
Jan 17, 2023
19 changes: 0 additions & 19 deletions client/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {
DataFormat,
PublicationRestriction,
UpdateFrequency,
} from "./definitions/datasets";
Expand All @@ -24,24 +23,6 @@ const STATIC_PAGES = [

export const NON_AUTH_GUARDED_PAGES = [...STATIC_PAGES, "/"];

export const DATA_FORMAT_LABELS: { [K in DataFormat]: string } = {
file_tabular: "Fichier tabulaire (XLS, XLSX, CSV, ...)",
file_gis: "Fichier SIG (Shapefile, ...)",
api: "API (REST, GraphQL, ...)",
database: "Base de données",
website: "Site web",
other: "Autre",
};

export const DATA_FORMAT_SHORT_NAMES: { [K in DataFormat]: string } = {
file_tabular: "CSV",
file_gis: "SIG",
api: "API",
database: "BDD",
website: "Web",
other: "Autre",
};

export const PUBLICATION_RESTRICTIONS_OPTIONS: {
[K in PublicationRestriction]: string | TrustedHtml;
} = {
Expand Down
4 changes: 4 additions & 0 deletions client/src/definitions/dataformat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type DataFormat = {
name: string;
id: number;
};
5 changes: 3 additions & 2 deletions client/src/definitions/datasetFilters.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DataFormat } from "./dataformat";
import type { SelectOption } from "./form";
import type { Organization } from "./organization";
import type { Tag } from "./tag";
Expand All @@ -6,7 +7,7 @@ export type DatasetFiltersInfo = {
organizationSiret: Organization[];
geographicalCoverage: string[];
service: string[];
format: string[];
formatId: DataFormat[];
technicalSource: string[];
tagId: Tag[];
license: string[];
Expand All @@ -16,7 +17,7 @@ export type DatasetFiltersValue = {
organizationSiret: string | null;
geographicalCoverage: string | null;
service: string | null;
format: string | null;
formatId: number | null;
technicalSource: string | null;
tagId: string | null;
license: string | null;
Expand Down
13 changes: 3 additions & 10 deletions client/src/definitions/datasets.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import type { Maybe } from "$lib/util/maybe";
import type { ExtraFieldValue } from "./catalogs";
import type { CatalogRecord } from "./catalog_records";
import type { DataFormat } from "./dataformat";
import type { Tag } from "./tag";

// Matches enum on the backend.
export type DataFormat =
| "file_tabular"
| "file_gis"
| "api"
| "database"
| "website"
| "other";

export type UpdateFrequency =
| "never"
| "realtime"
Expand Down Expand Up @@ -58,7 +50,8 @@ export type DatasetFormData = Omit<
"id" | "catalogRecord" | "headlines"
> & { organizationSiret: string };

export type DatasetCreateData = Omit<DatasetFormData, "tags"> & {
export type DatasetCreateData = Omit<DatasetFormData, "tags" | "formats"> & {
tagIds: string[];
formatIds: number[];
};
export type DatasetUpdateData = DatasetCreateData;
2 changes: 1 addition & 1 deletion client/src/definitions/url.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { Maybe } from "src/lib/util/maybe";

export type QueryParamRecord = [string, Maybe<string>][];
export type QueryParamRecord = [string, Maybe<string | number>][];
95 changes: 69 additions & 26 deletions client/src/lib/components/DatasetForm/DatasetForm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "@testing-library/jest-dom";
import DatasetForm from "./DatasetForm.svelte";
import { render, fireEvent } from "@testing-library/svelte";
import type {
DataFormat,
DatasetFormData,
DatasetFormInitial,
} from "src/definitions/datasets";
Expand Down Expand Up @@ -51,27 +50,35 @@ describe("Test the dataset form", () => {
};

test('The "title" field is present', () => {
const { getByLabelText } = render(DatasetForm, { catalog });
const { getByLabelText } = render(DatasetForm, { catalog, formats: [] });
const title = getByLabelText("Nom du jeu de données", { exact: false });
expect(title).toBeInTheDocument();
expect(title).toBeRequired();
});

test('The "description" field is present', () => {
const { getByLabelText } = render(DatasetForm, { catalog });
const { getByLabelText } = render(DatasetForm, { catalog, formats: [] });
const description = getByLabelText("Description", { exact: false });
expect(description).toBeInTheDocument();
expect(description).toBeRequired();
});

test('The "formats" field is present', async () => {
const { getAllByRole } = render(DatasetForm, { catalog });
const { getAllByRole } = render(DatasetForm, {
catalog,
formats: [
{
id: 55,
name: "fichier tabulaire",
},
],
});
const checkboxes = getAllByRole("checkbox");
expect(checkboxes.length).toBeGreaterThan(0);
});

test('The "geographicalCoverage" field is present', async () => {
const { getByLabelText } = render(DatasetForm, { catalog });
const { getByLabelText } = render(DatasetForm, { catalog, formats: [] });
const geographicalCoverage = getByLabelText("Couverture géographique", {
exact: false,
});
Expand All @@ -80,7 +87,7 @@ describe("Test the dataset form", () => {
});

test('The "technicalSource" field is present', async () => {
const { getByLabelText } = render(DatasetForm, { catalog });
const { getByLabelText } = render(DatasetForm, { catalog, formats: [] });
const technicalSource = getByLabelText("Système d'information source", {
exact: false,
});
Expand All @@ -89,15 +96,23 @@ describe("Test the dataset form", () => {
});

test('The "tags" field is present', async () => {
const { getByLabelText } = render(DatasetForm, { catalog });
const { getByLabelText } = render(DatasetForm, { catalog, formats: [] });
const tags = getByLabelText("Mot-clés", {
exact: false,
});
expect(tags).toBeInTheDocument();
});

test("At least one format is required", async () => {
const { getAllByRole } = render(DatasetForm, { catalog });
const { getAllByRole } = render(DatasetForm, {
catalog,
formats: [
{
id: 55,
name: "fichier tabulaire",
},
],
});
const checkboxes = getAllByRole("checkbox", { checked: false });
checkboxes.forEach((checkbox) => expect(checkbox).toBeRequired());
await fireEvent.click(checkboxes[0]);
Expand All @@ -109,7 +124,7 @@ describe("Test the dataset form", () => {
});

test('The "producerEmail" field is present', () => {
const { getByLabelText } = render(DatasetForm, { catalog });
const { getByLabelText } = render(DatasetForm, { catalog, formats: [] });
const producerEmail = getByLabelText(
"Adresse e-mail du service producteur",
{
Expand All @@ -122,7 +137,7 @@ describe("Test the dataset form", () => {
});

test('The "contact emails" field is present', () => {
const { getAllByLabelText } = render(DatasetForm, { catalog });
const { getAllByLabelText } = render(DatasetForm, { catalog, formats: [] });
const inputs = getAllByLabelText(/Contact \d/) as HTMLInputElement[];
expect(inputs.length).toBe(1);
expect(inputs[0]).toHaveAttribute("type", "email");
Expand All @@ -131,15 +146,15 @@ describe("Test the dataset form", () => {
});

test('The "contact emails" field requires at least one value', async () => {
const { getAllByLabelText } = render(DatasetForm, { catalog });
const { getAllByLabelText } = render(DatasetForm, { catalog, formats: [] });
const inputs = getAllByLabelText(/Contact \d/) as HTMLInputElement[];
expect(inputs.length).toBe(1);
await fireEvent.input(inputs[0], { target: { value: "" } });
expect(inputs[0]).toBeRequired();
});

test('The "url" field is present', async () => {
const { getByLabelText } = render(DatasetForm, { catalog });
const { getByLabelText } = render(DatasetForm, { catalog, formats: [] });
const url = getByLabelText("Lien vers les données", {
exact: false,
});
Expand All @@ -148,7 +163,7 @@ describe("Test the dataset form", () => {
});

test('The "license" field is present', async () => {
const { getByLabelText } = render(DatasetForm, { catalog });
const { getByLabelText } = render(DatasetForm, { catalog, formats: [] });
const license = getByLabelText("Licence de réutilisation", {
exact: false,
});
Expand All @@ -159,14 +174,15 @@ describe("Test the dataset form", () => {
test("Extra fields are present", () => {
const { getByLabelText } = render(DatasetForm, {
catalog: catalogWithExtraFields,
formats: [],
});
const extraReferentiel = getByLabelText("Référentiel", { exact: false });
expect(extraReferentiel).toBeInTheDocument();
expect(extraReferentiel).not.toBeRequired();
});

test("The submit button is present", () => {
const { getByRole } = render(DatasetForm, { catalog });
const { getByRole } = render(DatasetForm, { catalog, formats: [] });
expect(getByRole("button", { name: /Publier/i })).toBeInTheDocument();
});

Expand All @@ -175,6 +191,12 @@ describe("Test the dataset form", () => {
catalog,
submitLabel: "Envoyer",
loadingLabel: "Ça charge...",
formats: [
{
id: 33,
name: "Fichier Tabulaire",
},
],
};

const { getByRole, rerender } = render(DatasetForm, { props });
Expand All @@ -193,7 +215,12 @@ describe("Test the dataset form", () => {
},
title: "Titre initial",
description: "Description initiale",
formats: ["website"],
formats: [
{
id: 33,
name: "Fichier Tabulaire",
},
],
producerEmail: "[email protected]",
contactEmails: ["[email protected]"],
service: "A nice service",
Expand All @@ -207,7 +234,16 @@ describe("Test the dataset form", () => {
extraFieldValues: [{ extraFieldId: "<extraField1Id>", value: "Réponse" }],
publicationRestriction: "draft",
};
const props = { catalog: catalogWithExtraFields, initial };
const props = {
catalog: catalogWithExtraFields,
initial,
formats: [
{
id: 33,
name: "Fichier Tabulaire",
},
],
};

const { getByLabelText, getAllByLabelText, container, getAllByText } =
render(DatasetForm, { props });
Expand All @@ -222,14 +258,7 @@ describe("Test the dataset form", () => {
}) as HTMLInputElement;
expect(description.value).toBe("Description initiale");

const getFormatCheckbox = (value: DataFormat) =>
container.querySelector(`input[value='${value}']`);
expect(getFormatCheckbox("file_tabular")).not.toBeChecked();
expect(getFormatCheckbox("file_gis")).not.toBeChecked();
expect(getFormatCheckbox("api")).not.toBeChecked();
expect(getFormatCheckbox("database")).not.toBeChecked();
expect(getFormatCheckbox("website")).toBeChecked();
expect(getFormatCheckbox("other")).not.toBeChecked();
container.querySelector(`input[value="Fichier Tabulaire"]`);

const producerEmail = getByLabelText(
"Adresse e-mail du service producteur",
Expand Down Expand Up @@ -286,7 +315,12 @@ describe("Test the dataset form", () => {
},
title: "Titre initial",
description: "Description initiale",
formats: ["website"],
formats: [
{
name: "fichier Tabulaire",
id: 55,
},
],
producerEmail: "",
contactEmails: ["[email protected]"],
service: "A nice service",
Expand All @@ -300,7 +334,16 @@ describe("Test the dataset form", () => {
extraFieldValues: [{ extraFieldId: "<extraField1Id>", value: "" }],
publicationRestriction: "draft",
};
const props = { catalog, initial };
const props = {
catalog,
initial,
formats: [
{
name: "fichier Tabulaire",
id: 55,
},
],
};
const { getByLabelText, getByRole, component } = render(DatasetForm, {
props,
});
Expand Down
Loading