import { Injectable } from '@angular/core'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect, spy } from 'chai'; import { DashboardTabActionsService } from './dashboard-tab-actions.service'; @Injectable({ providedIn: 'root' }) @DescribeAngularService(DashboardTabActionsService, { imports: [GCMockModule] }) export class DashboardTabActionsServiceSpec implements Spec { @TestCase('should exist') testShouldExist (service: DashboardTabActionsService) { expect(service).to.exist; } @TestCase('should edit if modal was confirmed') async testShouldEditIfModalConfirmed ( service: DashboardTabActionsService ) { service['dashboardsService'].setEditing(false, null); service['modalFactory'].open = ( arg1: any, arg2: any, arg3: any ) => { return Promise.resolve(true) as any; }; await service.openManageWidgetModal(1); expect(service['dashboardsService'].get('editingDashId')) .to.equal(1); expect(service['dashboardsService'].get('editing')) .to.be.true; } @TestCase('should not edit if modal was cancelled') async testShouldEditIfModalNotConfirmed ( service: DashboardTabActionsService ) { service['dashboardsService'].setEditing(false, null); service['modalFactory'].open = () => { return Promise.resolve(false) as any; }; await service.openManageWidgetModal(1); expect(service['dashboardsService'].get('editingDashId')) .to.be.null; expect(service['dashboardsService'].get('editing')) .to.be.false; } @TestCase('should be able to publish standard dashboard') async testPublishingStandardDashboard ( service: DashboardTabActionsService ) { service['standardProductConfigService']['handlePublishStandardComponents'] = async () => { return null; }; service['dashboardsService']['resetMyDashboards'] = async () => { return null; }; const handlePublishSpy = spy.on(service['standardProductConfigService'], 'handlePublishStandardComponents', (a) => a); const resetMyDashboardsSpy = spy.on(service['dashboardsService'], 'resetMyDashboards', (a) => a); await service.publishStandardDB(1); expect(handlePublishSpy).to.have.been.called(); expect(resetMyDashboardsSpy).at.have.been.called(); } @TestCase('should be able to unpublish standard dashboards') async testUnpublishingStandardDashboards ( service: DashboardTabActionsService ) { service['standardProductConfigService']['handlePublishStandardComponents'] = async () => { return null; }; service['dashboardsService']['resetMyDashboards'] = async () => { return null; }; const handleUnpublishSpy = spy.on(service['standardProductConfigService'], 'handleUnpublishStandardComponents', (a) => a); const resetMyDashboardsSpy = spy.on(service['dashboardsService'], 'resetMyDashboards', (a) => a); await service.unpublishStandardProductDB(1); expect(handleUnpublishSpy).to.have.been.called(); expect(resetMyDashboardsSpy).at.have.been.called(); } }