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,51 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ToolbarActionComponent } from './toolbar-action.component';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { ToolbarButtonType } from '../toolbar-button/toolbar-button.component';
|
||||
import { ChangeDetectorRef } from '@angular/core';
|
||||
import { ContentActionType } from '@alfresco/adf-extensions';
|
||||
import { IconModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('ToolbarActionComponent', () => {
|
||||
it('should be defined', () => {
|
||||
expect(ToolbarActionComponent).toBeDefined();
|
||||
let fixture: ComponentFixture<ToolbarActionComponent>;
|
||||
let component: ToolbarActionComponent;
|
||||
let changeDetectorRef: ChangeDetectorRef;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CommonModule, HttpClientModule, TranslateModule.forRoot(), IconModule],
|
||||
providers: [{ provide: ChangeDetectorRef, useValue: { markForCheck() {} } }],
|
||||
declarations: [ToolbarActionComponent]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(ToolbarActionComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
changeDetectorRef = TestBed.inject(ChangeDetectorRef);
|
||||
});
|
||||
|
||||
it('should be icon button by default', () => {
|
||||
expect(component.type).toBe(ToolbarButtonType.ICON_BUTTON);
|
||||
});
|
||||
|
||||
it('should force update UI on check for the viewer', () => {
|
||||
component = new ToolbarActionComponent(changeDetectorRef);
|
||||
const markForCheck = spyOn(changeDetectorRef, 'markForCheck');
|
||||
|
||||
component.actionRef = {
|
||||
id: '-app.viewer',
|
||||
type: ContentActionType.button,
|
||||
actions: {
|
||||
click: 'ON_CLICK'
|
||||
}
|
||||
};
|
||||
|
||||
component.ngDoCheck();
|
||||
expect(markForCheck).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
@@ -23,10 +23,69 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { ToolbarButtonComponent } from './toolbar-button.component';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ToolbarButtonComponent, ToolbarButtonType } from './toolbar-button.component';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { IconModule, TranslationMock, TranslationService } from '@alfresco/adf-core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { of } from 'rxjs';
|
||||
import { AppExtensionService } from '../../../services/app.extension.service';
|
||||
import { ContentActionType } from '@alfresco/adf-extensions';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
|
||||
describe('ToolbarButtonComponent', () => {
|
||||
it('should be defined', () => {
|
||||
expect(ToolbarButtonComponent).toBeDefined();
|
||||
let fixture: ComponentFixture<ToolbarButtonComponent>;
|
||||
let component: ToolbarButtonComponent;
|
||||
let appExtensionService: AppExtensionService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CommonModule, HttpClientModule, TranslateModule.forRoot(), IconModule, MatButtonModule],
|
||||
declarations: [ToolbarButtonComponent],
|
||||
providers: [
|
||||
{ provide: TranslationService, useClass: TranslationMock },
|
||||
{ provide: AppExtensionService, useValue: { runActionById() {} } },
|
||||
{
|
||||
provide: Store,
|
||||
useValue: {
|
||||
dispatch: () => {},
|
||||
select: () => of({ count: 1 })
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(ToolbarButtonComponent);
|
||||
component = fixture.componentInstance;
|
||||
appExtensionService = TestBed.inject(AppExtensionService);
|
||||
});
|
||||
|
||||
it('should be icon button by default', () => {
|
||||
expect(component.type).toBe(ToolbarButtonType.ICON_BUTTON);
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
@@ -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');
|
||||
});
|
||||
});
|
||||
|
@@ -28,7 +28,8 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MaterialModule } from '@alfresco/adf-core';
|
||||
import { OverlayModule } from '@angular/cdk/overlay';
|
||||
import { TranslateModule, TranslateLoader, TranslateFakeLoader } from '@ngx-translate/core';
|
||||
import { ContentActionRef } from '@alfresco/adf-extensions';
|
||||
import { ContentActionRef, ContentActionType } from '@alfresco/adf-extensions';
|
||||
import { QueryList } from '@angular/core';
|
||||
|
||||
describe('ToolbarMenuComponent', () => {
|
||||
let fixture: ComponentFixture<ToolbarMenuComponent>;
|
||||
@@ -50,6 +51,7 @@ describe('ToolbarMenuComponent', () => {
|
||||
component = fixture.componentInstance;
|
||||
component.matTrigger = jasmine.createSpyObj('MatMenuTrigger', ['closeMenu']);
|
||||
component.actionRef = actions;
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
@@ -59,4 +61,23 @@ describe('ToolbarMenuComponent', () => {
|
||||
fixture.detectChanges();
|
||||
expect(component.matTrigger.closeMenu).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should populate underlying menu with toolbar items', () => {
|
||||
component.toolbarMenuItems = new QueryList();
|
||||
component.toolbarMenuItems.reset([{ menuItem: {} } as any]);
|
||||
expect(component.toolbarMenuItems.length).toBe(1);
|
||||
|
||||
expect(component.menu._allItems.length).toBe(0);
|
||||
component.ngAfterViewInit();
|
||||
expect(component.menu._allItems.length).toBe(1);
|
||||
});
|
||||
|
||||
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