-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
133 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
|
@@ -51,27 +50,34 @@ 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, | ||
}); | ||
|
@@ -80,7 +86,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, | ||
}); | ||
|
@@ -89,15 +95,22 @@ 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]); | ||
|
@@ -109,7 +122,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", | ||
{ | ||
|
@@ -122,7 +135,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"); | ||
|
@@ -131,15 +144,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, | ||
}); | ||
|
@@ -148,7 +161,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, | ||
}); | ||
|
@@ -159,14 +172,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(); | ||
}); | ||
|
||
|
@@ -175,6 +189,10 @@ describe("Test the dataset form", () => { | |
catalog, | ||
submitLabel: "Envoyer", | ||
loadingLabel: "Ça charge...", | ||
formats: [{ | ||
id: 33, | ||
name: "Fichier Tabulaire", | ||
},] | ||
}; | ||
|
||
const { getByRole, rerender } = render(DatasetForm, { props }); | ||
|
@@ -193,7 +211,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", | ||
|
@@ -207,7 +230,12 @@ 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 }); | ||
|
@@ -222,14 +250,9 @@ 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", | ||
|
@@ -286,7 +309,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", | ||
|
@@ -300,7 +328,14 @@ 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, | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
client/src/lib/components/DatasetListItem/DatasetListItem.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.