Fix tests pt. 1

This commit is contained in:
Yury Bondarenko
2025-02-07 17:57:42 +01:00
parent fbffcca945
commit 3fecbc245b
8 changed files with 77 additions and 105 deletions

View File

@@ -54,6 +54,7 @@ const mockMenuID = 'mock-menuID' as MenuID;
// eslint-disable-next-line @angular-eslint/component-selector
selector: '',
template: '',
standalone: true,
})
@rendersSectionForMenu(mockMenuID, true)
class TestExpandableMenuComponent {
@@ -63,6 +64,7 @@ class TestExpandableMenuComponent {
// eslint-disable-next-line @angular-eslint/component-selector
selector: '',
template: '',
standalone: true,
})
@rendersSectionForMenu(mockMenuID, false)
class TestMenuComponent {
@@ -85,8 +87,6 @@ describe('MenuComponent', () => {
visible: true,
};
const mockMenuID = 'mock-menuID' as MenuID;
const mockStatisticSection = { 'id': 'statistics_site', 'active': true, 'visible': true, 'index': 2, 'type': 'statistics', 'model': { 'type': 1, 'text': 'menu.section.statistics', 'link': 'statistics' } };
let authorizationService: AuthorizationDataService;
@@ -144,7 +144,7 @@ describe('MenuComponent', () => {
});
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), NoopAnimationsModule, RouterTestingModule, MenuComponent, StoreModule.forRoot(authReducer, storeModuleConfig)],
imports: [TranslateModule.forRoot(), NoopAnimationsModule, RouterTestingModule, MenuComponent, StoreModule.forRoot(authReducer, storeModuleConfig), TestExpandableMenuComponent, TestMenuComponent],
providers: [
Injector,
{ provide: ThemeService, useValue: getMockThemeService() },
@@ -152,8 +152,6 @@ describe('MenuComponent', () => {
provideMockStore({ initialState }),
{ provide: AuthorizationDataService, useValue: authorizationService },
{ provide: ActivatedRoute, useValue: routeStub },
TestExpandableMenuComponent,
TestMenuComponent,
],
schemas: [NO_ERRORS_SCHEMA],
}).overrideComponent(MenuComponent, {
@@ -272,35 +270,4 @@ describe('MenuComponent', () => {
expect(menuService.collapseMenuPreview).toHaveBeenCalledWith(comp.menuID);
}));
});
describe('when unauthorized statistics', () => {
beforeEach(() => {
(authorizationService as any).isAuthorized.and.returnValue(observableOf(false));
fixture.detectChanges();
});
it('should return observable of empty object', done => {
comp.getAuthorizedStatistics(mockStatisticSection).subscribe((res) => {
expect(res).toEqual({});
done();
});
});
});
describe('get authorized statistics', () => {
beforeEach(() => {
(authorizationService as any).isAuthorized.and.returnValue(observableOf(true));
fixture.detectChanges();
});
it('should return observable of statistics section menu', done => {
comp.getAuthorizedStatistics(mockStatisticSection).subscribe((res) => {
expect(res).toEqual(mockStatisticSection);
done();
});
});
});
});