mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
add "create menu" unit tests (#1720)
* add "create menu" unit tests * submenu tests
This commit is contained in:
@@ -1,19 +1,12 @@
|
|||||||
<ng-container [ngSwitch]="actionRef.type">
|
<ng-container [ngSwitch]="actionRef.type">
|
||||||
<ng-container *ngSwitchCase="'menu'">
|
<ng-container *ngSwitchCase="'menu'">
|
||||||
<button
|
<button [id]="actionRef.id" mat-menu-item role="menuitem" [disabled]="actionRef.disabled" [matMenuTriggerFor]="childMenu">
|
||||||
mat-menu-item
|
|
||||||
role="menuitem"
|
|
||||||
[disabled]="actionRef.disabled"
|
|
||||||
[matMenuTriggerFor]="childMenu"
|
|
||||||
>
|
|
||||||
<adf-icon [value]="actionRef.icon"></adf-icon>
|
<adf-icon [value]="actionRef.icon"></adf-icon>
|
||||||
<span>{{ actionRef.title | translate }}</span>
|
<span data-automation-id="menu-item-title">{{ actionRef.title | translate }}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<mat-menu #childMenu="matMenu" class="app-create-menu__sub-menu">
|
<mat-menu #childMenu="matMenu" class="app-create-menu__sub-menu">
|
||||||
<ng-container
|
<ng-container *ngFor="let child of actionRef.children; trackBy: trackById">
|
||||||
*ngFor="let child of actionRef.children; trackBy: trackById"
|
|
||||||
>
|
|
||||||
<app-toolbar-menu-item [actionRef]="child"></app-toolbar-menu-item>
|
<app-toolbar-menu-item [actionRef]="child"></app-toolbar-menu-item>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</mat-menu>
|
</mat-menu>
|
||||||
@@ -32,18 +25,13 @@
|
|||||||
[id]="actionRef.id"
|
[id]="actionRef.id"
|
||||||
role="menuItem"
|
role="menuItem"
|
||||||
mat-menu-item
|
mat-menu-item
|
||||||
[role]="'menuItem'"
|
[role]="'menuitem'"
|
||||||
color="primary"
|
|
||||||
[disabled]="actionRef.disabled"
|
[disabled]="actionRef.disabled"
|
||||||
[attr.title]="
|
[attr.title]="(actionRef.disabled ? actionRef['description-disabled'] : actionRef.description || actionRef.title) | translate"
|
||||||
(actionRef.disabled
|
|
||||||
? actionRef['description-disabled']
|
|
||||||
: actionRef.description || actionRef.title) | translate
|
|
||||||
"
|
|
||||||
(click)="runAction()"
|
(click)="runAction()"
|
||||||
>
|
>
|
||||||
<adf-icon [value]="actionRef.icon"></adf-icon>
|
<adf-icon [value]="actionRef.icon"></adf-icon>
|
||||||
<span>{{ actionRef.title | translate }}</span>
|
<span data-automation-id="menu-item-title">{{ actionRef.title | translate }}</span>
|
||||||
</button>
|
</button>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
@@ -24,9 +24,107 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { CreateMenuComponent } from './create-menu.component';
|
import { CreateMenuComponent } from './create-menu.component';
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { CoreModule } from '@alfresco/adf-core';
|
||||||
|
import { AppCreateMenuModule } from './create-menu.module';
|
||||||
|
import { OverlayContainer, OverlayModule } from '@angular/cdk/overlay';
|
||||||
|
import { AppExtensionService } from '@alfresco/aca-shared';
|
||||||
|
import { ContentActionType } from '@alfresco/adf-extensions';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||||
|
import { MatMenuModule } from '@angular/material/menu';
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
|
||||||
describe('CreateMenuComponent', () => {
|
describe('CreateMenuComponent', () => {
|
||||||
it('should be defined', () => {
|
let fixture: ComponentFixture<CreateMenuComponent>;
|
||||||
expect(CreateMenuComponent).toBeDefined();
|
let extensionService: AppExtensionService;
|
||||||
|
let getCreateActionsSpy: jasmine.Spy;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [AppTestingModule, CoreModule.forRoot(), AppCreateMenuModule, OverlayModule, MatMenuModule, MatButtonModule]
|
||||||
|
});
|
||||||
|
|
||||||
|
extensionService = TestBed.inject(AppExtensionService);
|
||||||
|
getCreateActionsSpy = spyOn(extensionService, 'getCreateActions');
|
||||||
|
getCreateActionsSpy.and.returnValue([
|
||||||
|
{
|
||||||
|
id: 'action1',
|
||||||
|
type: ContentActionType.button,
|
||||||
|
title: 'action one'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(CreateMenuComponent);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function clickMenu() {
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
const button: HTMLButtonElement = fixture.debugElement.query(By.css('[data-automation-id="create-button"]')).nativeElement;
|
||||||
|
button.click();
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
}
|
||||||
|
|
||||||
|
it('should render collapsed button', async () => {
|
||||||
|
fixture.componentInstance.expanded = false;
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
const button: HTMLButtonElement = fixture.debugElement.query(By.css('[data-automation-id="create-button"]')).nativeElement;
|
||||||
|
const isCollapsed = button.classList.contains('app-create-menu--collapsed');
|
||||||
|
|
||||||
|
expect(isCollapsed).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render expanded button', async () => {
|
||||||
|
fixture.componentInstance.expanded = true;
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
const button: HTMLButtonElement = fixture.debugElement.query(By.css('[data-automation-id="create-button"]')).nativeElement;
|
||||||
|
const isCollapsed = button.classList.contains('app-create-menu--collapsed');
|
||||||
|
|
||||||
|
expect(isCollapsed).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render custom actions', async () => {
|
||||||
|
await clickMenu();
|
||||||
|
|
||||||
|
const menuItems = fixture.debugElement.queryAll(By.css('.app-toolbar-menu-item'));
|
||||||
|
expect(menuItems.length).toBe(1);
|
||||||
|
|
||||||
|
const label: HTMLSpanElement = (menuItems[0].nativeElement as HTMLButtonElement).querySelector('[data-automation-id="menu-item-title"]');
|
||||||
|
expect(label.innerText).toBe('action one');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render sub-menus', async () => {
|
||||||
|
getCreateActionsSpy.and.returnValue([
|
||||||
|
{
|
||||||
|
id: 'level1',
|
||||||
|
type: ContentActionType.menu,
|
||||||
|
title: 'level one',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: 'level2',
|
||||||
|
type: ContentActionType.button,
|
||||||
|
title: 'level two'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
await clickMenu();
|
||||||
|
|
||||||
|
const level1 = fixture.debugElement.query(By.css('#level1')).nativeElement as HTMLButtonElement;
|
||||||
|
level1.click();
|
||||||
|
|
||||||
|
const overlayContainer = TestBed.inject(OverlayContainer);
|
||||||
|
const level2 = overlayContainer.getContainerElement().querySelector('#level2');
|
||||||
|
|
||||||
|
expect(level2).not.toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user