Skip to content

Commit

Permalink
Rename methods in usercard ui component for clarity
Browse files Browse the repository at this point in the history
Signed-off-by: freddidierRTE <[email protected]>
  • Loading branch information
freddidierRTE authored and vlo-rte committed Jan 7, 2025
1 parent 5ea2bcc commit 7646106
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -80,55 +80,55 @@ 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'}
]);
});
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'}
]);
});
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'}
]);
});
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'}
]);
});
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');
});
Expand All @@ -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 () => {
Expand All @@ -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'}
Expand All @@ -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'}
Expand All @@ -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'}
Expand All @@ -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 () => {
Expand All @@ -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');
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down
11 changes: 3 additions & 8 deletions ui/main/src/app/business/view/userCard/userCard.view.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7646106

Please sign in to comment.