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

OZG-3574 impl hasAnyLink pipe; fix linkRel renaming; cleanup

parent 62767967
No related branches found
No related tags found
No related merge requests found
Showing
with 63 additions and 19 deletions
import { Resource } from "@ngxp/rest";
import { createDummyResource } from "libs/tech-shared/test/resource";
import { HasAnyLinkPipe } from "./has-any-link.pipe";
describe('HasAnyLinkPipe', () => {
const oneLink: string = 'one';
const anotherLink: string = 'another';
const resource: Resource = createDummyResource([oneLink, anotherLink]);
const pipe: HasAnyLinkPipe = new HasAnyLinkPipe();
it('should return true if resource has at least on link', () => {
const result: boolean = pipe.transform(resource, oneLink, 'notExists');
expect(result).toBe(true);
})
it('resource return true if resoure has multiple links', () => {
const result: boolean = pipe.transform(resource, oneLink, anotherLink);
expect(result).toBe(true);
})
it('should return false if resource has no of given links', () => {
const result: boolean = pipe.transform(resource, 'notExists', 'notExistsToo');
expect(result).toBe(false);
})
it('should return false if resource is null', () => {
const result: boolean = pipe.transform(null, 'notExists', 'notExistsToo');
expect(result).toBe(false);
})
})
import { Pipe, PipeTransform } from "@angular/core";
import { hasLink, Resource } from "@ngxp/rest";
import { isEmpty } from "lodash-es";
@Pipe({ name: 'hasAnyLink' })
export class HasAnyLinkPipe implements PipeTransform {
transform(resource: Resource, ...links: string[]) {
return !isEmpty(links.map(link => hasLink(resource, link)).filter(hasLink => hasLink === true));
}
}
......@@ -32,6 +32,7 @@ import { EnumToLabelPipe } from './pipe/enum-to-label.pipe';
import { FileSizePipe } from './pipe/file-size.pipe';
import { FormatDateWithTimePipe } from './pipe/format-date-with-time.pipe';
import { FormatToPrettyDatePipe } from './pipe/format-to-pretty-date.pipe';
import { HasAnyLinkPipe } from './pipe/has-any-link.pipe';
import { HasLinkPipe } from './pipe/has-link.pipe';
import { NotHasLinkPipe } from './pipe/not-has-link.pipe';
import { ToEmbeddedResourcesPipe } from './pipe/to-embedded-resource.pipe';
......@@ -46,6 +47,7 @@ import { ToTrafficLightPipe } from './pipe/to-traffic-light.pipe';
EnumToLabelPipe,
FormatDateWithTimePipe,
HasLinkPipe,
HasAnyLinkPipe,
NotHasLinkPipe,
ToResourceUriPipe,
ToTrafficLightPipe,
......@@ -59,6 +61,7 @@ import { ToTrafficLightPipe } from './pipe/to-traffic-light.pipe';
EnumToLabelPipe,
FormatDateWithTimePipe,
HasLinkPipe,
HasAnyLinkPipe,
NotHasLinkPipe,
ToResourceUriPipe,
ToTrafficLightPipe,
......
......@@ -25,7 +25,7 @@
-->
<ng-container *ngIf="apiRoot$ | async as apiRootStateResource">
<goofy-client-vorgang-search *ngIf="(apiRootStateResource.resource | hasLink: apiRootLinkRel.SEARCH) || (apiRootStateResource.resource | hasLink: apiRootLinkRel.SEARCH_MY_VORGAENGE)" data-test-id="vorgang-search"
<goofy-client-vorgang-search *ngIf="(apiRootStateResource.resource | hasLink: apiRootLinkRel.SEARCH_ALLE) || (apiRootStateResource.resource | hasLink: apiRootLinkRel.SEARCH_MEINE)" data-test-id="vorgang-search"
[vorgangSearchPreviewList]="vorgangSearchPreviewList$ | async" [searchString]="searchString$ | async"
(clearVorgangSearchPreviewList)="clearVorgangSearchPreviewList()">
</goofy-client-vorgang-search>
......
......@@ -104,7 +104,7 @@ describe('VorgangSearchContainerComponent', () => {
expect(element).not.toBeInstanceOf(HTMLElement);
})
it.each([ApiRootLinkRel.SEARCH, ApiRootLinkRel.SEARCH_MY_VORGAENGE])
it.each([ApiRootLinkRel.SEARCH_ALLE, ApiRootLinkRel.SEARCH_MEINE])
('should show on link "%s"', (linkRel: string) => {
component.apiRoot$ = of(createStateResource(createApiRootResource([linkRel])));
fixture.detectChanges();
......@@ -118,7 +118,7 @@ describe('VorgangSearchContainerComponent', () => {
describe('clear vorgangSearchPreviewList event', () => {
it('should call service clearSearchPreviewList', () => {
component.apiRoot$ = of(createStateResource(createApiRootResource([ApiRootLinkRel.SEARCH])));
component.apiRoot$ = of(createStateResource(createApiRootResource([ApiRootLinkRel.SEARCH_ALLE])));
fixture.detectChanges();
dispatchEventFromFixture(fixture, vorgangSearch, 'clearVorgangSearchPreviewList');
......
......@@ -85,10 +85,6 @@ export function getSearchLinkRel(vorgangFilter: VorgangFilter): string {
return vorgangFilter === VorgangFilter.MEINE_VORGAENGE ? ApiRootLinkRel.SEARCH_MEINE : ApiRootLinkRel.SEARCH_ALLE;
}
// export function shouldSearchForPreview(previewList: StateResource<VorgangListResource>, searchString: string): boolean {
// return previewList.reload && !previewList.loading && (searchString != EMPTY_STRING);
// }
export function getVorgangFilter(routeData: RouteData): VorgangFilter {
return isUebersichtsSeite(routeData) ? VORGANG_FILTER_BY_ROUTE_PARAM[getRouteUrlSegment(routeData, 0)] : undefined;
}
......
......@@ -28,7 +28,7 @@
<mat-button-toggle data-test-id="meine-vorgaenge-filter-toggle-button" [value]="formService.FILTER_MEINE_VALUE">
<goofy-client-vorgang-meine-filter-item-container></goofy-client-vorgang-meine-filter-item-container>
</mat-button-toggle>
<mat-button-toggle *ngIf="apiRootStateResource.resource | hasLink: apiRootLinkRel.VORGAENGE" data-test-id="alle-filter-toggle-button" [value]="formService.FILTER_ALLE_VALUE">
<mat-button-toggle *ngIf="apiRootStateResource.resource | hasLink: apiRootLinkRel.ALLE_VORGAENGE" data-test-id="alle-filter-toggle-button" [value]="formService.FILTER_ALLE_VALUE">
<goofy-client-vorgang-alle-filter-item-container></goofy-client-vorgang-alle-filter-item-container>
</mat-button-toggle>
</mat-button-toggle-group>
......
......@@ -28,7 +28,7 @@
<div class="content">
<goofy-client-vorgang-views-menu *ngIf="apiRootStateResource.resource" [apiRootResource]="apiRootStateResource.resource" class="left"></goofy-client-vorgang-views-menu>
<main *ngIf="apiRootStateResource?.resource | hasLink: apiRootLinkRel.VORGAENGE; else showNoRoleMessage" data-test-id="vorgaenge-list"><router-outlet></router-outlet></main>
<main *ngIf="apiRootStateResource?.resource | hasLink: apiRootLinkRel.ALLE_VORGAENGE; else showNoRoleMessage" data-test-id="vorgaenge-list"><router-outlet></router-outlet></main>
<ng-template #showNoRoleMessage>
<h1 data-test-id="user-no-role-message">Die Allgemeine Fachanwendung ist wegen fehlender Rollen nicht benutzbar.</h1>
</ng-template>
......
......@@ -24,8 +24,9 @@
-->
<div class="views">
<goofy-client-vorgang-neu-view-item-container *ngIf="(apiRootResource | hasLink: apiRootLinkRel.ALLE_VORGAENGE_NEU) || (apiRootResource | hasLink: apiRootLinkRel.MEINE_VORGAENGE_NEU)" data-test-id="vorgang-neu-view">
<goofy-client-vorgang-neu-view-item-container *ngIf="apiRootResource | hasAnyLink: apiRootLinkRel.ALLE_VORGAENGE_NEU: apiRootLinkRel.MEINE_VORGAENGE_NEU" data-test-id="vorgang-neu-view">
</goofy-client-vorgang-neu-view-item-container>
<!-- TODO Richtige Links abfragen + Tests -->
<goofy-client-vorgang-angenommen-view-item-container *ngIf="(apiRootResource | hasLink: apiRootLinkRel.ALLE_VORGAENGE_ANGENOMMEN) || (apiRootResource | hasLink: apiRootLinkRel.MEINE_VORGAENGE_NEU)" data-test-id="vorgang-angenommen-view">
</goofy-client-vorgang-angenommen-view-item-container>
<goofy-client-vorgang-in-bearbeitung-view-item-container *ngIf="(apiRootResource | hasLink: apiRootLinkRel.ALLE_VORGAENGE_IN_BEARBEITUNG) || (apiRootResource | hasLink: apiRootLinkRel.MEINE_VORGAENGE_NEU)" data-test-id="vorgang-in-bearbeitung-view">
......@@ -36,10 +37,8 @@
</goofy-client-vorgang-abgeschlossen-view-item-container>
<goofy-client-vorgang-verworfen-view-item-container *ngIf="(apiRootResource | hasLink: apiRootLinkRel.ALLE_VORGAENGE_VERWORFEN) || (apiRootResource | hasLink: apiRootLinkRel.MEINE_VORGAENGE_NEU)" data-test-id="vorgang-verworfen-view">
</goofy-client-vorgang-verworfen-view-item-container>
<goofy-client-vorgang-list-view-item-container *ngIf="apiRootResource | hasLink: apiRootLinkRel.VORGAENGE" data-test-id="vorgang-vorgang-list-view" class="top-border">
<goofy-client-vorgang-list-view-item-container *ngIf="apiRootResource | hasLink: apiRootLinkRel.ALLE_VORGAENGE" data-test-id="vorgang-vorgang-list-view" class="top-border">
</goofy-client-vorgang-list-view-item-container>
<goofy-client-vorgang-search-view-item-container *ngIf="(apiRootResource | hasLink: apiRootLinkRel.SEARCH) || (apiRootResource | hasLink: apiRootLinkRel.SEARCH_MY_VORGAENGE)" data-test-id="vorgang-search-view" class="top-border">
<goofy-client-vorgang-search-view-item-container *ngIf="(apiRootResource | hasLink: apiRootLinkRel.SEARCH_ALLE) || (apiRootResource | hasLink: apiRootLinkRel.SEARCH_MEINE)" data-test-id="vorgang-search-view" class="top-border">
</goofy-client-vorgang-search-view-item-container>
</div>
\ No newline at end of file
......@@ -26,6 +26,7 @@ import { ApiRootLinkRel } from '@goofy-client/api-root-shared';
import { HasLinkPipe } from '@goofy-client/tech-shared';
import { getElementFromFixture } from '@goofy-client/test-utils';
import { createApiRootResource } from 'libs/api-root-shared/test/api-root';
import { HasAnyLinkPipe } from 'libs/tech-shared/src/lib/pipe/has-any-link.pipe';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { MockComponent } from 'ng-mocks';
import { VorgangAbgeschlossenViewItemContainerComponent } from './vorgang-abgeschlossen-view-item-container/vorgang-abgeschlossen-view-item-container.component';
......@@ -51,6 +52,7 @@ describe('VorgangViewsMenuComponent', () => {
declarations: [
VorgangViewsMenuComponent,
HasLinkPipe,
HasAnyLinkPipe,
MockComponent(VorgangListViewItemContainerComponent),
MockComponent(VorgangSearchViewItemContainerComponent),
MockComponent(VorgangNeuViewItemContainerComponent),
......@@ -102,7 +104,7 @@ describe('VorgangViewsMenuComponent', () => {
})
describe('alle vorgaenge view', () => {
describe('vorgangList view', () => {
it('should show if link exists', () => {
component.apiRootResource = createApiRootResource([ApiRootLinkRel.ALLE_VORGAENGE]);
......@@ -125,7 +127,7 @@ describe('VorgangViewsMenuComponent', () => {
describe('search view', () => {
it('should show if search link exists', () => {
it('should show if ' + ApiRootLinkRel.SEARCH_ALLE + ' link exists', () => {
component.apiRootResource = createApiRootResource([ApiRootLinkRel.SEARCH_ALLE]);
fixture.detectChanges();
......@@ -134,7 +136,7 @@ describe('VorgangViewsMenuComponent', () => {
expect(element).toBeInstanceOf(HTMLElement);
})
it('should show if searchMyVorgaenge link exists', () => {
it('should show if ' + ApiRootLinkRel.SEARCH_MEINE + ' link exists', () => {
component.apiRootResource = createApiRootResource([ApiRootLinkRel.SEARCH_MEINE]);
fixture.detectChanges();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment