Skip to content

Commit

Permalink
feat: 2122: recherche entreprise (#1398)
Browse files Browse the repository at this point in the history
* feat: 2122: recherche entreprise

* fix: bouton

* fix: tests cypress
  • Loading branch information
remy-auricoste authored Aug 5, 2024
1 parent c2d912d commit c17a9b1
Show file tree
Hide file tree
Showing 23 changed files with 492 additions and 126 deletions.
4 changes: 2 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fileignoreconfig:
- filename: server/src/db/migrations/202405230000000-migrate-fix-missing-date-blacklist.ts
checksum: 0c1b814245a58b8ca788fbfab9899206edbddaae795d56963f86c5aa83ea555f
- filename: server/src/http/controllers/application.controller.test.ts
checksum: 931dca1e50c7215fee39e1b648e15d9d12482f2537e8d97f63782856c351e5f8
checksum: 1f3c9b8cd7c578252a0c41ca9028672712a5bca2ce1686cba83ff60305708305
- filename: server/src/http/controllers/appointments/appointments.controller.ts
checksum: dc77c04efc26dcd8ca4816f392ab24a32a92cb45ca4b94adb593a08e7a2d231e
- filename: server/src/http/routes/appointmentRequest.controller.ts
Expand Down Expand Up @@ -154,7 +154,7 @@ fileignoreconfig:
- filename: ui/components/espace_pro/Admin/utilisateurs/infoDetails/InfoDetails.tsx
checksum: be2ad6ca5c2bd36d26cd7aebb33ab876bd32662be3735fee3b167325c284ccff
- filename: ui/components/espace_pro/AjouterVoeux.tsx
checksum: 0a8365f461dfaeffa4970365fb1c45ed63c5e28588a63382e1b3e99dfdb42b9a
checksum: 8ba50b9d7127114cd71789bbf7c26dc19b4b915ab4ae2e2e033c1ca65accee94
- filename: ui/components/footer.tsx
checksum: d82b5a7d6905070fb32383864566fc16eae4797ca18f82782fb32c95a0d50369
- filename: ui/pages/accessibilite.tsx
Expand Down
5 changes: 3 additions & 2 deletions cypress/e2e/create-cfa-with-entreprise-siret.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ describe("create-cfa-with-entreprise-siret", () => {
cy.viewport(1254, 721)

FlowCreationCfa.siretPage.goTo()
FlowCreationCfa.siretPage.fillSiret(entrepriseSiret)
FlowCreationCfa.siretPage.searchAndSelectSiret(entrepriseSiret)
FlowCreationCfa.siretPage.submit()
cy.contains("Le numéro siret n'est pas référencé comme centre de formation.")
cy.url().should("contain", "/espace-pro/creation/detail")
cy.contains("CAISSE NATIONALE DE L'ASSURANC")
})
})
2 changes: 1 addition & 1 deletion cypress/e2e/create-entreprise-account-no-delegation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("create-entreprise-account-no-delegation", () => {
const studyLevel = "Cap, autres formations niveau (Infrabac)"

FlowCreationEntreprise.siretPage.goTo()
FlowCreationEntreprise.siretPage.fillSiret(siret)
FlowCreationEntreprise.siretPage.searchAndSelectSiret(siret)
FlowCreationEntreprise.siretPage.submit()

FlowCreationEntreprise.personalInfosPage.fillForm({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("create-recruiter-account-manual-validation", () => {
const studyLevel = "Indifférent"

FlowCreationEntreprise.siretPage.goTo()
FlowCreationEntreprise.siretPage.fillSiret(siret)
FlowCreationEntreprise.siretPage.searchAndSelectSiret(siret)
FlowCreationEntreprise.siretPage.submit()

FlowCreationEntreprise.personalInfosPage.fillForm({
Expand Down
3 changes: 1 addition & 2 deletions cypress/e2e/create-recruiter-account-siret-inexistent.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ describe("create-recruiter-account-siret-inexistent", () => {

FlowCreationEntreprise.siretPage.goTo()
FlowCreationEntreprise.siretPage.fillSiret(siret)
FlowCreationEntreprise.siretPage.submit()

cy.contains("Le numéro siret est invalide.", { timeout: 10000 }).should("exist")
cy.contains("Pas de résultats pour votre recherche", { timeout: 10000 }).should("exist")
cy.get("button[type='submit']", { timeout: 10000 }).should("be.disabled")
})
})
3 changes: 1 addition & 2 deletions cypress/e2e/create-recruiter-account-siret-malformate.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ describe("create-recruiter-account-siret-malformate", () => {

FlowCreationEntreprise.siretPage.goTo()
FlowCreationEntreprise.siretPage.fillSiret(siret)
// unfocus
cy.get("h2").first().click()

cy.contains("Le numéro de SIRET saisi n’est pas valide", { timeout: 10000 }).should("exist")
cy.get("button[type='submit']", { timeout: 10000 }).should("be.disabled")
})
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/create-recruiter-account.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("create-recruiter-account", () => {
const studyLevel = "Cap, autres formations niveau (Infrabac)"

FlowCreationEntreprise.siretPage.goTo()
FlowCreationEntreprise.siretPage.fillSiret(siret)
FlowCreationEntreprise.siretPage.searchAndSelectSiret(siret)
FlowCreationEntreprise.siretPage.submit()

FlowCreationEntreprise.personalInfosPage.fillForm({
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/manual/create-cfa-account-autovalidated.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LoginBar } from "../../pages/LoginBar"
import { generateRandomString } from "../../utils/generateRandomString"

describe("create-cfa-account-autovalidated", () => {
it("test create-cfa-account-autovalidated", () => {
it.skip("test create-cfa-account-autovalidated", () => {
const cfaEmail = `${generateRandomString()}@${Cypress.env("CFA_AUTOVALIDE_EMAIL_DOMAIN")}`
const cfaSiret = Cypress.env("CFA_AUTOVALIDE_SIRET")
const firstName = "John"
Expand All @@ -16,7 +16,7 @@ describe("create-cfa-account-autovalidated", () => {
// cy.deleteMany({ establishment_siret: cfaSiret }, { collection: "userrecruteurs" })

FlowCreationCfa.siretPage.goTo()
FlowCreationCfa.siretPage.fillSiret(cfaSiret)
FlowCreationCfa.siretPage.searchAndSelectSiret(cfaSiret)
FlowCreationCfa.siretPage.submit()

FlowCreationCfa.personalInfosPage.fillForm({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { FlowCreationCfa } from "../pages/FlowCreationCfa"
import { FlowCreationEntreprise } from "../pages/FlowCreationEntreprise"
import { FlowCreationCfa } from "../../pages/FlowCreationCfa"
import { FlowCreationEntreprise } from "../../pages/FlowCreationEntreprise"

describe("create-entreprise-account-siret-cfa", () => {
it("test create-entreprise-account-siret-cfa", () => {
it.skip("test create-entreprise-account-siret-cfa", () => {
cy.viewport(1271, 721)

const cfaSiret = Cypress.env("CFA_AUTOVALIDE_SIRET")

FlowCreationEntreprise.siretPage.goTo()
FlowCreationEntreprise.siretPage.fillSiret(cfaSiret)
FlowCreationEntreprise.siretPage.searchAndSelectSiret(cfaSiret)
FlowCreationEntreprise.siretPage.submit()
cy.contains("veuillez utiliser ce lien", { timeout: 10000 }).click()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("create-recruiter-account-manual-validation-no-offer", () => {
const lastName = "Doe"

FlowCreationEntreprise.siretPage.goTo()
FlowCreationEntreprise.siretPage.fillSiret(siret)
FlowCreationEntreprise.siretPage.searchAndSelectSiret(siret)
FlowCreationEntreprise.siretPage.submit()

FlowCreationEntreprise.personalInfosPage.fillForm({
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/manual/entreprise-create-offre.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("entreprise-create-offre", () => {
const lastName = `Doe-${generateRandomString()}`

FlowCreationEntreprise.siretPage.goTo()
FlowCreationEntreprise.siretPage.fillSiret(siret)
FlowCreationEntreprise.siretPage.searchAndSelectSiret(siret)
FlowCreationEntreprise.siretPage.submit()

FlowCreationEntreprise.personalInfosPage.fillForm({
Expand Down
4 changes: 4 additions & 0 deletions cypress/pages/FlowCreationCfa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export const FlowCreationCfa = {
cy.visit(`${Cypress.env("ui")}/espace-pro/creation/cfa`)
cy.contains("Comment s'inscrire ?", { timeout: 10000 }).should("exist")
},
searchAndSelectSiret(siret: string) {
FlowCreationCfa.siretPage.fillSiret(siret)
cy.contains(siret).click()
},
fillSiret(siret: string) {
cy.get("input[name='establishment_siret']").click()
cy.get("input[name='establishment_siret']").type(siret)
Expand Down
6 changes: 5 additions & 1 deletion cypress/pages/FlowCreationEntreprise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export const FlowCreationEntreprise = {
cy.get("input[name='establishment_siret']").click()
cy.get("input[name='establishment_siret']").type(siret)
},
searchAndSelectSiret(siret: string) {
FlowCreationEntreprise.siretPage.fillSiret(siret)
cy.contains(siret).click()
},
submit() {
cy.get("button[type='submit']").click({ timeout: 10000 })
},
Expand Down Expand Up @@ -52,7 +56,7 @@ export const FlowCreationEntreprise = {
jobDurationInMonths: number
}) {
const typedRomeLabel = romeLabel.substring(0, romeLabel.length - 10)
cy.intercept(`${Cypress.env("server")}/api/v1/metiers/intitule?label=${encodeURI(typedRomeLabel)}`).as("romeSearch")
cy.intercept(`${Cypress.env("server")}/api/v1/metiers/intitule?label=${encodeURIComponent(typedRomeLabel).replace(/%20/g, "+")}`).as("romeSearch")

cy.get("[data-testid='offre-metier'] input").click()
cy.get("[data-testid='offre-metier'] input").type(typedRomeLabel)
Expand Down
2 changes: 2 additions & 0 deletions shared/models/diplomesMetiers.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export const ZAppellationsRomes = z
})
.strict()

export type IAppellationsRomes = z.output<typeof ZAppellationsRomes>

const collectionName = "diplomesmetiers" as const

export const ZDiplomesMetiers = z
Expand Down
10 changes: 5 additions & 5 deletions ui/common/utils/debounce.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export function debounce(callback, delay) {
let timer
export function debounce<T, R>(callback: (param: T) => Promise<R>, delay: number): (param: T) => Promise<R> {
let timer: NodeJS.Timeout

return (...args) => {
return (args: T) => {
return new Promise((resolve, reject) => {
clearTimeout(timer)
const localTimer = setTimeout(() => {
try {
callback(...args)
callback(args)
.then((output) => localTimer === timer && resolve(output))
.catch((err) => localTimer === timer && reject(err))
} catch (err) {
reject(err)
localTimer === timer && reject(err)
}
}, delay)
timer = localTimer
Expand Down
17 changes: 7 additions & 10 deletions ui/components/espace_pro/AjouterVoeux.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import omit from "lodash/omit"
import { useRouter } from "next/router"
import { useContext, useState } from "react"
import { useQuery } from "react-query"
import { IRecruiterJson, IReferentielRomeForJob } from "shared"
import { IAppellationsRomes, IRecruiterJson, IReferentielRomeForJob } from "shared"
import { TRAINING_CONTRACT_TYPE, TRAINING_RYTHM } from "shared/constants/recruteur"
import { IJobJson, JOB_STATUS } from "shared/models/job.model"
import * as Yup from "yup"
Expand All @@ -33,17 +33,16 @@ import { AUTHTYPE } from "@/common/contants"
import { debounce } from "@/common/utils/debounce"
import { InfosDiffusionOffre } from "@/components/DepotOffre/InfosDiffusionOffre"
import { RomeDetailWithQuery } from "@/components/DepotOffre/RomeDetailWithQuery"
import { publicConfig } from "@/config.public"
import { LogoContext } from "@/context/contextLogo"
import { WidgetContext } from "@/context/contextWidget"
import { useAuth } from "@/context/UserContext"
import { ArrowRightLine, ExternalLinkLine, Minus, Plus, Warning } from "@/theme/components/icons"
import { createOffre, createOffreByToken, getFormulaire, getFormulaireByToken, getRelatedEtablissementsFromRome, getRomeDetail } from "@/utils/api"
import { apiGet } from "@/utils/api.utils"

import DropdownCombobox from "./DropdownCombobox"

const DATE_FORMAT = "YYYY-MM-DD"
const URL_LBA = publicConfig.apiEndpoint

const ChampNombre = ({ value, max, name, handleChange, label, dataTestId }) => {
return (
Expand Down Expand Up @@ -83,13 +82,11 @@ const AjouterVoeuxForm = ({

const minDate = dayjs().format(DATE_FORMAT)

const handleJobSearch = async (search) => {
const handleJobSearch = async (search: string) => {
if (search.trim().length !== 0) {
try {
// KBA 20230214 : update api call.
const result = await fetch(`${URL_LBA}/v1/metiers/intitule?label=${search}`)
const data = await result.json()
return data.coupleAppellationRomeMetier
const result = (await apiGet(`/v1/metiers/intitule`, { querystring: { label: search } })) as IAppellationsRomes
return result.coupleAppellationRomeMetier
} catch (error) {
throw new Error(error)
}
Expand Down Expand Up @@ -138,7 +135,7 @@ const AjouterVoeuxForm = ({
<FormLabel>Métier</FormLabel>
<DropdownCombobox
handleSearch={debounce(handleJobSearch, 300)}
saveSelectedItem={(values) => {
saveSelectedItem={(values: IAppellationsRomes["coupleAppellationRomeMetier"][number]) => {
/**
* validator broken when using setFieldValue : https://github.com/formium/formik/issues/2266
* work around until v3 : setTimeout
Expand All @@ -153,7 +150,7 @@ const AjouterVoeuxForm = ({
name="rome_label"
value={values.rome_appellation_label}
placeholder="Rechercher un métier.."
data-testid="offre-metier"
dataTestId="offre-metier"
/>
</FormControl>
<FormControl mt={6}>
Expand Down
Loading

0 comments on commit c17a9b1

Please sign in to comment.