mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
[ACA] Context menu - support nested sub menus (#715)
* remove ContextMenuItemDirective * remove custom menu animation * remove custom menu styling * menu item component * material menu trigger * clean up menu theme * update context menu module * remoe context menu from libraries document list * clean up * clean up * tests
This commit is contained in:
committed by
Denys Vuika
parent
9dcdacce40
commit
4802656d79
@@ -23,10 +23,104 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {
|
||||
TestBed,
|
||||
ComponentFixture,
|
||||
fakeAsync,
|
||||
tick
|
||||
} from '@angular/core/testing';
|
||||
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||
import { AppExtensionService } from '../../extensions/extension.service';
|
||||
import { ContextMenuComponent } from './context-menu.component';
|
||||
import { ContextMenuModule } from './context-menu.module';
|
||||
import { ContextMenuOverlayRef } from './context-menu-overlay';
|
||||
import {
|
||||
TranslateModule,
|
||||
TranslateLoader,
|
||||
TranslateFakeLoader
|
||||
} from '@ngx-translate/core';
|
||||
|
||||
import { of } from 'rxjs';
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
describe('ContextMenuComponent', () => {
|
||||
it('should be defined', () => {
|
||||
expect(ContextMenuComponent).toBeDefined();
|
||||
let fixture: ComponentFixture<ContextMenuComponent>;
|
||||
let component: ContextMenuComponent;
|
||||
let contextMenuOverlayRef;
|
||||
let extensionsService;
|
||||
const contextItem = {
|
||||
type: 'button',
|
||||
id: 'action-button',
|
||||
title: 'Test Button',
|
||||
actions: {
|
||||
click: 'TEST_EVENT'
|
||||
}
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppTestingModule,
|
||||
ContextMenuModule,
|
||||
TranslateModule.forRoot({
|
||||
loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
|
||||
})
|
||||
],
|
||||
providers: [
|
||||
AppExtensionService,
|
||||
{
|
||||
provide: ContextMenuOverlayRef,
|
||||
useValue: {
|
||||
close: jasmine.createSpy('close')
|
||||
}
|
||||
},
|
||||
{
|
||||
provide: Store,
|
||||
useValue: {
|
||||
dispatch: () => {},
|
||||
select: () => of({ count: 1 })
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(ContextMenuComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
contextMenuOverlayRef = TestBed.get(ContextMenuOverlayRef);
|
||||
extensionsService = TestBed.get(AppExtensionService);
|
||||
|
||||
spyOn(extensionsService, 'getAllowedContextMenuActions').and.returnValue([
|
||||
contextItem
|
||||
]);
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should close context menu on Escape event', () => {
|
||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
|
||||
expect(contextMenuOverlayRef.close).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should render defined context menu actions items', fakeAsync(() => {
|
||||
component.ngAfterViewInit();
|
||||
tick(500);
|
||||
|
||||
const contextMenuElements = document.body
|
||||
.querySelector('.aca-context-menu')
|
||||
.querySelectorAll('button');
|
||||
|
||||
expect(contextMenuElements.length).toBe(1);
|
||||
expect(contextMenuElements[0].innerText).toBe(contextItem.title);
|
||||
}));
|
||||
|
||||
it('should run action with provided action id', fakeAsync(() => {
|
||||
spyOn(extensionsService, 'runActionById');
|
||||
|
||||
component.runAction(contextItem.actions.click);
|
||||
|
||||
expect(extensionsService.runActionById).toHaveBeenCalledWith(
|
||||
contextItem.actions.click
|
||||
);
|
||||
}));
|
||||
});
|
||||
|
Reference in New Issue
Block a user