Skip to content

Commit

Permalink
Fix arrival date filtering in prior notification list
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Mar 20, 2024
1 parent d418ea3 commit f59bb04
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ INSERT INTO logbook_raw_messages (operation_number) VALUES ('FAKE_OPERATION_111'
INSERT INTO logbook_raw_messages (operation_number) VALUES ('FAKE_OPERATION_112');

INSERT INTO logbook_reports (id, cfr, enriched, flag_state, integration_datetime_utc, log_type, operation_datetime_utc, operation_number, operation_type, report_datetime_utc, transmission_format, vessel_id, vessel_name, trip_gears, trip_segments, value) VALUES (101, 'FAK000999999', true, 'FRA', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'PNO', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'FAKE_OPERATION_101', 'DAT', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'ERS', 1, 'PHENOMENE', '[{"gear":"TBN","mesh":100,"dimensions":"250;180"},{"gear":"OTT","mesh":120.5,"dimensions":"250;280"}]', '[{"segment":"SWW04","segment_name":"Chaluts pélagiques"},{"segment":"SWW06","segment_name":"Sennes"}]', '{"catchOnboard":[{"weight":25,"nbFish":null,"species":"COD","faoZone":"27.8.a","effortZone":"C","economicZone":"FRA","statisticalRectangle":"23E6"}],"pnoTypes":[{"pnoTypeName":"Préavis type A","minimumNotificationPeriod":4,"hasDesignatedPorts":false},{"pnoTypeName":"Préavis type B","minimumNotificationPeriod":8,"hasDesignatedPorts":true}],"port":"FRSML","predictedArrivalDatetimeUtc":null,"predictedLandingDatetimeUtc":null,"purpose":"LAN","tripStartDate":null}');
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '4 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 101;
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 101;
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '1 hour', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 101;
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '2 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 101;
UPDATE logbook_reports SET value = JSONB_SET(value, '{tripStartDate}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '10 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 101;

INSERT INTO logbook_reports (id, cfr, enriched, flag_state, integration_datetime_utc, log_type, operation_datetime_utc, operation_number, operation_type, report_datetime_utc, transmission_format, vessel_id, vessel_name, trip_gears, trip_segments, value) VALUES (102, 'ABC000042310', true, 'FRA', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'PNO', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'FAKE_OPERATION_102', 'DAT', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'ERS', 10, 'COURANT MAIN PROFESSEUR', '[{"gear":"PT","mesh":100,"dimensions":"250;180"},{"gear":"OT","mesh":120.5,"dimensions":"250;280"}]', '[{"segment":"SWW10","segment_name":"Palangres ciblant les espèces démersales"},{"segment":"SWW11","segment_name":"Hameçons"}]', '{"catchOnboard":[{"weight":25,"nbFish":null,"species":"SOL","faoZone":"27.8.a","effortZone":"C","economicZone":"FRA","statisticalRectangle":"23E6"},{"weight":25,"nbFish":null,"species":"HKE","faoZone":"27.8.a","effortZone":"C","economicZone":"FRA","statisticalRectangle":"23E6"}],"pnoTypes":[{"pnoTypeName":"Préavis type C","minimumNotificationPeriod":4,"hasDesignatedPorts":false}],"port":"FRBES","predictedArrivalDatetimeUtc":null,"predictedLandingDatetimeUtc":null,"purpose":"LAN","tripStartDate":null}');
Expand All @@ -39,6 +39,6 @@ INSERT INTO logbook_reports (id, enriched, flag_state, integration_datetime_utc,
UPDATE logbook_reports SET value = JSONB_SET(value, '{tripStartDate}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '10 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 103;

INSERT INTO logbook_reports (id, cfr, enriched, flag_state, integration_datetime_utc, log_type, operation_datetime_utc, operation_number, operation_type, report_datetime_utc, transmission_format, vessel_id, vessel_name, trip_gears, trip_segments, value) VALUES (104, 'CFR101', true, 'ESP', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'PNO', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'FAKE_OPERATION_104', 'DAT', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'ERS', 101, 'VIVA ESPANA', '[{"gear":"TB","mesh":100,"dimensions":"250;180"},{"gear":"TBS","mesh":120.5,"dimensions":"250;280"}]', '[{"segment":"NWW03","segment_name":"Chalut de fond en eau profonde"},{"segment":"NWW05","segment_name":"Chalut à perche"}]', '{"catchOnboard":[{"weight":25,"nbFish":null,"species":"FRF","faoZone":"27.8.a","effortZone":"C","economicZone":"FRA","statisticalRectangle":"23E6"}],"pnoTypes":[{"pnoTypeName":"Préavis type A","minimumNotificationPeriod":4,"hasDesignatedPorts":false},{"pnoTypeName":"Préavis type B","minimumNotificationPeriod":8,"hasDesignatedPorts":true}],"port":"FRVNE","predictedArrivalDatetimeUtc":null,"predictedLandingDatetimeUtc":null,"purpose":"LAN","tripStartDate":null}');
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '4 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 104;
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 104;
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 104;
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '4 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 104;
UPDATE logbook_reports SET value = JSONB_SET(value, '{tripStartDate}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '10 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 104;
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
}
],
"port": "FRSML",
"predictedArrivalDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '4 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"predictedLandingDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"predictedArrivalDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '1 hour', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"predictedLandingDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '2 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"purpose": "LAN",
"tripStartDate:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '10 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')"
}
Expand Down Expand Up @@ -208,8 +208,8 @@
}
],
"port": "FRVNE",
"predictedArrivalDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '4 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"predictedLandingDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"predictedArrivalDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"predictedLandingDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '4 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"purpose": "LAN",
"tripStartDate:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '10 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { assertNotNullish } from '@utils/assertNotNullish'
import { SideWindowMenuLabel } from 'domain/entities/sideWindow/constants'

import { openSideWindowPriorNotificationList } from './utils'
import { assertAll } from '../../utils/assertAll'
import { customDayjs } from '../../utils/customDayjs'
import { getUtcDateInMultipleFormats } from '../../utils/getUtcDateInMultipleFormats'

import type { PriorNotification } from '@features/PriorNotification/PriorNotification.types'

context('Side Window > Prior Notification List > Filter Bar', () => {
const basePath = '/bff/v1/prior-notifications?'
const apiPathBase = '/bff/v1/prior-notifications?'

beforeEach(() => {
it('Should filter prior notifications by countries', () => {
openSideWindowPriorNotificationList()
})

it('Should filter prior notifications by countries', () => {
cy.intercept('GET', `${basePath}*flagStates=FRA&flagStates=ESP*`).as('getPriorNotifications')
cy.intercept('GET', `${apiPathBase}*flagStates=FRA&flagStates=ESP*`).as('getPriorNotifications')

cy.fill('Nationalité', ['Espagne', 'France'])

Expand All @@ -19,7 +24,11 @@ context('Side Window > Prior Notification List > Filter Bar', () => {
})

it('Should filter prior notifications by fleet segments', () => {
cy.intercept('GET', `${basePath}*tripSegmentSegments=NWW03&tripSegmentSegments=SWW06*`).as('getPriorNotifications')
openSideWindowPriorNotificationList()

cy.intercept('GET', `${apiPathBase}*tripSegmentSegments=NWW03&tripSegmentSegments=SWW06*`).as(
'getPriorNotifications'
)

cy.fill('Segments de flotte', ['NWW03', 'SWW06'])

Expand All @@ -29,7 +38,9 @@ context('Side Window > Prior Notification List > Filter Bar', () => {
})

it('Should filter prior notifications by species', () => {
cy.intercept('GET', `${basePath}*specyCodes=FRF&specyCodes=HKE*`).as('getPriorNotifications')
openSideWindowPriorNotificationList()

cy.intercept('GET', `${apiPathBase}*specyCodes=FRF&specyCodes=HKE*`).as('getPriorNotifications')

cy.fill('Espèces à bord', ['FRF', 'HKE'])

Expand All @@ -39,7 +50,9 @@ context('Side Window > Prior Notification List > Filter Bar', () => {
})

it('Should filter prior notifications by gears', () => {
cy.intercept('GET', `${basePath}*tripGearCodes=OTT&tripGearCodes=TBS*`).as('getPriorNotifications')
openSideWindowPriorNotificationList()

cy.intercept('GET', `${apiPathBase}*tripGearCodes=OTT&tripGearCodes=TBS*`).as('getPriorNotifications')

cy.get('#gearCodes').click()
cy.get('[role="searchbox"]').type('OTT')
Expand All @@ -57,17 +70,19 @@ context('Side Window > Prior Notification List > Filter Bar', () => {
})

it('Should filter prior notifications by last control date', () => {
const expectedPartialBeforeDate = customDayjs().subtract(3, 'months').toISOString().substring(0, 10)
cy.intercept('GET', `${basePath}*lastControlledBefore=${expectedPartialBeforeDate}*`).as('getPriorNotifications')
openSideWindowPriorNotificationList()

const expectedPartialBeforeDate = customDayjs.utc().subtract(3, 'months').toISOString().substring(0, 10)
cy.intercept('GET', `${apiPathBase}*lastControlledBefore=${expectedPartialBeforeDate}*`).as('getPriorNotifications')

cy.fill('Date du dernier contrôle', 'Contrôlé il y a plus de 3 mois')

cy.wait('@getPriorNotifications')

cy.get('.Table-SimpleTable tr').should('have.length.to.be.greaterThan', 0)

const expectedPartialAfterDate = customDayjs().subtract(1, 'month').toISOString().substring(0, 10)
cy.intercept('GET', `${basePath}*lastControlledAfter=${expectedPartialAfterDate}*`).as('getPriorNotifications')
const expectedPartialAfterDate = customDayjs.utc().subtract(1, 'month').toISOString().substring(0, 10)
cy.intercept('GET', `${apiPathBase}*lastControlledAfter=${expectedPartialAfterDate}*`).as('getPriorNotifications')

cy.fill('Date du dernier contrôle', 'Contrôlé il y a moins d’1 mois')

Expand All @@ -76,32 +91,95 @@ context('Side Window > Prior Notification List > Filter Bar', () => {
cy.get('.Table-SimpleTable tr').should('have.length.to.be.greaterThan', 0)
})

// it('Should filter prior notifications by arrival date', () => {
// const expectedPartialDefaultAfterDate = customDayjs().add(3, 'months').toISOString().substring(0, 10)
// cy.intercept('GET', `${basePath}*willArriveAfter=${expectedPartialDefaultAfterDate}*`).as('getPriorNotifications')
it('Should filter prior notifications by arrival date (default)', () => {
const expectedAfterDate = customDayjs.utc()
const expectedBeforeDate = customDayjs.utc().add(4, 'hours').toISOString()

cy.viewport(1920, 1080)
cy.visit('/side_window')
cy.wait(500)
if (document.querySelector('[data-cy="first-loader"]')) {
cy.getDataCy('first-loader').should('not.be.visible')
}

cy.intercept('GET', `${apiPathBase}*`).as('getPriorNotifications')
cy.clickButton(SideWindowMenuLabel.PRIOR_NOTIFICATION_LIST)

cy.wait('@getPriorNotifications').then(interception => {
const priorNotifications: PriorNotification.PriorNotification[] = interception.response?.body

assertNotNullish(priorNotifications)
assert.isNotEmpty(priorNotifications)

assertAll(
priorNotifications,
priorNotification =>
customDayjs(priorNotification.expectedArrivalDate).isSameOrAfter(expectedAfterDate) &&
customDayjs(priorNotification.expectedArrivalDate).isSameOrBefore(expectedBeforeDate)
)
})
})

// cy.wait('@getPriorNotifications')
it('Should filter prior notifications by arrival date', () => {
openSideWindowPriorNotificationList()

// cy.intercept('GET', `${basePath}*willArriveAfter=${expectedPartialBeforeDate}*`).as('getPriorNotifications')
cy.intercept('GET', `${apiPathBase}*`).as('getPriorNotifications')

// cy.fill('Date d’arrivée estimée', 'Arrivée estimée dans moins de 24h')
const expectedAfterDate = customDayjs.utc()
const expectedBeforeDate = customDayjs.utc().add(2, 'hours').toISOString()

// cy.wait('@getPriorNotifications')
cy.fill('Date d’arrivée estimée', 'Arrivée estimée dans moins de 2h')

// cy.get('.Table-SimpleTable tr').should('have.length.to.be.greaterThan', 0)
cy.wait('@getPriorNotifications').then(interception => {
const priorNotifications: PriorNotification.PriorNotification[] = interception.response?.body

// const expectedPartialAfterDate = customDayjs().subtract(1, 'month').toISOString().substring(0, 10)
// cy.intercept('GET', `${basePath}*lastControlledAfter=${expectedPartialAfterDate}*`).as('getPriorNotifications')
assertNotNullish(priorNotifications)
assert.isNotEmpty(priorNotifications)

// cy.fill('Date d’arrivée estimée', 'Contrôlé il y a moins d’1 mois')
assertAll(
priorNotifications,
priorNotification =>
customDayjs(priorNotification.expectedArrivalDate).isSameOrAfter(expectedAfterDate) &&
customDayjs(priorNotification.expectedArrivalDate).isSameOrBefore(expectedBeforeDate)
)
})
})

it('Should filter prior notifications by arrival date (custom)', () => {
openSideWindowPriorNotificationList()

cy.intercept('GET', `${apiPathBase}*`).as('getPriorNotifications')

cy.fill('Date d’arrivée estimée', 'Période spécifique')
cy.wait('@getPriorNotifications')

const startDate = getUtcDateInMultipleFormats('2023-01-01T00:00:00Z')
const endDate = getUtcDateInMultipleFormats('2023-12-31T23:59:59Z')

cy.fill('Arrivée estimée du navire entre deux dates', [
startDate.utcDateTupleWithTime,
endDate.utcDateTupleWithTime
])

// cy.wait('@getPriorNotifications')
cy.wait('@getPriorNotifications').then(interception => {
const priorNotifications: PriorNotification.PriorNotification[] = interception.response?.body

// cy.get('.Table-SimpleTable tr').should('have.length.to.be.greaterThan', 0)
// })
assertNotNullish(priorNotifications)
assert.isNotEmpty(priorNotifications)

assertAll(
priorNotifications,
priorNotification =>
customDayjs(priorNotification.expectedArrivalDate).isSameOrAfter(startDate.utcDateAsDayjs) &&
customDayjs(priorNotification.expectedArrivalDate).isSameOrBefore(endDate.utcDateAsDayjs)
)
})
})

it('Should filter prior notifications by ports', () => {
cy.intercept('GET', `${basePath}*&tripSegmentSegments=NWW03*`).as('getPriorNotifications')
openSideWindowPriorNotificationList()

cy.intercept('GET', `${apiPathBase}*&tripSegmentSegments=NWW03*`).as('getPriorNotifications')

cy.get('#portLocodes').click()
cy.get('[role="searchbox"]').type('Saint-Malo')
Expand All @@ -117,9 +195,12 @@ context('Side Window > Prior Notification List > Filter Bar', () => {
})

it('Should filter prior notifications by type', () => {
cy.intercept('GET', `${basePath}*priorNotificationTypes=Préavis type A&priorNotificationTypes=Préavis type C*`).as(
'getPriorNotifications'
)
openSideWindowPriorNotificationList()

cy.intercept(
'GET',
`${apiPathBase}*priorNotificationTypes=Préavis type A&priorNotificationTypes=Préavis type C*`
).as('getPriorNotifications')

cy.fill('Types de préavis', ['Préavis type A', 'Préavis type C'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ import { SideWindowMenuLabel } from '../../../../src/domain/entities/sideWindow/

export const openSideWindowPriorNotificationList = () => {
cy.viewport(1920, 1080)

cy.visit('/side_window')

cy.wait(500)

if (document.querySelector('[data-cy="first-loader"]')) {
cy.getDataCy('first-loader').should('not.be.visible')
}

cy.clickButton(SideWindowMenuLabel.PRIOR_NOTIFICATION_LIST)
if (document.querySelector('[data-cy="first-loader"]')) {
cy.getDataCy('first-loader').should('not.be.visible')
}

cy.wait(500)
}
5 changes: 5 additions & 0 deletions frontend/cypress/e2e/utils/assertAll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function assertAll<T = any>(items: T[], assert: (item: T) => boolean) {
const result = items.filter(assert)

expect(result).to.have.lengthOf(items.length)
}
6 changes: 3 additions & 3 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f59bb04

Please sign in to comment.