Skip to content

Commit

Permalink
Préavis – Assure la synchronisation entre un préavis ouvert et sa rep…
Browse files Browse the repository at this point in the history
…résentation dans la liste (#3781)

## Linked issues

- Resolve #3598

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
ivangabriele authored Oct 31, 2024
2 parents b77ef6b + 4ba40b7 commit 00f9f3e
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 100 deletions.

This file was deleted.

10 changes: 5 additions & 5 deletions frontend/config/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {defineConfig} from 'cypress'
import { defineConfig } from 'cypress'
import initCypressMousePositionPlugin from 'cypress-mouse-position/plugin'
import {initPlugin} from 'cypress-plugin-snapshots/plugin'
import { initPlugin } from 'cypress-plugin-snapshots/plugin'

const IS_CI = Boolean(process.env.CI)

Expand All @@ -15,8 +15,6 @@ export default defineConfig({
specPattern: 'cypress/e2e/**/*.spec.ts'
},
env: {
"FRONTEND_OIDC_AUTHORITY": `http://${IS_CI ? '0.0.0.0:8880' : 'localhost:8880'}/realms/monitor`,
"FRONTEND_OIDC_CLIENT_ID": "monitorfish",
'cypress-plugin-snapshots': {
imageConfig: {
threshold: 20,
Expand All @@ -28,7 +26,9 @@ export default defineConfig({
* When running Cypress tests, we modify this env var in spec file, so we use `window.Cypress.env()`
* instead of `import.meta.env` in application code.
*/
FRONTEND_MISSION_FORM_AUTO_SAVE_ENABLED: true
FRONTEND_MISSION_FORM_AUTO_SAVE_ENABLED: true,
FRONTEND_OIDC_AUTHORITY: `http://${IS_CI ? '0.0.0.0:8880' : 'localhost:8880'}/realms/monitor`,
FRONTEND_OIDC_CLIENT_ID: 'monitorfish'
},
projectId: '9b7q8z',
retries: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,51 @@ context('BackOffice > Control Objective Tables > Actions', () => {
cy.get('.rs-table-row').should('have.length', 67)
})

it('Should add the next control objective year', () => {
it('Should handle new year as expected', () => {
const currentYear = new Date().getFullYear()
const nextYear = currentYear + 1

cy.intercept('GET', `/bff/v1/fleet_segments/${currentYear}`).as('fleetSegments')
cy.intercept('GET', `/bff/v1/admin/control_objectives/${currentYear}`).as('controlObjectives')
cy.intercept('POST', '/bff/v1/admin/control_objectives/years').as('addObjectiveYear')

cy.log('Should allow adding a control objective for a year that has not yet been added')

// Given
cy.clock(new Date(nextYear, 3, 14).getTime())

cy.getDataCy('control-objectives-year').contains(currentYear)
cy.get('.rs-table-row').should('have.length', 67)

// When
cy.getDataCy('control-objectives-year').click()

// Then
cy.get('.rs-picker-select-menu-item').should('have.length', 2)
cy.get('*[data-cy="control-objectives-add-year"]').contains(nextYear)

cy.log('Should add the next control objective year')

// Given
cy.clock(new Date().getTime())

cy.get('.rs-table-row').should('have.length', 67)
cy.get('*[data-cy^="control-objectives-year"]').click()

cy.getDataCy('control-objectives-year').click()

cy.get('.rs-picker-select-menu-item').should('have.length', 2)
cy.intercept('POST', '/bff/v1/admin/control_objectives/years').as('addObjectiveYear')

// When
cy.get('*[data-cy="control-objectives-add-year"]').click()

cy.wait('@addObjectiveYear')

// Then
cy.wait(50)
const nextYear = new Date().getFullYear() + 1
cy.get('*[data-cy^="control-objectives-year"]').contains(nextYear)
cy.get('*[data-cy^="control-objectives-year"]').click()
cy.getDataCy('control-objectives-year').contains(nextYear)
cy.getDataCy('control-objectives-year').click()
cy.get('.rs-picker-select-menu-item').should('have.length', 3)
cy.get('.rs-table-row').should('have.length', 67)
cy.get('*[data-cy="control-objectives-add-year"]').should('be.not.visible')
cy.getDataCy('control-objectives-add-year').should('be.not.visible')
})
})

This file was deleted.

6 changes: 0 additions & 6 deletions frontend/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ Cypress.on('uncaught:exception', err => {
return false
}

// We ignore uncaught exceptions `TypeError: NetworkError when attempting to fetch resource`
// if (err.message.includes('NetworkError when attempting to fetch resource') ) {
// console.log(`Error skipped: ${err}`)
// return false // return false to make test continue
// }

// We ignore uncaught exceptions `AbortError: The operation was aborted`
// This error happens after using `reload()` in Cypress
if (err.message.includes('The operation was aborted')) {
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/api/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ import type { StartQueryActionCreatorOptions, SubscriptionOptions } from '@redux

export const RTK_MAX_RETRIES = 1

export const RTK_THIRTY_SECONDS_POLLING_QUERY_OPTIONS: SubscriptionOptions & Partial<RefetchConfigOptions> = {
pollingInterval: THIRTY_SECONDS,
export const RTK_DEFAULT_REFETCH_QUERY_OPTIONS: Partial<RefetchConfigOptions> = {
refetchOnMountOrArgChange: true,
refetchOnReconnect: true
}

export const RTK_THIRTY_SECONDS_POLLING_QUERY_OPTIONS: SubscriptionOptions & Partial<RefetchConfigOptions> = {
...RTK_DEFAULT_REFETCH_QUERY_OPTIONS,
pollingInterval: THIRTY_SECONDS
}

export const RTK_ONE_MINUTE_POLLING_QUERY_OPTIONS: SubscriptionOptions & Partial<RefetchConfigOptions> = {
pollingInterval: ONE_MINUTE,
refetchOnMountOrArgChange: true,
refetchOnReconnect: true
...RTK_DEFAULT_REFETCH_QUERY_OPTIONS,
pollingInterval: ONE_MINUTE
}

export const RTK_FIVE_MINUTES_POLLING_QUERY_OPTIONS: SubscriptionOptions & Partial<RefetchConfigOptions> = {
pollingInterval: FIVE_MINUTES,
refetchOnMountOrArgChange: true,
refetchOnReconnect: true
...RTK_DEFAULT_REFETCH_QUERY_OPTIONS,
pollingInterval: FIVE_MINUTES
}

export const RTK_FORCE_REFETCH_QUERY_OPTIONS: StartQueryActionCreatorOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function LogbookPriorNotificationForm() {
)
},
isBeingSent,
5000
1000
)

const displayedErrorKey = displayedError ? DisplayedErrorKey.SIDE_WINDOW_PRIOR_NOTIFICATION_FORM_ERROR : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function ManualPriorNotificationForm() {
)
},
isBeingSent,
5000
1000
)

const [shouldValidateOnChange, setShouldValidateOnChange] = useState(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RTK_DEFAULT_REFETCH_QUERY_OPTIONS } from '@api/constants'
import { PriorNotification } from '@features/PriorNotification/PriorNotification.types'
import { useGetPriorNotificationSentNessagesQuery } from '@features/PriorNotification/priorNotificationApi'
import { Icon } from '@mtes-mct/monitor-ui'
Expand All @@ -12,7 +13,11 @@ type SentMessageListProps = Readonly<{
state: PriorNotification.State | undefined
}>
export function SentMessageList({ detail, state }: SentMessageListProps) {
const { data: sentMessages, isError, isFetching } = useGetPriorNotificationSentNessagesQuery(detail.reportId)
const {
data: sentMessages,
isError,
isFetching
} = useGetPriorNotificationSentNessagesQuery(detail.reportId, RTK_DEFAULT_REFETCH_QUERY_OPTIONS)

const sentMessagesBatches = sentMessages ? getSentMessagesBatches(sentMessages) : []
const lastSentMessagesBatch = sentMessagesBatches ? sentMessagesBatches[sentMessagesBatches.length - 1] : undefined
Expand Down

0 comments on commit 00f9f3e

Please sign in to comment.