Skip to content
Snippets Groups Projects
Commit 67133562 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2500 OZG-2667 improve code for historie item decision

parent 19967d69
No related branches found
No related tags found
No related merge requests found
...@@ -51,3 +51,35 @@ export enum CommandOrder { ...@@ -51,3 +51,35 @@ export enum CommandOrder {
VORGANG_ABSCHLIESSEN = 'VORGANG_ABSCHLIESSEN', VORGANG_ABSCHLIESSEN = 'VORGANG_ABSCHLIESSEN',
VORGANG_WIEDEREROEFFNEN = 'VORGANG_WIEDEREROEFFNEN' VORGANG_WIEDEREROEFFNEN = 'VORGANG_WIEDEREROEFFNEN'
} }
export enum CommandOrderType {
USER = 'User',
FORWARDING = 'Forwarding',
KOMMENTAR = 'Kommentar',
POSTFACH_NACHRICHT = 'PostfachNachricht',
VORGANG = 'Vorgang',
WIEDERVORLAGE = 'Wiedervorlage'
}
export const ORDER_TYPE_BY_COMMAND_ORDER = {
[CommandOrder.ASSIGN_USER]: CommandOrderType.USER,
[CommandOrder.CREATE_KOMMENTAR]: CommandOrderType.KOMMENTAR,
[CommandOrder.EDIT_KOMMENTAR]: CommandOrderType.KOMMENTAR,
[CommandOrder.CREATE_WIEDERVORLAGE]: CommandOrderType.WIEDERVORLAGE,
[CommandOrder.EDIT_WIEDERVORLAGE]: CommandOrderType.WIEDERVORLAGE,
[CommandOrder.FORWARD_FAILED]: CommandOrderType.FORWARDING,
[CommandOrder.REDIRECT_VORGANG]: CommandOrderType.FORWARDING,
[CommandOrder.FORWARD_SUCCESSFULL]: CommandOrderType.FORWARDING,
[CommandOrder.SEND_POSTFACH_NACHRICHT]: CommandOrderType.POSTFACH_NACHRICHT,
[CommandOrder.RECEIVE_POSTFACH_NACHRICHT]: CommandOrderType.POSTFACH_NACHRICHT,
[CommandOrder.WIEDERVORLAGE_ERLEDIGEN]: CommandOrderType.WIEDERVORLAGE,
[CommandOrder.WIEDERVORLAGE_WIEDEREROEFFNEN]: CommandOrderType.WIEDERVORLAGE,
[CommandOrder.VORGANG_ANNEHMEN]: CommandOrderType.VORGANG,
[CommandOrder.VORGANG_VERWERFEN]: CommandOrderType.VORGANG,
[CommandOrder.VORGANG_ZURUECKHOLEN]: CommandOrderType.VORGANG,
[CommandOrder.VORGANG_BEARBEITEN]: CommandOrderType.VORGANG,
[CommandOrder.VORGANG_BESCHEIDEN]: CommandOrderType.VORGANG,
[CommandOrder.VORGANG_ZURUECKSTELLEN]: CommandOrderType.VORGANG,
[CommandOrder.VORGANG_ABSCHLIESSEN]: CommandOrderType.VORGANG,
[CommandOrder.VORGANG_WIEDEREROEFFNEN]: CommandOrderType.VORGANG
}
\ No newline at end of file
<ng-container *ngIf="isAssignUserOrder()"> <ng-container [ngSwitch]="orderTypeByCommandOrder[historieCommand.order]">
<goofy-client-historie-item-assign-user-container [command]="historieCommand"></goofy-client-historie-item-assign-user-container> <ng-container *ngSwitchCase="commandOrderType.USER">
<goofy-client-historie-item-assign-user-container [command]="historieCommand" data-test-id="historie-item-assign-user"></goofy-client-historie-item-assign-user-container>
</ng-container> </ng-container>
<ng-container *ngIf="isKommentarOrder()"> <ng-container *ngSwitchCase="commandOrderType.KOMMENTAR">
<goofy-client-historie-item-kommentar [command]="historieCommand"></goofy-client-historie-item-kommentar> <goofy-client-historie-item-kommentar [command]="historieCommand" data-test-id="historie-item-kommentar"></goofy-client-historie-item-kommentar>
</ng-container> </ng-container>
<ng-container *ngIf="isForwardingOrder()"> <ng-container *ngSwitchCase="commandOrderType.FORWARDING">
<goofy-client-historie-item-forwarding [command]="historieCommand"></goofy-client-historie-item-forwarding> <goofy-client-historie-item-forwarding [command]="historieCommand" data-test-id="historie-item-forwarding"></goofy-client-historie-item-forwarding>
</ng-container> </ng-container>
<ng-container *ngIf="isPostfachNachrichtOrder()"> <ng-container *ngSwitchCase="commandOrderType.POSTFACH_NACHRICHT">
<goofy-client-historie-item-postfach-nachricht [command]="historieCommand"></goofy-client-historie-item-postfach-nachricht> <goofy-client-historie-item-postfach-nachricht [command]="historieCommand" data-test-id="historie-item-postfach-nachricht"></goofy-client-historie-item-postfach-nachricht>
</ng-container> </ng-container>
<ng-container *ngIf="isVorgangStatusOrder()"> <ng-container *ngSwitchCase="commandOrderType.VORGANG">
<goofy-client-historie-item-vorgang-status [command]="historieCommand"></goofy-client-historie-item-vorgang-status> <goofy-client-historie-item-vorgang-status [command]="historieCommand" data-test-id="historie-item-vorgang"></goofy-client-historie-item-vorgang-status>
</ng-container> </ng-container>
<ng-container *ngIf="isWiedervorlageOrder()"> <ng-container *ngSwitchCase="commandOrderType.WIEDERVORLAGE">
<goofy-client-historie-item-wiedervorlage [command]="historieCommand"></goofy-client-historie-item-wiedervorlage> <goofy-client-historie-item-wiedervorlage [command]="historieCommand" data-test-id="historie-item-wiedervorlage"></goofy-client-historie-item-wiedervorlage>
</ng-container>
<ng-container *ngSwitchDefault>
<goofy-client-historie-item-unknown [headline]="historieCommand.order" [resource]="historieCommand" data-test-id="historie-item-unknown"></goofy-client-historie-item-unknown>
</ng-container> </ng-container>
<ng-container *ngIf="isUnknownOrder()">
<goofy-client-historie-item-unknown [headline]="order" [resource]="historieCommand"></goofy-client-historie-item-unknown>
</ng-container> </ng-container>
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CommandOrder } from '@goofy-client/command-shared'; import { CommandOrder, CommandOrderType } from '@goofy-client/command-shared';
import { getElementFromFixture } from '@goofy-client/test-utils';
import { createCommandResource } from 'libs/command-shared/test/command'; import { createCommandResource } from 'libs/command-shared/test/command';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { MockComponent } from 'ng-mocks'; import { MockComponent } from 'ng-mocks';
import { HistorieItemAssignUserContainerComponent } from '../historie-item-assign-user-container/historie-item-assign-user-container.component'; import { HistorieItemAssignUserContainerComponent } from '../historie-item-assign-user-container/historie-item-assign-user-container.component';
import { HistorieItemForwardingComponent } from '../historie-item-forwarding/historie-item-forwarding.component'; import { HistorieItemForwardingComponent } from '../historie-item-forwarding/historie-item-forwarding.component';
...@@ -16,13 +18,12 @@ describe('HistorieListItemComponent', () => { ...@@ -16,13 +18,12 @@ describe('HistorieListItemComponent', () => {
let component: HistorieListItemComponent; let component: HistorieListItemComponent;
let fixture: ComponentFixture<HistorieListItemComponent>; let fixture: ComponentFixture<HistorieListItemComponent>;
const kommentarOrder: string[] = [CommandOrder.CREATE_KOMMENTAR, CommandOrder.EDIT_KOMMENTAR]; const assignUserItem: string = getDataTestIdOf('historie-item-assign-user');
const forwardingOrder: string[] = [CommandOrder.FORWARD_FAILED, CommandOrder.REDIRECT_VORGANG, CommandOrder.FORWARD_SUCCESSFULL]; const kommentarItem: string = getDataTestIdOf('historie-item-kommentar');
const postfachNachrichtOrder: string[] = [CommandOrder.SEND_POSTFACH_NACHRICHT, CommandOrder.RECEIVE_POSTFACH_NACHRICHT]; const forwardingItem: string = getDataTestIdOf('historie-item-forwarding');
const vorgangStatusOrder: string[] = [CommandOrder.VORGANG_ANNEHMEN, CommandOrder.VORGANG_VERWERFEN, CommandOrder.VORGANG_ZURUECKHOLEN, CommandOrder.VORGANG_BEARBEITEN, const postfachNachrichtItem: string = getDataTestIdOf('historie-item-postfach-nachricht');
CommandOrder.VORGANG_BESCHEIDEN, CommandOrder.VORGANG_ZURUECKSTELLEN, CommandOrder.VORGANG_ABSCHLIESSEN, CommandOrder.VORGANG_WIEDEREROEFFNEN]; const vorgangItem: string = getDataTestIdOf('historie-item-vorgang');
const wiedervorlageOrder: string[] = [CommandOrder.CREATE_WIEDERVORLAGE, CommandOrder.EDIT_WIEDERVORLAGE, CommandOrder.WIEDERVORLAGE_ERLEDIGEN, CommandOrder.WIEDERVORLAGE_WIEDEREROEFFNEN]; const wiedervorlageItem: string = getDataTestIdOf('historie-item-wiedervorlage');
const UNKNOWN_ORDER: string = 'QUATSCH_ORDER_73';
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
...@@ -51,174 +52,91 @@ describe('HistorieListItemComponent', () => { ...@@ -51,174 +52,91 @@ describe('HistorieListItemComponent', () => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
}); });
describe('is assign user order', () => { describe('decision of item component', () => {
describe('on assign user order', () => {
it('should show on ' + CommandOrder.ASSIGN_USER, () => {
component.historieCommand = { ...createCommandResource(), order: CommandOrder.ASSIGN_USER };
const isAssignUserOrder = component.isAssignUserOrder();
expect(isAssignUserOrder).toBeTruthy();
})
})
describe('on other orders', () => {
it.each(wiedervorlageOrder)('should NOT show on order %s', (order: CommandOrder) => { describe('on ' + CommandOrderType.USER + ' type ', () => {
component.historieCommand = { ...createCommandResource(), order, body: {} };
const isAssignUserOrder = component.isAssignUserOrder(); const order: CommandOrder[] = [CommandOrder.ASSIGN_USER];
expect(isAssignUserOrder).toBeFalsy(); it.each(order)('should show item on order s%', (order: CommandOrder) => {
})
})
})
describe('is kommentar order', () => {
describe('on kommentar order', () => {
it.each(kommentarOrder)('should show on %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order }; component.historieCommand = { ...createCommandResource(), order };
fixture.detectChanges();
const isKommentarCommand = component.isKommentarOrder(); const itemComponent = getElementFromFixture(fixture, assignUserItem);
expect(isKommentarCommand).toBeTruthy();
})
})
describe('on other orders', () => {
it.each(wiedervorlageOrder)('should NOT show on order %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order, body: {} };
const isKommentarCommand = component.isKommentarOrder();
expect(isKommentarCommand).toBeFalsy(); expect(itemComponent).toBeInstanceOf(HTMLElement);
})
}) })
}) })
describe('is forwarding order', () => { describe('on ' + CommandOrderType.KOMMENTAR + ' type ', () => {
describe('on forwarding order', () => { const order: CommandOrder[] = [CommandOrder.CREATE_KOMMENTAR, CommandOrder.EDIT_KOMMENTAR];
it.each(forwardingOrder)('should show on %s', (order: CommandOrder) => { it.each(order)('should show item on order %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order }; component.historieCommand = { ...createCommandResource(), order };
fixture.detectChanges();
const isForwardingOrder = component.isForwardingOrder(); const itemComponent = getElementFromFixture(fixture, kommentarItem);
expect(isForwardingOrder).toBeTruthy();
})
})
describe('on other orders', () => {
it.each(wiedervorlageOrder)('should NOT show on order %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order, body: {} };
const isForwardingOrder = component.isForwardingOrder();
expect(isForwardingOrder).toBeFalsy(); expect(itemComponent).toBeInstanceOf(HTMLElement);
})
}) })
}) })
describe('is postfach nachricht order', () => { describe('on ' + CommandOrderType.FORWARDING + ' type ', () => {
describe('on postfach nachricht order', () => { const order: CommandOrder[] = [CommandOrder.REDIRECT_VORGANG, CommandOrder.FORWARD_SUCCESSFULL, CommandOrder.FORWARD_FAILED];
it.each(postfachNachrichtOrder)('should show on %s', (order: CommandOrder) => { it.each(order)('should show item on order %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order }; component.historieCommand = { ...createCommandResource(), order };
fixture.detectChanges();
const isPostfachNachrichtOrder = component.isPostfachNachrichtOrder(); const itemComponent = getElementFromFixture(fixture, forwardingItem);
expect(isPostfachNachrichtOrder).toBeTruthy();
})
})
describe('on other orders', () => {
it.each(kommentarOrder.concat(wiedervorlageOrder).concat(vorgangStatusOrder))('should NOT show on order %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order, body: {} };
const isWiedervorlageOrder = component.isPostfachNachrichtOrder();
expect(isWiedervorlageOrder).toBeFalsy(); expect(itemComponent).toBeInstanceOf(HTMLElement);
})
}) })
}) })
describe('is wiedervorlage order', () => { describe('on ' + CommandOrderType.POSTFACH_NACHRICHT + ' type ', () => {
describe('on wiedervorlage order', () => { const order: CommandOrder[] = [CommandOrder.SEND_POSTFACH_NACHRICHT, CommandOrder.RECEIVE_POSTFACH_NACHRICHT];
it.each(wiedervorlageOrder)('should show on %s', (order: CommandOrder) => { it.each(order)('should show item on order %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order }; component.historieCommand = { ...createCommandResource(), order };
fixture.detectChanges();
const isKommentarOrder = component.isWiedervorlageOrder(); const itemComponent = getElementFromFixture(fixture, postfachNachrichtItem);
expect(isKommentarOrder).toBeTruthy();
})
})
describe('on other orders', () => {
it.each(kommentarOrder)('should NOT show on order %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order, body: {} };
const isWiedervorlageOrder = component.isWiedervorlageOrder();
expect(isWiedervorlageOrder).toBeFalsy(); expect(itemComponent).toBeInstanceOf(HTMLElement);
})
}) })
}) })
describe('is vorgang status order', () => { describe('on ' + CommandOrderType.VORGANG + ' type ', () => {
describe('on vorgang status order', () => { const order: CommandOrder[] = [CommandOrder.VORGANG_ANNEHMEN, CommandOrder.VORGANG_VERWERFEN, CommandOrder.VORGANG_ZURUECKHOLEN, CommandOrder.VORGANG_BEARBEITEN,
CommandOrder.VORGANG_BESCHEIDEN, CommandOrder.VORGANG_ZURUECKSTELLEN, CommandOrder.VORGANG_ABSCHLIESSEN, CommandOrder.VORGANG_WIEDEREROEFFNEN];
it.each(vorgangStatusOrder)('should show on %s', (order: CommandOrder) => { it.each(order)('should show item on order %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order }; component.historieCommand = { ...createCommandResource(), order };
fixture.detectChanges();
const isKommentarOrder = component.isVorgangStatusOrder(); const itemComponent = getElementFromFixture(fixture, vorgangItem);
expect(isKommentarOrder).toBeTruthy();
})
})
describe('on other orders', () => {
it.each(kommentarOrder.concat(wiedervorlageOrder))('should NOT show on order %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order, body: {} };
const isWiedervorlageOrder = component.isVorgangStatusOrder();
expect(isWiedervorlageOrder).toBeFalsy(); expect(itemComponent).toBeInstanceOf(HTMLElement);
})
}) })
}) })
describe('is unknown order', () => { describe('on ' + CommandOrderType.WIEDERVORLAGE + ' type ', () => {
const knownOrder: string[] = wiedervorlageOrder.concat(kommentarOrder).concat(vorgangStatusOrder); const order: CommandOrder[] = [CommandOrder.CREATE_WIEDERVORLAGE, CommandOrder.EDIT_WIEDERVORLAGE, CommandOrder.WIEDERVORLAGE_ERLEDIGEN, CommandOrder.WIEDERVORLAGE_WIEDEREROEFFNEN];
it.each(knownOrder)('should return false on known order %s', (order: CommandOrder) => { it.each(order)('should show item on order %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order, body: {} }; component.historieCommand = { ...createCommandResource(), order };
fixture.detectChanges();
const isWiedervorlageOrder = component.isUnknownOrder(); const itemComponent = getElementFromFixture(fixture, wiedervorlageItem);
expect(isWiedervorlageOrder).toBeFalsy(); expect(itemComponent).toBeInstanceOf(HTMLElement);
}) })
it.each([UNKNOWN_ORDER])('should return true on unknown order %s', (order: CommandOrder) => {
component.historieCommand = { ...createCommandResource(), order, body: {} };
const isWiedervorlageOrder = component.isUnknownOrder();
expect(isWiedervorlageOrder).toBeTruthy();
}) })
}) })
}); });
\ No newline at end of file
import { Component, Input } from '@angular/core'; import { Component, Input } from '@angular/core';
import { CommandOrder, CommandResource } from '@goofy-client/command-shared'; import { CommandOrderType, CommandResource, ORDER_TYPE_BY_COMMAND_ORDER } from '@goofy-client/command-shared';
@Component({ @Component({
selector: 'goofy-client-historie-list-item', selector: 'goofy-client-historie-list-item',
...@@ -10,76 +10,6 @@ export class HistorieListItemComponent { ...@@ -10,76 +10,6 @@ export class HistorieListItemComponent {
@Input() historieCommand: CommandResource @Input() historieCommand: CommandResource
readonly commandOrder = CommandOrder; readonly orderTypeByCommandOrder = ORDER_TYPE_BY_COMMAND_ORDER;
readonly commandOrderType = CommandOrderType;
get order(): CommandOrder {
return this.historieCommand.order;
}
isUnknownOrder(): boolean {
return !this.isAssignUserOrder()
&& !this.isKommentarOrder()
&& !this.isForwardingOrder()
&& !this.isPostfachNachrichtOrder()
&& !this.isVorgangStatusOrder()
&& !this.isWiedervorlageOrder();
}
isAssignUserOrder(): boolean {
return CommandOrder.ASSIGN_USER == this.order;
}
isKommentarOrder(): boolean {
return KOMMENTAR_ORDER.includes(this.order);
}
isForwardingOrder(): boolean {
return FORWARDING_ORDER.includes(this.order);
}
isPostfachNachrichtOrder(): boolean {
return POSTFACH_NACHRICHT_ORDER.includes(this.order);
} }
\ No newline at end of file
isVorgangStatusOrder(): boolean {
return VORGANG_STATUS_ORDER.includes(this.order);
}
isWiedervorlageOrder(): boolean {
return WIEDERVORLAGE_ORDER.includes(this.order);
}
}
const KOMMENTAR_ORDER: CommandOrder[] = [
CommandOrder.CREATE_KOMMENTAR,
CommandOrder.EDIT_KOMMENTAR
];
const FORWARDING_ORDER: CommandOrder[] = [
CommandOrder.REDIRECT_VORGANG,
CommandOrder.FORWARD_FAILED,
CommandOrder.FORWARD_SUCCESSFULL
];
const POSTFACH_NACHRICHT_ORDER: CommandOrder[] = [
CommandOrder.SEND_POSTFACH_NACHRICHT,
CommandOrder.RECEIVE_POSTFACH_NACHRICHT
];
const VORGANG_STATUS_ORDER: CommandOrder[] = [
CommandOrder.VORGANG_ANNEHMEN,
CommandOrder.VORGANG_VERWERFEN,
CommandOrder.VORGANG_ZURUECKHOLEN,
CommandOrder.VORGANG_BEARBEITEN,
CommandOrder.VORGANG_BESCHEIDEN,
CommandOrder.VORGANG_ZURUECKSTELLEN,
CommandOrder.VORGANG_ABSCHLIESSEN,
CommandOrder.VORGANG_WIEDEREROEFFNEN
];
const WIEDERVORLAGE_ORDER: CommandOrder[] = [
CommandOrder.CREATE_WIEDERVORLAGE,
CommandOrder.EDIT_WIEDERVORLAGE,
CommandOrder.WIEDERVORLAGE_ERLEDIGEN,
CommandOrder.WIEDERVORLAGE_WIEDEREROEFFNEN
];
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment