mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
[ACS-4865] setup and enable code coverage for all projects (#3074)
This commit is contained in:
@@ -23,10 +23,98 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ToolbarMenuItemComponent } from './toolbar-menu-item.component';
|
||||
import { AppExtensionService } from '../../../services/app.extension.service';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { IconModule, TranslationMock, TranslationService } from '@alfresco/adf-core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { of } from 'rxjs';
|
||||
import { ContentActionRef, ContentActionType } from '@alfresco/adf-extensions';
|
||||
|
||||
describe('ToolbarMenuItemComponent', () => {
|
||||
it('should be defined', () => {
|
||||
expect(ToolbarMenuItemComponent).toBeDefined();
|
||||
let fixture: ComponentFixture<ToolbarMenuItemComponent>;
|
||||
let component: ToolbarMenuItemComponent;
|
||||
let appExtensionService: AppExtensionService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CommonModule, HttpClientModule, TranslateModule.forRoot(), IconModule, MatButtonModule],
|
||||
declarations: [ToolbarMenuItemComponent],
|
||||
providers: [
|
||||
{ provide: TranslationService, useClass: TranslationMock },
|
||||
{ provide: AppExtensionService, useValue: { runActionById() {} } },
|
||||
{
|
||||
provide: Store,
|
||||
useValue: {
|
||||
dispatch: () => {},
|
||||
select: () => of({ count: 1 })
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(ToolbarMenuItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
appExtensionService = TestBed.inject(AppExtensionService);
|
||||
});
|
||||
|
||||
it('should run action on click', async () => {
|
||||
const runActionById = spyOn(appExtensionService, 'runActionById');
|
||||
|
||||
component.actionRef = {
|
||||
id: 'button1',
|
||||
type: ContentActionType.button,
|
||||
actions: {
|
||||
click: 'ON_CLICK'
|
||||
}
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const button: HTMLButtonElement = fixture.nativeElement.querySelector('[id="button1"]');
|
||||
button.click();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(runActionById).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should run action with focus selector on click', async () => {
|
||||
const runActionById = spyOn(appExtensionService, 'runActionById');
|
||||
|
||||
component.menuId = 'menu1';
|
||||
component.actionRef = {
|
||||
id: 'button1',
|
||||
type: ContentActionType.button,
|
||||
actions: {
|
||||
click: 'ON_CLICK'
|
||||
}
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const button: HTMLButtonElement = fixture.nativeElement.querySelector('[id="button1"]');
|
||||
button.click();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(runActionById).toHaveBeenCalledWith('ON_CLICK', { focusedElementOnCloseSelector: '#menu1' });
|
||||
});
|
||||
|
||||
it('should track elements by content action id', () => {
|
||||
const contentActionRef: ContentActionRef = {
|
||||
id: 'action1',
|
||||
type: ContentActionType.button
|
||||
};
|
||||
|
||||
expect(component.trackByActionId(0, contentActionRef)).toBe('action1');
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user