diff --git a/ui/main/src/app/business/view/userCard/publisherForm/publisherForm.spec.ts b/ui/main/src/app/business/view/userCard/publisherForm/publisherForm.spec.ts index 32fb558eef..09b421c9de 100644 --- a/ui/main/src/app/business/view/userCard/publisherForm/publisherForm.spec.ts +++ b/ui/main/src/app/business/view/userCard/publisherForm/publisherForm.spec.ts @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, RTE (http://www.rte-france.com) +/* Copyright (c) 2024-2025, RTE (http://www.rte-france.com) * See AUTHORS.txt * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -80,17 +80,17 @@ describe('UserCard PublisherForm', () => { }); it('Should hide publisher multiselect if user has only one entity that can send the card', async () => { await setUserWithEntities(['ENTITY1']); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(userCardUIControl.inputVisibility_FctCalls[InputFieldName.Publisher]).toBe(false); }); it('Should show publisher multiselect if user has more than one entity that can send the card', async () => { await setUserWithEntities(['ENTITY1', 'ENTITY2']); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(userCardUIControl.inputVisibility_FctCalls[InputFieldName.Publisher]).toBe(true); }); it('Should set a list of 2 publishers to the userCardUIControl if user has 2 entities to send card', async () => { await setUserWithEntities(['ENTITY1', 'ENTITY2']); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(userCardUIControl.publishers).toEqual([ {id: 'ENTITY1', label: 'ENTITY1_NAME'}, {id: 'ENTITY2', label: 'ENTITY2_NAME'} @@ -98,7 +98,7 @@ describe('UserCard PublisherForm', () => { }); it('Should set a list of 2 publishers to the userCardUIControl if user has 2 entities to send card and one entity with no roles', async () => { await setUserWithEntities(['ENTITY1', 'ENTITY2', 'NO_ROLES_ENTITY']); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(userCardUIControl.publishers).toEqual([ {id: 'ENTITY1', label: 'ENTITY1_NAME'}, {id: 'ENTITY2', label: 'ENTITY2_NAME'} @@ -106,7 +106,7 @@ describe('UserCard PublisherForm', () => { }); it('Should set a list of 2 publishers by alphabetical order', async () => { await setUserWithEntities(['ENTITY2', 'ENTITY1']); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(userCardUIControl.publishers).toEqual([ {id: 'ENTITY1', label: 'ENTITY1_NAME'}, {id: 'ENTITY2', label: 'ENTITY2_NAME'} @@ -114,7 +114,7 @@ describe('UserCard PublisherForm', () => { }); it('Should set entity label as entity id if entity has no name', async () => { await setUserWithEntities(['ENTITY1', 'ENTITY_WITH_NO_NAME']); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(userCardUIControl.publishers).toEqual([ {id: 'ENTITY_WITH_NO_NAME', label: 'ENTITY_WITH_NO_NAME'}, {id: 'ENTITY1', label: 'ENTITY1_NAME'} @@ -122,13 +122,13 @@ describe('UserCard PublisherForm', () => { }); it('Should set the first entity as selected in the publisher multiselect', async () => { await setUserWithEntities(['ENTITY1', 'ENTITY2']); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(userCardUIControl.selectedPublisher).toBe('ENTITY1'); expect(publisherForm.getSelectedPublisher()).toEqual('ENTITY1'); }); it('Should set the first entity by alphabetical order as selected in the publisher multiselect', async () => { await setUserWithEntities(['ENTITY2', 'ENTITY1']); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(userCardUIControl.selectedPublisher).toBe('ENTITY1'); expect(publisherForm.getSelectedPublisher()).toEqual('ENTITY1'); }); @@ -138,12 +138,12 @@ describe('UserCard PublisherForm', () => { opfab.currentUserCard.listenToEntityUsedForSendingCard((entity) => { entitySelectedReceiveByTemplate = entity; }); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(entitySelectedReceiveByTemplate).toEqual('ENTITY1'); }); it('Should set the selected publisher as the entity allowed to send card if only one entity is possible', async () => { await setUserWithEntities(['ENTITY1']); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(publisherForm.getSelectedPublisher()).toEqual('ENTITY1'); }); it('Should set the selected publisher as the entity allowed to send card to template via opfabAPI if only one entity is possible', async () => { @@ -152,12 +152,12 @@ describe('UserCard PublisherForm', () => { opfab.currentUserCard.listenToEntityUsedForSendingCard((entity) => { entitySelectedReceiveByTemplate = entity; }); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(entitySelectedReceiveByTemplate).toEqual('ENTITY1'); }); it('Should not add entity3 in the list of publishers as entity3 has no role CARD_SENDER', async () => { await setUserWithEntities(['ENTITY1', 'ENTITY2', 'ENTITY3']); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(userCardUIControl.publishers).toEqual([ {id: 'ENTITY1', label: 'ENTITY1_NAME'}, {id: 'ENTITY2', label: 'ENTITY2_NAME'} @@ -170,7 +170,7 @@ describe('UserCard PublisherForm', () => { await setProcessConfigWithUserCardConfig({ publisherList: [new EntitiesTree('ENTITY2'), new EntitiesTree('ENTITY4')] }); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(userCardUIControl.publishers).toEqual([ {id: 'ENTITY2', label: 'ENTITY2_NAME'}, {id: 'ENTITY4', label: 'ENTITY4_NAME'} @@ -181,7 +181,7 @@ describe('UserCard PublisherForm', () => { await setProcessConfigWithUserCardConfig({ publisherList: [new EntitiesTree('PARENT_ENTITY', [1])] }); - publisherForm.setProcessAndState('testProcessId', 'testStateId'); + publisherForm.init('testProcessId', 'testStateId'); expect(userCardUIControl.publishers).toEqual([ {id: 'ENTITY1', label: 'ENTITY1_NAME'}, {id: 'ENTITY2', label: 'ENTITY2_NAME'} @@ -193,7 +193,7 @@ describe('UserCard PublisherForm', () => { await setUserWithEntities(['ENTITY1', 'ENTITY2', 'ENTITY4']); await setProcessConfigWithUserCardConfig({}); const card = getOneCard({publisher: 'ENTITY4'}); - publisherForm.setProcessAndState('testProcessId', 'testStateId', card, EditionMode.EDITION); + publisherForm.init('testProcessId', 'testStateId', card, EditionMode.EDITION); expect(publisherForm.getSelectedPublisher()).toEqual('ENTITY4'); }); it('Should not select publisher of existing card in edit mode if user is not member of the publishing entity', async () => { @@ -202,14 +202,14 @@ describe('UserCard PublisherForm', () => { const card = getOneCard({ publisher: 'ENTITY3' }); - publisherForm.setProcessAndState('testProcessId', 'testStateId', card, EditionMode.EDITION); + publisherForm.init('testProcessId', 'testStateId', card, EditionMode.EDITION); expect(publisherForm.getSelectedPublisher()).toEqual('ENTITY1'); }); it('Should not select publisher of existing card in copy mode if user is member of the publishing entity', async () => { await setUserWithEntities(['ENTITY1', 'ENTITY2', 'ENTITY4']); await setProcessConfigWithUserCardConfig({}); const card = getOneCard({publisher: 'ENTITY4'}); - publisherForm.setProcessAndState('testProcessId', 'testStateId', card, EditionMode.COPY); + publisherForm.init('testProcessId', 'testStateId', card, EditionMode.COPY); expect(publisherForm.getSelectedPublisher()).toEqual('ENTITY1'); }); }); diff --git a/ui/main/src/app/business/view/userCard/publisherForm/publisherForm.ts b/ui/main/src/app/business/view/userCard/publisherForm/publisherForm.ts index eddf813d29..e5e1a00c94 100644 --- a/ui/main/src/app/business/view/userCard/publisherForm/publisherForm.ts +++ b/ui/main/src/app/business/view/userCard/publisherForm/publisherForm.ts @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, RTE (http://www.rte-france.com) +/* Copyright (c) 2024-2025, RTE (http://www.rte-france.com) * See AUTHORS.txt * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -21,7 +21,7 @@ export class PublisherForm { constructor(private readonly userCardUIControl: UserCardUIControl) {} - public setProcessAndState(processId: string, stateId: string, card?: Card, editionMode?: EditionMode) { + public init(processId: string, stateId: string, card?: Card, editionMode?: EditionMode) { this.editionMode = editionMode; let entitiesAllowedToSendCard = this.getUserEntitiesWithCardSenderRole(); entitiesAllowedToSendCard = this.filterEntitiesAllowedToCreateCardForState( diff --git a/ui/main/src/app/business/view/userCard/severityForm/severityForm.spec.ts b/ui/main/src/app/business/view/userCard/severityForm/severityForm.spec.ts index 0dc397abd8..f52e0b960f 100644 --- a/ui/main/src/app/business/view/userCard/severityForm/severityForm.spec.ts +++ b/ui/main/src/app/business/view/userCard/severityForm/severityForm.spec.ts @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, RTE (http://www.rte-france.com) +/* Copyright (c) 2024-2025, RTE (http://www.rte-france.com) * See AUTHORS.txt * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -37,44 +37,44 @@ describe('UserCard SeverityForm', () => { it(`Severity visibility should be set to true if severity visibility set visible in state configuration`, async () => { await setProcessConfigWithUserCardConfig({severityVisible: true}); - userCardSeverity.setProcessAndState('process1', 'state1_1'); + userCardSeverity.init('process1', 'state1_1'); expect(userCardSeverity.isSeverityVisible()).toEqual(true); expect(userCardUIControl.inputVisibility_FctCalls['severity']).toEqual(true); }); it(`Severity visibility should be set to false if severity visibility set invisible in state configuration`, async () => { await setProcessConfigWithUserCardConfig({severityVisible: false}); - userCardSeverity.setProcessAndState('process1', 'state1_1'); + userCardSeverity.init('process1', 'state1_1'); expect(userCardSeverity.isSeverityVisible()).toEqual(false); expect(userCardUIControl.inputVisibility_FctCalls['severity']).toEqual(false); }); it(`Severity visibility should be set to true if severity visibility is not defined in state configuration`, async () => { await setProcessConfigWithUserCardConfig({}); - userCardSeverity.setProcessAndState('process1', 'state1_1'); + userCardSeverity.init('process1', 'state1_1'); expect(userCardUIControl.inputVisibility_FctCalls['severity']).toEqual(true); }); it('Severity should be set to ALARM by default', async () => { await setProcessConfigWithUserCardConfig({}); - userCardSeverity.setProcessAndState('process1', 'state1_1'); + userCardSeverity.init('process1', 'state1_1'); expect(userCardUIControl.severity).toEqual(Severity.ALARM); expect(userCardSeverity.getSelectedSeverity()).toEqual(Severity.ALARM); }); it('Severity should be set to Card severity if edition or copy mode', async () => { await setProcessConfigWithUserCardConfig({}); const card = getOneCard({severity: 'INFORMATION'}); - userCardSeverity.setProcessAndState('process1', 'state1_1', card); + userCardSeverity.init('process1', 'state1_1', card); expect(userCardUIControl.severity).toEqual(Severity.INFORMATION); expect(userCardSeverity.getSelectedSeverity()).toEqual(Severity.INFORMATION); }); it('Should set severity to value set by template via opfab.currentUserCard.setInitialSeverity ', async () => { await setProcessConfigWithUserCardConfig({}); opfab.currentUserCard.setInitialSeverity('COMPLIANT'); - userCardSeverity.setProcessAndState('process1', 'state1_1'); + userCardSeverity.init('process1', 'state1_1'); expect(userCardUIControl.severity).toEqual(Severity.COMPLIANT); expect(userCardSeverity.getSelectedSeverity()).toEqual(Severity.COMPLIANT); }); it('Should set selected severity when user selects severity', async () => { await setProcessConfigWithUserCardConfig({}); - userCardSeverity.setProcessAndState('process1', 'state1_1'); + userCardSeverity.init('process1', 'state1_1'); userCardSeverity.userSelectsSeverity(Severity.INFORMATION); expect(userCardSeverity.getSelectedSeverity()).toEqual(Severity.INFORMATION); }); diff --git a/ui/main/src/app/business/view/userCard/severityForm/severityForm.ts b/ui/main/src/app/business/view/userCard/severityForm/severityForm.ts index b23cd9a321..7c34a79c11 100644 --- a/ui/main/src/app/business/view/userCard/severityForm/severityForm.ts +++ b/ui/main/src/app/business/view/userCard/severityForm/severityForm.ts @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, RTE (http://www.rte-france.com) +/* Copyright (c) 2024-2025, RTE (http://www.rte-france.com) * See AUTHORS.txt * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -19,7 +19,7 @@ export class SeverityForm { constructor(private readonly userCardUIControl: UserCardUIControl) {} - public setProcessAndState(processId: string, stateId: string, card: Card = undefined) { + public init(processId: string, stateId: string, card: Card = undefined) { const state = ProcessesService.getProcess(processId).states.get(stateId); if (state) { this.severityVisible = state.userCard?.severityVisible ?? true; diff --git a/ui/main/src/app/business/view/userCard/userCard.view.ts b/ui/main/src/app/business/view/userCard/userCard.view.ts index 712a79bf7f..e425733d16 100644 --- a/ui/main/src/app/business/view/userCard/userCard.view.ts +++ b/ui/main/src/app/business/view/userCard/userCard.view.ts @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, RTE (http://www.rte-france.com) +/* Copyright (c) 2024-2025, RTE (http://www.rte-france.com) * See AUTHORS.txt * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -155,19 +155,14 @@ export class UserCardView { private initFieldsThatNeedToBeSetAfterExecutingTemplateScripts() { this.datesForm.initDatesAfterTemplateScriptsExecution(); - this.severityForm.setProcessAndState(this.currentProcessId, this.currentStateId, this.existingCard); + this.severityForm.init(this.currentProcessId, this.currentStateId, this.existingCard); this.keepChildCardsForm.setValueAndVisibility( this.currentProcessId, this.currentStateId, this.existingCard, this.editionMode ); - this.publisherForm.setProcessAndState( - this.currentProcessId, - this.currentStateId, - this.existingCard, - this.editionMode - ); + this.publisherForm.init(this.currentProcessId, this.currentStateId, this.existingCard, this.editionMode); } public async userClicksOnState(stateId: string) {