[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

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