Skip to content
Snippets Groups Projects
Commit 92562f3f authored by Albert Bruns's avatar Albert Bruns
Browse files

OZG-3563 some fixes

parent 661b881a
No related branches found
No related tags found
1 merge request!129OZG-3563-anbindung-resourceservice-kommentar-shared
Showing with 104 additions and 125 deletions
...@@ -22,16 +22,18 @@ ...@@ -22,16 +22,18 @@
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { BinaryFileService } from '@alfa-client/binary-file-shared'; import { BinaryFileService } from '@alfa-client/binary-file-shared';
import { createStateResource, StateResource } from '@alfa-client/tech-shared'; import { createStateResource, EMPTY_STRING, StateResource } from '@alfa-client/tech-shared';
import { mock, Mock, useFromMock } from '@alfa-client/test-utils'; import { mock, Mock, useFromMock } from '@alfa-client/test-utils';
import { createKommentar, createKommentarResource } from 'libs/kommentar-shared/test/kommentar'; import { createKommentar, createKommentarResource } from 'libs/kommentar-shared/test/kommentar';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
import { KommentarListResourceService } from './kommentar-list-resource.service'; import { KommentarListResourceService } from './kommentar-list-resource.service';
import { KommentarResourceService } from './kommentar-recource.service'; import { KommentarResourceService } from './kommentar-recource.service';
import { Kommentar, KommentarResource } from './kommentar.model'; import { Kommentar, KOMMENTAR_UPLOADED_ATTACHMENTS, KommentarResource } from './kommentar.model';
import { KommentarService } from './kommentar.service'; import { KommentarService } from './kommentar.service';
import { CommandLinkRel, CommandResource } from '@alfa-client/command-shared'; import { CommandLinkRel, CommandResource } from '@alfa-client/command-shared';
import { faker } from '@faker-js/faker/.';
import { ResourceUri } from '@ngxp/rest';
import { createCommandResource } from '../../../command-shared/test/command'; import { createCommandResource } from '../../../command-shared/test/command';
import { singleCold } from '../../../tech-shared/test/marbles'; import { singleCold } from '../../../tech-shared/test/marbles';
import { KommentarLinkRel } from './kommentar.linkrel'; import { KommentarLinkRel } from './kommentar.linkrel';
...@@ -142,16 +144,11 @@ describe('KommentarService', () => { ...@@ -142,16 +144,11 @@ describe('KommentarService', () => {
describe('attachments', () => { describe('attachments', () => {
it('should be loaded if link avaible', () => { it('should be loaded if link avaible', () => {
const kommentarResource: KommentarResource = createKommentarResource([ const kommentarResource: KommentarResource = createKommentarResource([KommentarLinkRel.ATTACHMENTS]);
KommentarLinkRel.ATTACHMENTS,
]);
service.getAttachments(kommentarResource); service.getAttachments(kommentarResource);
expect(binaryFileService.getFiles).toHaveBeenCalledWith( expect(binaryFileService.getFiles).toHaveBeenCalledWith(kommentarResource, KommentarLinkRel.ATTACHMENTS);
kommentarResource,
KommentarLinkRel.ATTACHMENTS,
);
}); });
it('should not be loaded if no link available', () => { it('should not be loaded if no link available', () => {
...@@ -190,21 +187,21 @@ describe('KommentarService', () => { ...@@ -190,21 +187,21 @@ describe('KommentarService', () => {
service._currentlyEdited$.next(EMPTY_STRING); service._currentlyEdited$.next(EMPTY_STRING);
service.formularVisibility$.next(true); service.formularVisibility$.next(true);
expect(service.isFormularVisible()).toBeObservable(singleCold(true)); expect(service.isNewKommentarFormularVisible()).toBeObservable(singleCold(true));
}); });
it('should emit false if any kommentar is being edited', () => { it('should emit false if any kommentar is being edited', () => {
service._currentlyEdited$.next(faker.internet.url()); service._currentlyEdited$.next(faker.internet.url());
service.formularVisibility$.next(true); service.formularVisibility$.next(true);
expect(service.isFormularVisible()).toBeObservable(singleCold(false)); expect(service.isNewKommentarFormularVisible()).toBeObservable(singleCold(false));
}); });
it('should emit false if not visible', () => { it('should emit false if not visible', () => {
service._currentlyEdited$.next(EMPTY_STRING); service._currentlyEdited$.next(EMPTY_STRING);
service.formularVisibility$.next(false); service.formularVisibility$.next(false);
expect(service.isFormularVisible()).toBeObservable(singleCold(false)); expect(service.isNewKommentarFormularVisible()).toBeObservable(singleCold(false));
}); });
}); });
...@@ -214,13 +211,13 @@ describe('KommentarService', () => { ...@@ -214,13 +211,13 @@ describe('KommentarService', () => {
}); });
it('should set currently edited to empty string', () => { it('should set currently edited to empty string', () => {
service.showFormular(); service.showNewKommentarFormular();
expect(service.setCurrentlyEdited).toHaveBeenCalledWith(EMPTY_STRING); expect(service.setCurrentlyEdited).toHaveBeenCalledWith(EMPTY_STRING);
}); });
it('should set formular visibility', () => { it('should set formular visibility', () => {
service.showFormular(); service.showNewKommentarFormular();
expect(service.formularVisibility$).toBeObservable(singleCold(true)); expect(service.formularVisibility$).toBeObservable(singleCold(true));
}); });
...@@ -229,7 +226,7 @@ describe('KommentarService', () => { ...@@ -229,7 +226,7 @@ describe('KommentarService', () => {
describe('set currently edited kommentar uri', () => { describe('set currently edited kommentar uri', () => {
beforeEach(() => { beforeEach(() => {
service.clearUploadedFiles = jest.fn(); service.clearUploadedFiles = jest.fn();
service.hideFormular = jest.fn(); service.hideNewKommentarFormular = jest.fn();
}); });
it('should clear uploaded files', () => { it('should clear uploaded files', () => {
...@@ -241,13 +238,13 @@ describe('KommentarService', () => { ...@@ -241,13 +238,13 @@ describe('KommentarService', () => {
it('should hide kommentar creation formular', () => { it('should hide kommentar creation formular', () => {
service.setCurrentlyEdited(faker.internet.url()); service.setCurrentlyEdited(faker.internet.url());
expect(service.hideFormular).toHaveBeenCalled(); expect(service.hideNewKommentarFormular).toHaveBeenCalled();
}); });
it('should NOT hide kommentar creation formular', () => { it('should NOT hide kommentar creation formular', () => {
service.setCurrentlyEdited(EMPTY_STRING); service.setCurrentlyEdited(EMPTY_STRING);
expect(service.hideFormular).not.toHaveBeenCalled(); expect(service.hideNewKommentarFormular).not.toHaveBeenCalled();
}); });
it('should emit currently edited resource uri', () => { it('should emit currently edited resource uri', () => {
......
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
*/ */
import { BinaryFileListResource, BinaryFileService } from '@alfa-client/binary-file-shared'; import { BinaryFileListResource, BinaryFileService } from '@alfa-client/binary-file-shared';
import { CommandResource, tapOnCommandSuccessfullyDone } from '@alfa-client/command-shared'; import { CommandResource, tapOnCommandSuccessfullyDone } from '@alfa-client/command-shared';
import { createEmptyStateResource, EMPTY_STRING, StateResource } from '@alfa-client/tech-shared'; import { createEmptyStateResource, EMPTY_STRING, isNotEmpty, StateResource } from '@alfa-client/tech-shared';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { getUrl, hasLink, ResourceUri } from '@ngxp/rest'; import { getUrl, hasLink, ResourceUri } from '@ngxp/rest';
import { BehaviorSubject, Observable, of } from 'rxjs'; import { BehaviorSubject, combineLatest, map, Observable, of } from 'rxjs';
import { KommentarListResourceService } from './kommentar-list-resource.service'; import { KommentarListResourceService } from './kommentar-list-resource.service';
import { KommentarResourceService } from './kommentar-recource.service'; import { KommentarResourceService } from './kommentar-recource.service';
import { KommentarLinkRel } from './kommentar.linkrel'; import { KommentarLinkRel } from './kommentar.linkrel';
...@@ -48,11 +48,13 @@ export class KommentarService { ...@@ -48,11 +48,13 @@ export class KommentarService {
} }
public isNewKommentarFormularVisible(): Observable<boolean> { public isNewKommentarFormularVisible(): Observable<boolean> {
return this.formularVisibility$.asObservable(); return combineLatest([this.formularVisibility$, this._currentlyEdited$]).pipe(
map(([isVisible, currentlyEdited]) => isVisible && currentlyEdited === EMPTY_STRING),
);
} }
public showNewKommentarFormular(): void { public showNewKommentarFormular(): void {
// this.setCurrentlyEdited(EMPTY_STRING); this.setCurrentlyEdited(EMPTY_STRING);
this.formularVisibility$.next(true); this.formularVisibility$.next(true);
} }
...@@ -96,15 +98,15 @@ export class KommentarService { ...@@ -96,15 +98,15 @@ export class KommentarService {
this.binaryFileService.clearUploadedFiles(KOMMENTAR_UPLOADED_ATTACHMENTS); this.binaryFileService.clearUploadedFiles(KOMMENTAR_UPLOADED_ATTACHMENTS);
} }
// public getCurrentlyEdited(): Observable<ResourceUri> { public getCurrentlyEdited(): Observable<ResourceUri> {
// return this._currentlyEdited$.asObservable(); return this._currentlyEdited$.asObservable();
// } }
//
// public setCurrentlyEdited(resourceUri: ResourceUri): void { public setCurrentlyEdited(resourceUri: ResourceUri): void {
// this.clearUploadedFiles(); this.clearUploadedFiles();
// if (isNotEmpty(resourceUri)) { if (isNotEmpty(resourceUri)) {
// this.hideNewKommentarFormular(); this.hideNewKommentarFormular();
// } }
// this._currentlyEdited$.next(resourceUri); this._currentlyEdited$.next(resourceUri);
// } }
} }
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<div class="kommentar-head"> <div class="kommentar-head">
<alfa-user-profile-in-kommentar-container <alfa-user-profile-in-kommentar-container
class="username" class="username"
*ngIf="kommentar | hasLink: kommentarLinkRel.CREATED_BY" *ngIf="kommentar | hasLink: KommentarLinkRel.CREATED_BY"
[kommentar]="kommentar" [kommentar]="kommentar"
data-test-class="kommentar-created-by" data-test-class="kommentar-created-by"
> >
...@@ -41,10 +41,10 @@ ...@@ -41,10 +41,10 @@
<p class="text">{{ kommentar.text }}</p> <p class="text">{{ kommentar.text }}</p>
</button> </button>
@if (kommentar | hasLink: kommentarLinkRel.ATTACHMENTS) { @if (kommentar | hasLink: KommentarLinkRel.ATTACHMENTS) {
<alfa-binary-file-list-container <alfa-binary-file-list-container
[resource]="kommentar" [resource]="kommentar"
[linkRel]="kommentarLinkRel.ATTACHMENTS" [linkRel]="KommentarLinkRel.ATTACHMENTS"
></alfa-binary-file-list-container> ></alfa-binary-file-list-container>
} }
</div> </div>
......
...@@ -21,18 +21,16 @@ ...@@ -21,18 +21,16 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { KommentarLinkRel, KommentarService } from '@alfa-client/kommentar-shared'; import { KommentarLinkRel, KommentarResource, KommentarService } from '@alfa-client/kommentar-shared';
import { import { ConvertForDataTestPipe, createStateResource, FormatDateWithTimePipe, HasLinkPipe } from '@alfa-client/tech-shared';
ConvertForDataTestPipe,
FormatDateWithTimePipe,
HasLinkPipe,
createStateResource,
} from '@alfa-client/tech-shared';
import { getElementFromFixture, mock } from '@alfa-client/test-utils'; import { getElementFromFixture, mock } from '@alfa-client/test-utils';
import { UserProfileInKommentarContainerComponent } from '@alfa-client/user-profile'; import { UserProfileInKommentarContainerComponent } from '@alfa-client/user-profile';
import { registerLocaleData } from '@angular/common'; import { registerLocaleData } from '@angular/common';
import localeDe from '@angular/common/locales/de'; import localeDe from '@angular/common/locales/de';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { faker } from '@faker-js/faker/.';
import { expect } from '@jest/globals';
import { getUrl } from '@ngxp/rest';
import { createKommentarResource } from 'libs/kommentar-shared/test/kommentar'; import { createKommentarResource } from 'libs/kommentar-shared/test/kommentar';
import { getDataTestClassOf } from 'libs/tech-shared/test/data-test'; import { getDataTestClassOf } from 'libs/tech-shared/test/data-test';
import { MockComponent } from 'ng-mocks'; import { MockComponent } from 'ng-mocks';
...@@ -47,7 +45,6 @@ describe('KommentarListItemInVorgangComponent', () => { ...@@ -47,7 +45,6 @@ describe('KommentarListItemInVorgangComponent', () => {
let component: KommentarListItemInVorgangComponent; let component: KommentarListItemInVorgangComponent;
let fixture: ComponentFixture<KommentarListItemInVorgangComponent>; let fixture: ComponentFixture<KommentarListItemInVorgangComponent>;
const clickEvent = new MouseEvent('click');
const userProfile: string = getDataTestClassOf('kommentar-created-by'); const userProfile: string = getDataTestClassOf('kommentar-created-by');
const kommentarService = mock(KommentarService); const kommentarService = mock(KommentarService);
...@@ -73,7 +70,7 @@ describe('KommentarListItemInVorgangComponent', () => { ...@@ -73,7 +70,7 @@ describe('KommentarListItemInVorgangComponent', () => {
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(KommentarListItemInVorgangComponent); fixture = TestBed.createComponent(KommentarListItemInVorgangComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
component.kommentar = createKommentarResource([KommentarLinkRel.SELF, KommentarLinkRel.EDIT]); component.kommentar = createKommentarResource();
fixture.detectChanges(); fixture.detectChanges();
}); });
...@@ -81,6 +78,37 @@ describe('KommentarListItemInVorgangComponent', () => { ...@@ -81,6 +78,37 @@ describe('KommentarListItemInVorgangComponent', () => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
}); });
describe('set currently edited', () => {
const kommentar: KommentarResource = createKommentarResource();
it('should set edit mode to false on same currently edited resource uri', () => {
component.editMode = false;
component.kommentar = kommentar;
component.currentlyEdited = getUrl(kommentar);
expect(component.editMode).toBe(false);
});
it('should set edit mode to false on different currently edited resource uri', () => {
component.editMode = true;
component.kommentar = kommentar;
component.currentlyEdited = faker.internet.url();
expect(component.editMode).toBe(false);
});
it('should set edit mode to true', () => {
component.editMode = true;
component.kommentar = kommentar;
component.currentlyEdited = getUrl(kommentar);
expect(component.editMode).toBe(true);
});
});
describe('user profile', () => { describe('user profile', () => {
it('should be visible on existing link', () => { it('should be visible on existing link', () => {
component.kommentar = createKommentarResource([KommentarLinkRel.CREATED_BY]); component.kommentar = createKommentarResource([KommentarLinkRel.CREATED_BY]);
...@@ -112,56 +140,35 @@ describe('KommentarListItemInVorgangComponent', () => { ...@@ -112,56 +140,35 @@ describe('KommentarListItemInVorgangComponent', () => {
}); });
}); });
describe('onDocumentClick', () => { describe('edit', () => {
const clickedInsideSpy = jest.spyOn( beforeEach(() => {
KommentarListItemInVorgangComponent.prototype, kommentarService.getKommentarStateResource.mockReturnValue(of(createStateResource(createDummyResource())));
'clickedInside',
);
const clickedNotOnBinaryFileSpy = jest.spyOn(
KommentarListItemInVorgangComponent.prototype,
'clickedNotOnBinaryFile',
);
it('should activate editMode when clicked inside of component and not on binary File', () => {
clickedNotOnBinaryFileSpy.mockReturnValue(true);
clickedInsideSpy.mockReturnValue(true);
component.onDocumentClick(clickEvent);
expect(component.editMode).toEqual(true);
}); });
it('should deactivate editMode when clicked outside but not on binary file', () => { const kommentar: KommentarResource = createKommentarResource();
clickedNotOnBinaryFileSpy.mockReturnValue(true);
clickedInsideSpy.mockReturnValue(false);
component.onDocumentClick(clickEvent); it('should change editMode', () => {
component.kommentar = createKommentarResource([KommentarLinkRel.EDIT]);
expect(component.editMode).toEqual(false); component.edit();
expect(component.editMode).toBeTruthy();
}); });
it('should not change editmode when clicked inside of a binary file', () => { it('should NOT change editMode', () => {
component.editMode = false; component.kommentar = kommentar;
clickedNotOnBinaryFileSpy.mockReturnValue(false);
clickedInsideSpy.mockReturnValue(true);
component.onDocumentClick(clickEvent); component.edit();
expect(component.editMode).toEqual(false); expect(component.editMode).toBeFalsy();
});
}); });
describe('edit', () => { it('should set currently edited kommetar uri', () => {
beforeEach(() => { component.kommentar = kommentar;
kommentarService.getKommentarStateResource.mockReturnValue(
of(createStateResource(createDummyResource())),
);
});
it('should call kommentar service hideFormular', () => {
component.edit(); component.edit();
expect(kommentarService.hideNewKommentarFormular).toHaveBeenCalled(); expect(kommentarService.setCurrentlyEdited).toHaveBeenCalledWith(getUrl(kommentar));
}); });
it('should call kommentar service selectKommentar', () => { it('should call kommentar service selectKommentar', () => {
......
...@@ -22,15 +22,10 @@ ...@@ -22,15 +22,10 @@
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { BinaryFileListResource } from '@alfa-client/binary-file-shared'; import { BinaryFileListResource } from '@alfa-client/binary-file-shared';
import { import { KommentarLinkRel, KommentarListResource, KommentarResource, KommentarService } from '@alfa-client/kommentar-shared';
KommentarLinkRel, import { createEmptyStateResource, StateResource } from '@alfa-client/tech-shared';
KommentarListResource, import { Component, inject, Input, OnInit } from '@angular/core';
KommentarResource, import { getUrl, hasLink, ResourceUri } from '@ngxp/rest';
KommentarService,
} from '@alfa-client/kommentar-shared';
import { StateResource, createEmptyStateResource } from '@alfa-client/tech-shared';
import { Component, ElementRef, HostListener, Input, OnInit } from '@angular/core';
import { isNil } from 'lodash-es';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
@Component({ @Component({
...@@ -39,51 +34,29 @@ import { Observable, of } from 'rxjs'; ...@@ -39,51 +34,29 @@ import { Observable, of } from 'rxjs';
styleUrls: ['./kommentar-list-item-in-vorgang.component.scss'], styleUrls: ['./kommentar-list-item-in-vorgang.component.scss'],
}) })
export class KommentarListItemInVorgangComponent implements OnInit { export class KommentarListItemInVorgangComponent implements OnInit {
public kommentarService = inject(KommentarService);
@Input() public kommentar: KommentarResource; @Input() public kommentar: KommentarResource;
@Input() public kommentarListStateResource: StateResource<KommentarListResource>; @Input() public kommentarListStateResource: StateResource<KommentarListResource>;
@Input() set currentlyEdited(value: ResourceUri) {
this.editMode &&= value === getUrl(this.kommentar);
}
public editMode: boolean = false; public editMode: boolean = false;
public kommentarStateResource$: Observable<StateResource<KommentarResource>>; public kommentarStateResource$: Observable<StateResource<KommentarResource>>;
public attachments$: Observable<StateResource<BinaryFileListResource>> = of(createEmptyStateResource<BinaryFileListResource>());
public attachments$: Observable<StateResource<BinaryFileListResource>> = of( public readonly KommentarLinkRel = KommentarLinkRel;
createEmptyStateResource<BinaryFileListResource>(),
);
public readonly kommentarLinkRel = KommentarLinkRel;
constructor(
public kommentarService: KommentarService,
private elementRef: ElementRef,
) {}
ngOnInit(): void { ngOnInit(): void {
this.attachments$ = this.kommentarService.getAttachments(this.kommentar); this.attachments$ = this.kommentarService.getAttachments(this.kommentar);
} }
@HostListener('document:click', ['$event'])
onDocumentClick(event: MouseEvent): void {
if (this.clickedNotOnBinaryFile(<HTMLElement>event.target)) {
this.editMode = this.clickedInside(event);
}
}
clickedNotOnBinaryFile(element: HTMLElement): boolean {
if (isNil(element)) {
return true;
}
if (element.tagName === 'ALFA-BINARY-FILE') {
return false;
}
return this.clickedNotOnBinaryFile(element.parentElement);
}
clickedInside(event: MouseEvent) {
return this.elementRef.nativeElement.contains(event.target);
}
edit(): void { edit(): void {
this.kommentarService.hideNewKommentarFormular();
this.kommentarService.selectKommentar(this.kommentar);
this.kommentarStateResource$ = this.kommentarService.getKommentarStateResource(); this.kommentarStateResource$ = this.kommentarService.getKommentarStateResource();
this.kommentarService.selectKommentar(this.kommentar);
this.kommentarService.setCurrentlyEdited(getUrl(this.kommentar));
this.editMode = hasLink(this.kommentar, KommentarLinkRel.EDIT);
} }
} }
...@@ -4,7 +4,7 @@ import { ResourceRepository } from '../resource/resource.repository'; ...@@ -4,7 +4,7 @@ import { ResourceRepository } from '../resource/resource.repository';
import { SingleResourceLoadActions } from './actions'; import { SingleResourceLoadActions } from './actions';
import { ResourceEffects } from './resource.effects'; import { ResourceEffects } from './resource.effects';
@Injectable() @Injectable({ providedIn: 'root' })
export class EffectService { export class EffectService {
constructor( constructor(
private actions$: Actions, private actions$: Actions,
......
...@@ -9,7 +9,7 @@ import { EffectService } from './effects.service'; ...@@ -9,7 +9,7 @@ import { EffectService } from './effects.service';
import * as ResourceSelectors from './selector'; import * as ResourceSelectors from './selector';
@Injectable() @Injectable({ providedIn: 'root' })
export class StateService { export class StateService {
constructor( constructor(
private store: Store, private store: Store,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment