Skip to content

Commit

Permalink
Fix bluefin tuna extra field & weight calculation in manual pno form
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Oct 8, 2024
1 parent 5c88c3c commit 1b5002c
Show file tree
Hide file tree
Showing 12 changed files with 937 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,43 @@ context('Side Window > Manual Prior Notification Form > Behavior', () => {

cy.get('[id="fishingCatches[0].weight"]').should('have.value', '90')
})

// Non-regression test
// https://github.com/MTES-MCT/monitorfish/issues/3683
it('Should create a manual prior notification Zero, remove a specy and calculate BFT total weight', () => {
const { utcDateTupleWithTime: arrivalDateTupleWithTime } = getUtcDateInMultipleFormats(
customDayjs().add(2, 'hours').startOf('minute').toISOString()
)

cy.intercept('POST', '/bff/v1/prior_notifications/manual').as('createPriorNotification')

addManualSideWindowPriorNotification()

cy.getDataCy('vessel-search-input').click().wait(500)
cy.getDataCy('vessel-search-input').type('PHENO', { delay: 100 })
cy.getDataCy('vessel-search-item').first().click()

cy.fill("Date et heure estimées d'arrivée au port (UTC)", arrivalDateTupleWithTime)
cy.fill("équivalentes à celles de l'arrivée au port", true)
cy.fill("Port d'arrivée", 'Vannes')
cy.fill('Zone globale de capture', '21.4.T')

cy.fill('Espèces à bord et à débarquer', 'BFT')
cy.fill('Espèces à bord et à débarquer', 'SWO')

cy.fill('Engins utilisés', ['OTP'], { index: 1 })
cy.fill('Saisi par', 'BOB')

cy.clickButton('Créer le préavis')

cy.wait('@createPriorNotification')

cy.contains('.Element-SingleTag', 'BFT – THON ROUGE').find('button').click()

cy.contains('BFT – THON ROUGE').should('not.exist')

cy.fill('Poids (SWO)', 10)

cy.get('[id="fishingCatches[0].weight"]').should('have.value', '10')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
import { describe, expect, it } from '@jest/globals'

import { getFormDataFishingCatchesFromFormValuesFishingCatches } from '../utils'

import type { ManualPriorNotificationFormValuesFishingCatch } from '../components/ManualPriorNotificationForm/types'

describe('getFormDataFishingCatchesFromFormValuesFishingCatches', () => {
it('Should return empty array when input is empty', () => {
const formValuesFishingCatches: ManualPriorNotificationFormValuesFishingCatch[] = []

const result = getFormDataFishingCatchesFromFormValuesFishingCatches(formValuesFishingCatches)

expect(result).toHaveLength(0)
})

it('Should handle non-bluefin tuna species correctly', () => {
const formValuesFishingCatches: ManualPriorNotificationFormValuesFishingCatch[] = [
{ faoArea: 'FA1', quantity: 10, specyCode: 'COD', specyName: 'Cod', weight: 100 },
{ faoArea: 'FA1', quantity: 5, specyCode: 'HAD', specyName: 'Haddock', weight: 50 }
]

const result = getFormDataFishingCatchesFromFormValuesFishingCatches(formValuesFishingCatches)

expect(result).toEqual([
{ faoArea: 'FA1', quantity: 10, specyCode: 'COD', specyName: 'Cod', weight: 100 },
{ faoArea: 'FA1', quantity: 5, specyCode: 'HAD', specyName: 'Haddock', weight: 50 }
])
})

it('Should handle bluefin tuna species without extended codes', () => {
const formValuesFishingCatches: ManualPriorNotificationFormValuesFishingCatch[] = [
{ faoArea: 'FA1', quantity: 20, specyCode: 'BFT', specyName: "Thon rouge de l'Atlantique", weight: 200 }
]

const result = getFormDataFishingCatchesFromFormValuesFishingCatches(formValuesFishingCatches)

expect(result).toEqual([
{ faoArea: 'FA1', quantity: 20, specyCode: 'BFT', specyName: "Thon rouge de l'Atlantique", weight: 200 }
])
})

it('Should expand bluefin tuna extended catches', () => {
const formValuesFishingCatches: ManualPriorNotificationFormValuesFishingCatch[] = [
{
$bluefinTunaExtendedCatch: {
BF1: { quantity: 5, specyName: "Thon rouge de l'Atlantique (Calibre 1)", weight: 50 },
BF2: { quantity: 3, specyName: "Thon rouge de l'Atlantique (Calibre 2)", weight: 30 }
} as any,
faoArea: 'FA1',
quantity: 20,
specyCode: 'BFT',
specyName: "Thon rouge de l'Atlantique",
weight: 200
}
]

const result = getFormDataFishingCatchesFromFormValuesFishingCatches(formValuesFishingCatches)

expect(result).toEqual([
{ faoArea: 'FA1', quantity: 20, specyCode: 'BFT', specyName: "Thon rouge de l'Atlantique", weight: 200 },
{
faoArea: 'FA1',
quantity: 5,
specyCode: 'BF1',
specyName: "Thon rouge de l'Atlantique (Calibre 1)",
weight: 50
},
{ faoArea: 'FA1', quantity: 3, specyCode: 'BF2', specyName: "Thon rouge de l'Atlantique (Calibre 2)", weight: 30 }
])
})

it('Should handle multiple FAO areas correctly', () => {
const formValuesFishingCatches: ManualPriorNotificationFormValuesFishingCatch[] = [
{
$bluefinTunaExtendedCatch: {
BF1: { quantity: 2, specyName: "Thon rouge de l'Atlantique (Calibre 1)", weight: 20 }
} as any,
faoArea: 'FA1',
quantity: 10,
specyCode: 'BFT',
specyName: "Thon rouge de l'Atlantique",
weight: 100
},
{
$bluefinTunaExtendedCatch: {
BF3: { quantity: 4, specyName: "Thon rouge de l'Atlantique (Calibre 3)", weight: 40 }
},
faoArea: 'FA2',
quantity: 15,
specyCode: 'BFT',
specyName: "Thon rouge de l'Atlantique",
weight: 150
},
{ faoArea: 'FA2', quantity: 5, specyCode: 'COD', specyName: 'Cod', weight: 50 }
]

const result = getFormDataFishingCatchesFromFormValuesFishingCatches(formValuesFishingCatches)

expect(result).toEqual([
{ faoArea: 'FA1', quantity: 10, specyCode: 'BFT', specyName: "Thon rouge de l'Atlantique", weight: 100 },
{
faoArea: 'FA1',
quantity: 2,
specyCode: 'BF1',
specyName: "Thon rouge de l'Atlantique (Calibre 1)",
weight: 20
},
{ faoArea: 'FA2', quantity: 15, specyCode: 'BFT', specyName: "Thon rouge de l'Atlantique", weight: 150 },
{
faoArea: 'FA2',
quantity: 4,
specyCode: 'BF3',
specyName: "Thon rouge de l'Atlantique (Calibre 3)",
weight: 40
},
{ faoArea: 'FA2', quantity: 5, specyCode: 'COD', specyName: 'Cod', weight: 50 }
])
})

it('Should handle undefined faoArea correctly', () => {
const formValuesFishingCatches: ManualPriorNotificationFormValuesFishingCatch[] = [
{
$bluefinTunaExtendedCatch: {
BF2: { quantity: 2, specyName: "Thon rouge de l'Atlantique (Calibre 2)", weight: 20 }
} as any,
quantity: 10,
specyCode: 'BFT',
specyName: "Thon rouge de l'Atlantique",
weight: 100
},
{ quantity: 5, specyCode: 'SAL', specyName: 'Salmon', weight: 50 }
]

const result = getFormDataFishingCatchesFromFormValuesFishingCatches(formValuesFishingCatches)

expect(result).toEqual([
{ quantity: 10, specyCode: 'BFT', specyName: "Thon rouge de l'Atlantique", weight: 100 },
{ quantity: 2, specyCode: 'BF2', specyName: "Thon rouge de l'Atlantique (Calibre 2)", weight: 20 },
{ quantity: 5, specyCode: 'SAL', specyName: 'Salmon', weight: 50 }
])
})

it('Should not lose data when $bluefinTunaExtendedCatch is undefined', () => {
const formValuesFishingCatches: ManualPriorNotificationFormValuesFishingCatch[] = [
{
faoArea: 'FA1',
quantity: undefined,
specyCode: 'BFT',
specyName: "Thon rouge de l'Atlantique",
weight: 0
}
]

const result = getFormDataFishingCatchesFromFormValuesFishingCatches(formValuesFishingCatches)

expect(result).toEqual([
{ faoArea: 'FA1', quantity: undefined, specyCode: 'BFT', specyName: "Thon rouge de l'Atlantique", weight: 0 }
])
})

it('Should handle bluefin tuna catches without a BFT entry', () => {
const formValuesFishingCatches: ManualPriorNotificationFormValuesFishingCatch[] = [
{
$bluefinTunaExtendedCatch: {
BF1: { quantity: 2, specyName: "Thon rouge de l'Atlantique (Calibre 1)", weight: 20 }
} as any,
faoArea: 'FA1',
quantity: undefined,
specyCode: 'BFT',
specyName: "Thon rouge de l'Atlantique",
weight: 0
}
]

const result = getFormDataFishingCatchesFromFormValuesFishingCatches(formValuesFishingCatches)

expect(result).toEqual([
{ faoArea: 'FA1', quantity: undefined, specyCode: 'BFT', specyName: "Thon rouge de l'Atlantique", weight: 0 },
{ faoArea: 'FA1', quantity: 2, specyCode: 'BF1', specyName: "Thon rouge de l'Atlantique (Calibre 1)", weight: 20 }
])
})

it('Should handle multiple bluefin tuna catches with the same faoArea', () => {
const formValuesFishingCatches: ManualPriorNotificationFormValuesFishingCatch[] = [
{
$bluefinTunaExtendedCatch: {
BF1: { quantity: 2, specyName: "Thon rouge de l'Atlantique (Calibre 1)", weight: 20 }
} as any,
faoArea: 'FA1',
quantity: 3,
specyCode: 'BFT',
specyName: "Thon rouge de l'Atlantique",
weight: 30
}
]

const result = getFormDataFishingCatchesFromFormValuesFishingCatches(formValuesFishingCatches)

expect(result).toEqual([
{ faoArea: 'FA1', quantity: 3, specyCode: 'BFT', specyName: "Thon rouge de l'Atlantique", weight: 30 },
{ faoArea: 'FA1', quantity: 2, specyCode: 'BF1', specyName: "Thon rouge de l'Atlantique (Calibre 1)", weight: 20 }
])
})

it('Should include all necessary fields in the output', () => {
const formValuesFishingCatches: ManualPriorNotificationFormValuesFishingCatch[] = [
{ quantity: 10, specyCode: 'COD', specyName: 'Cod', weight: 100 }
]

const result = getFormDataFishingCatchesFromFormValuesFishingCatches(formValuesFishingCatches)

expect(result).toEqual([{ quantity: 10, specyCode: 'COD', specyName: 'Cod', weight: 100 }])
})
})
Loading

0 comments on commit 1b5002c

Please sign in to comment.