[ACS-4865] setup and enable code coverage for all projects (#3074)

This commit is contained in:
Denys Vuika
2023-03-20 09:06:19 -04:00
committed by GitHub
parent 86c0bbb998
commit 9609393d1e
37 changed files with 1300 additions and 408 deletions

View File

@@ -143,12 +143,14 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
}
imageResolver(row: ShareDataRow): string | null {
if (isLocked(row.node)) {
return 'assets/images/baseline-lock-24px.svg';
}
if (row) {
if (isLocked(row.node)) {
return 'assets/images/baseline-lock-24px.svg';
}
if (isLibrary(row.node)) {
return 'assets/images/baseline-library_books-24px.svg';
if (isLibrary(row.node)) {
return 'assets/images/baseline-library_books-24px.svg';
}
}
return null;
@@ -181,7 +183,7 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
return location.href.includes('viewer:view');
}
onSortingChanged(event) {
onSortingChanged(event: any) {
this.filterSorting = event.detail.key + '-' + event.detail.direction;
}

View File

@@ -38,6 +38,7 @@ import { HttpClientModule } from '@angular/common/http';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { EffectsModule } from '@ngrx/effects';
import { Subscription } from 'rxjs';
export const INITIAL_APP_STATE: AppState = {
appName: 'Alfresco Content Application',
@@ -98,6 +99,14 @@ class TestComponent extends PageComponent {
constructor(store: Store<AppStore>, extensions: AppExtensionService, content: DocumentBasePageService) {
super(store, extensions, content);
}
addSubscription(entry: Subscription) {
this.subscriptions.push(entry);
}
getSubscriptions(): Subscription[] {
return this.subscriptions;
}
}
describe('PageComponent', () => {
@@ -341,4 +350,66 @@ describe('Info Drawer state', () => {
}
});
});
it('should not resolve custom image', () => {
expect(component.imageResolver(null)).toBe(null);
});
it('should resolve custom image for locked node', () => {
const row: any = {
node: {
entry: {
isLocked: true
}
}
};
expect(component.imageResolver(row)).toBe('assets/images/baseline-lock-24px.svg');
});
it('should resolve custom image for a library', () => {
const row: any = {
node: {
entry: {
nodeType: 'st:site'
}
}
};
expect(component.imageResolver(row)).toBe('assets/images/baseline-library_books-24px.svg');
});
it('should track elements by action id ', () => {
const action: any = { id: 'action1' };
expect(component.trackByActionId(0, action)).toBe('action1');
});
it('should track elements by id ', () => {
const action: any = { id: 'action1' };
expect(component.trackById(0, action)).toBe('action1');
});
it('should track elements by column id ', () => {
const action: any = { id: 'action1' };
expect(component.trackByColumnId(0, action)).toBe('action1');
});
it('should cleanup subscriptions on destroy', () => {
const sub = jasmine.createSpyObj('sub', ['unsubscribe']);
expect(component.getSubscriptions().length).toBe(0);
component.addSubscription(sub);
expect(component.getSubscriptions().length).toBe(1);
component.ngOnDestroy();
expect(sub.unsubscribe).toHaveBeenCalled();
expect(component.getSubscriptions().length).toBe(0);
});
it('should update filter sorting', () => {
const event = new CustomEvent('sorting-changed', { detail: { key: 'name', direction: 'asc' } });
component.onSortingChanged(event);
expect(component.filterSorting).toBe('name-asc');
});
});

View File

@@ -0,0 +1,43 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { LockedByComponent } from './locked-by.component';
describe('LockedByComponent', () => {
it('should evaluate label text', () => {
const component = new LockedByComponent();
component.node = {
entry: {
properties: {
'cm:lockOwner': {
displayName: 'owner-name'
}
}
} as any
};
expect(component.text).toBe('owner-name');
});
});

View File

@@ -45,8 +45,6 @@ export class LockedByComponent {
node: NodeEntry;
get text(): string {
return (
this.node && this.node.entry.properties && this.node.entry.properties['cm:lockOwner'] && this.node.entry.properties['cm:lockOwner'].displayName
);
return this.node?.entry?.properties?.['cm:lockOwner']?.displayName;
}
}

View File

@@ -5,6 +5,9 @@ import { OpenInAppComponent } from './open-in-app.component';
import { initialState, LibTestingModule } from '../../testing/lib-testing-module';
import { provideMockStore } from '@ngrx/store/testing';
import { TranslateModule } from '@ngx-translate/core';
import { MatIconTestingModule } from '@angular/material/icon/testing';
import { MatIconModule } from '@angular/material/icon';
import { SharedModule } from '@alfresco/aca-shared';
describe('OpenInAppComponent', () => {
let fixture: ComponentFixture<OpenInAppComponent>;
@@ -15,16 +18,15 @@ describe('OpenInAppComponent', () => {
open: jasmine.createSpy('open')
};
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [OpenInAppComponent],
imports: [LibTestingModule, TranslateModule],
beforeEach(() => {
TestBed.configureTestingModule({
imports: [LibTestingModule, TranslateModule, SharedModule.forRoot(), MatIconModule, MatIconTestingModule],
providers: [
provideMockStore({ initialState }),
{ provide: MAT_DIALOG_DATA, useValue: { redirectUrl: 'mockRedirectUrl' } },
{ provide: MatDialogRef, useValue: mockDialogRef }
]
}).compileComponents();
});
fixture = TestBed.createComponent(OpenInAppComponent);
component = fixture.componentInstance;

View File

@@ -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();
});
});

View File

@@ -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();
});
});

View File

@@ -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');
});
});

View File

@@ -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');
});
});