[AAE-6309] Cleaning process references (#2360)

* [AAE-6309] Cleaning process references

* [AAE-6309] Added test for disabled button
This commit is contained in:
Bartosz Sekuła
2021-11-25 13:31:38 +01:00
committed by GitHub
parent 60446dc36e
commit 0a8a3895a1
6 changed files with 29 additions and 13 deletions
@@ -59,7 +59,7 @@ describe('CreateMenuComponent', () => {
])
);
spyOn(extensionService, 'getMainAction').and.returnValue(getContentActionRef());
spyOn(extensionService, 'getMainAction').and.returnValue(of(getContentActionRef()));
fixture = TestBed.createComponent(CreateMenuComponent);
});
@@ -3,6 +3,8 @@
<button
*ngSwitchCase="actionTypes.button"
mat-stroked-button
[id]="action.id"
[disabled]="action.disabled"
(click)="runAction(action.actions.click)"
class="app-main-action-button"
>
@@ -28,14 +28,14 @@ import { MainActionComponent } from './main-action.component';
import { TranslationService, TranslationMock } from '@alfresco/adf-core';
import { AppExtensionService } from '@alfresco/aca-shared';
import { of } from 'rxjs';
import { ACTION_CLICK, ACTION_TITLE } from '../../testing/content-action-ref';
import { ACTION_CLICK, ACTION_TITLE, getContentActionRef } from '../../testing/content-action-ref';
import { AppExtensionServiceMock } from '../../testing/app-extension-service-mock';
import { CommonModule } from '@angular/common';
import { MatButtonModule } from '@angular/material/button';
import { TranslateModule } from '@ngx-translate/core';
describe('MainActionComponent', () => {
let startProcessButtonComponent: MainActionComponent;
let mainActionComponent: MainActionComponent;
let fixture: ComponentFixture<MainActionComponent>;
let appExtensionService: AppExtensionServiceMock;
@@ -51,7 +51,7 @@ describe('MainActionComponent', () => {
appExtensionService = TestBed.inject(AppExtensionService);
fixture = TestBed.createComponent(MainActionComponent);
startProcessButtonComponent = fixture.componentInstance;
mainActionComponent = fixture.componentInstance;
fixture.detectChanges();
});
@@ -64,7 +64,7 @@ describe('MainActionComponent', () => {
it('should not display button if main action is not configured', () => {
spyOn(appExtensionService, 'getMainAction').and.returnValue(of(undefined));
startProcessButtonComponent.ngOnInit();
mainActionComponent.ngOnInit();
fixture.detectChanges();
const button = fixture.debugElement.nativeElement.querySelector('.app-main-action-button');
@@ -79,4 +79,20 @@ describe('MainActionComponent', () => {
expect(runExtensionActionSpy).toHaveBeenCalledWith(ACTION_CLICK);
});
it('should not call button if main action is disabled', () => {
const disabledMainActionRef = getContentActionRef();
disabledMainActionRef.disabled = true;
spyOn(appExtensionService, 'getMainAction').and.returnValue(of(disabledMainActionRef));
const runAction = spyOn(mainActionComponent, 'runAction');
mainActionComponent.ngOnInit();
fixture.detectChanges();
const button = fixture.debugElement.nativeElement.querySelector(`#${disabledMainActionRef.id}`);
button.click();
expect(runAction).not.toHaveBeenCalled();
});
});
@@ -29,8 +29,6 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
export const START_PROCESS_ACTION_ID = 'alfresco.app.start.process';
@Component({
selector: 'app-main-action',
templateUrl: './main-action.component.html',
@@ -24,11 +24,11 @@
*/
import { ContentActionRef } from '@alfresco/adf-extensions';
import { Observable } from 'rxjs';
import { Observable, of } from 'rxjs';
import { getContentActionRef } from './content-action-ref';
export class AppExtensionServiceMock {
getMainAction(): Observable<ContentActionRef> {
return getContentActionRef();
return of(getContentActionRef());
}
runActionById(_id: string) {}
+4 -4
View File
@@ -24,18 +24,18 @@
*/
import { ContentActionRef, ContentActionType } from '@alfresco/adf-extensions';
import { Observable, of } from 'rxjs';
export const ACTION_TITLE = 'ACTION_TITLE';
export const ACTION_CLICK = 'ACTION_CLICK';
export const getContentActionRef = (): Observable<ContentActionRef> => {
return of({
export const getContentActionRef = (): ContentActionRef => {
return {
id: 'id',
type: ContentActionType.button,
title: ACTION_TITLE,
disabled: false,
actions: {
click: ACTION_CLICK
}
});
};
};