Skip to content

Commit

Permalink
chore: fix errors in ASM lib unit tests (CXSPA-5164) (#18037)
Browse files Browse the repository at this point in the history
Co-authored-by: Hakwoo Kim <[email protected]>
  • Loading branch information
kimhw0630 and hakwookim authored Oct 30, 2023
1 parent 24f6312 commit 8190e95
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Pipe, PipeTransform } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { LaunchDialogService } from '@spartacus/storefront';
import { FocusDirective, LaunchDialogService } from '@spartacus/storefront';
import {
AsmBindCartDialogComponent,
BIND_CART_DIALOG_ACTION,
Expand All @@ -26,7 +26,11 @@ describe('AsmBindCartDialogComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AsmBindCartDialogComponent, MockTranslatePipe],
declarations: [
AsmBindCartDialogComponent,
MockTranslatePipe,
FocusDirective,
],
providers: [
{ provide: LaunchDialogService, useClass: MockLaunchDialogService },
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Pipe, PipeTransform } from '@angular/core';
import {
Component,
Injectable,
Input,
Pipe,
PipeTransform,
} from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AsmBindCartFacade, CsAgentAuthService } from '@spartacus/asm/root';
Expand All @@ -11,14 +17,19 @@ import { SavedCartFacade } from '@spartacus/cart/saved-cart/root';
import {
AuthService,
FeatureConfigService,
FeaturesConfigModule,
GlobalMessageEntities,
GlobalMessageService,
GlobalMessageType,
OCC_CART_ID_CURRENT,
RoutingService,
Translatable,
} from '@spartacus/core';
import { LaunchDialogService, LAUNCH_CALLER } from '@spartacus/storefront';
import {
LaunchDialogService,
LAUNCH_CALLER,
ICON_TYPE,
} from '@spartacus/storefront';
import { ProcessesLoaderState } from 'projects/core/src/state/utils/processes-loader';
import {
BehaviorSubject,
Expand All @@ -33,6 +44,16 @@ import { SAVE_CART_DIALOG_ACTION } from '../asm-save-cart-dialog/asm-save-cart-d
import { AsmComponentService } from '../services/asm-component.service';
import { AsmBindCartComponent } from './asm-bind-cart.component';
import createSpy = jasmine.createSpy;
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { DotSpinnerComponent } from '../dot-spinner/dot-spinner.component';

@Component({
selector: 'cx-icon',
template: '',
})
class MockCxIconComponent {
@Input() type: ICON_TYPE;
}

class MockAuthService implements Partial<AuthService> {
isUserLoggedIn(): Observable<boolean> {
Expand Down Expand Up @@ -107,7 +128,7 @@ class MockSavedCartFacade implements Partial<SavedCartFacade> {
return EMPTY;
}
}

@Injectable()
class MockAsmComponentService extends AsmComponentService {
logoutCustomerSupportAgentAndCustomer(): void {}
unload() {}
Expand Down Expand Up @@ -143,7 +164,13 @@ describe('AsmBindCartComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AsmBindCartComponent, MockTranslatePipe],
imports: [FormsModule, ReactiveFormsModule, FeaturesConfigModule],
declarations: [
AsmBindCartComponent,
MockTranslatePipe,
MockCxIconComponent,
DotSpinnerComponent,
],
providers: [
{ provide: AuthService, useClass: MockAuthService },
{ provide: CsAgentAuthService, useClass: MockCsAgentAuthService },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Component,
DebugElement,
EventEmitter,
Injectable,
Input,
Output,
} from '@angular/core';
Expand All @@ -17,12 +18,17 @@ import {
import {
AuthService,
FeatureConfigService,
FeaturesConfigModule,
GlobalMessageService,
I18nTestingModule,
RoutingService,
User,
} from '@spartacus/core';
import { LAUNCH_CALLER, LaunchDialogService } from '@spartacus/storefront';
import {
ICON_TYPE,
LAUNCH_CALLER,
LaunchDialogService,
} from '@spartacus/storefront';
import { UserAccountFacade } from '@spartacus/user/account/root';
import { BehaviorSubject, EMPTY, Observable, of } from 'rxjs';
import { AsmComponentService } from '../services/asm-component.service';
Expand All @@ -34,6 +40,14 @@ class MockAuthService implements Partial<AuthService> {
}
}

@Component({
selector: 'cx-icon',
template: '',
})
class MockCxIconComponent {
@Input() type: ICON_TYPE;
}

class MockCsAgentAuthService implements Partial<CsAgentAuthService> {
authorizeCustomerSupportAgent(): Promise<void> {
return Promise.resolve();
Expand Down Expand Up @@ -125,7 +139,7 @@ class MockGlobalMessageService implements Partial<GlobalMessageService> {
class MockRoutingService implements Partial<RoutingService> {
go = () => Promise.resolve(true);
}

@Injectable()
class MockAsmComponentService extends AsmComponentService {
logoutCustomerSupportAgentAndCustomer(): void {}
unload() {}
Expand Down Expand Up @@ -163,14 +177,15 @@ describe('AsmMainUiComponent', () => {
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [I18nTestingModule],
imports: [I18nTestingModule, FeaturesConfigModule],
declarations: [
AsmMainUiComponent,
MockAsmToggleUiComponent,
MockCSAgentLoginFormComponent,
MockCustomerSelectionComponent,
MockAsmSessionTimerComponent,
MockCustomerEmulationComponent,
MockCxIconComponent,
],
providers: [
{ provide: AuthService, useClass: MockAuthService },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { DebugElement, Pipe, PipeTransform } from '@angular/core';
import {
Component,
DebugElement,
EventEmitter,
Input,
Output,
Pipe,
PipeTransform,
} from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Cart } from '@spartacus/cart/base/root';
import { SavedCartFacade } from '@spartacus/cart/saved-cart/root';
import { LaunchDialogService } from '@spartacus/storefront';
import { FocusDirective, LaunchDialogService } from '@spartacus/storefront';
import { EMPTY, Observable, of } from 'rxjs';
import {
AsmSaveCartDialogComponent,
SAVE_CART_DIALOG_ACTION,
} from './asm-save-cart-dialog.component';
import { GlobalMessageType } from '@spartacus/core';

@Pipe({
name: 'cxTranslate',
Expand All @@ -35,6 +44,16 @@ class MockLaunchDialogService implements Partial<LaunchDialogService> {
closeDialog(_reason: any) {}
}

@Component({
selector: 'cx-message',
template: '',
})
class MockCxMessageComponent {
@Input() text: string;
@Input() type: GlobalMessageType;
@Output() closeMessage = new EventEmitter();
}

describe('AsmBindCartDialogComponent', () => {
let component: AsmSaveCartDialogComponent;
let fixture: ComponentFixture<AsmSaveCartDialogComponent>;
Expand All @@ -44,7 +63,12 @@ describe('AsmBindCartDialogComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AsmSaveCartDialogComponent, MockTranslatePipe],
declarations: [
AsmSaveCartDialogComponent,
MockTranslatePipe,
FocusDirective,
MockCxMessageComponent,
],
providers: [
{ provide: LaunchDialogService, useClass: MockLaunchDialogService },
{ provide: SavedCartFacade, useClass: MockSavedCartFacade },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ChangeDetectorRef, Pipe, PipeTransform } from '@angular/core';
import {
ChangeDetectorRef,
Injectable,
Pipe,
PipeTransform,
} from '@angular/core';
import {
ComponentFixture,
fakeAsync,
Expand Down Expand Up @@ -31,7 +36,7 @@ class MockUserIdService implements Partial<UserIdService> {
return of('');
}
}

@Injectable()
class MockAsmComponentService implements Partial<AsmComponentService> {
logoutCustomerSupportAgentAndCustomer(): void {}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { Pipe, PipeTransform } from '@angular/core';
import {
Component,
Injectable,
Input,
Pipe,
PipeTransform,
} from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { CsAgentAuthService } from '@spartacus/asm/root';
import { AuthService, RoutingService } from '@spartacus/core';
import { LaunchDialogService } from '@spartacus/storefront';
import {
FocusDirective,
ICON_TYPE,
LaunchDialogService,
} from '@spartacus/storefront';
import { Observable, of } from 'rxjs';
import { AsmComponentService } from '../services';
import {
Expand All @@ -28,11 +38,19 @@ class MockLaunchDialogService implements Partial<LaunchDialogService> {
}
closeDialog(_reason: any) {}
}

@Injectable()
class MockAsmComponentService extends AsmComponentService {
logoutCustomer() {}
}

@Component({
selector: 'cx-icon',
template: '',
})
class MockCxIconComponent {
@Input() type: ICON_TYPE;
}

class MockAuthService implements Partial<AuthService> {
isUserLoggedIn(): Observable<boolean> {
return of(false);
Expand Down Expand Up @@ -63,7 +81,12 @@ describe('AsmSwitchCustomerDialogComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AsmSwitchCustomerDialogComponent, MockTranslatePipe],
declarations: [
AsmSwitchCustomerDialogComponent,
MockTranslatePipe,
FocusDirective,
MockCxIconComponent,
],
providers: [
{ provide: LaunchDialogService, useClass: MockLaunchDialogService },
{ provide: AsmComponentService, useClass: MockAsmComponentService },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PasswordVisibilityToggleModule,
} from '@spartacus/storefront';
import { CSAgentLoginFormComponent } from './csagent-login-form.component';
import { DotSpinnerComponent } from '../dot-spinner/dot-spinner.component';

describe('CSAgentLoginFormComponent', () => {
let component: CSAgentLoginFormComponent;
Expand All @@ -28,7 +29,7 @@ describe('CSAgentLoginFormComponent', () => {
FormErrorsModule,
PasswordVisibilityToggleModule,
],
declarations: [CSAgentLoginFormComponent],
declarations: [CSAgentLoginFormComponent, DotSpinnerComponent],
}).compileComponents();
})
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DebugElement } from '@angular/core';
import { Component, DebugElement, Injectable } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import {
Expand All @@ -21,7 +21,7 @@ describe('CustomerEmulationComponent', () => {
return of({});
}
}

@Injectable()
class MockAsmComponentService {
logoutCustomer(): void {}
isCustomerEmulationSessionInProgress(): Observable<boolean> {
Expand All @@ -30,6 +30,12 @@ describe('CustomerEmulationComponent', () => {
handleAsmDialogAction(): void {}
}

@Component({
selector: 'cx-asm-bind-cart',
template: '',
})
class MockAsmBindCartComponent {}

const dialogClose$ = new BehaviorSubject<any>('');
class MockLaunchDialogService implements Partial<LaunchDialogService> {
openDialogAndSubscribe() {}
Expand Down Expand Up @@ -58,7 +64,11 @@ describe('CustomerEmulationComponent', () => {
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [I18nTestingModule, FeaturesConfigModule],
declarations: [CustomerEmulationComponent, MockFeatureLevelDirective],
declarations: [
CustomerEmulationComponent,
MockFeatureLevelDirective,
MockAsmBindCartComponent,
],
providers: [
{
provide: FeatureModulesService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from '@spartacus/storefront';
import { BehaviorSubject, EMPTY, Observable, Subject } from 'rxjs';
import { CustomerSelectionComponent } from './customer-selection.component';
import { DotSpinnerComponent } from '../dot-spinner/dot-spinner.component';

class MockGlobalMessageService {
add = jasmine.createSpy();
Expand Down Expand Up @@ -123,7 +124,7 @@ describe('CustomerSelectionComponent', () => {
FormErrorsModule,
FeaturesConfigModule,
],
declarations: [CustomerSelectionComponent],
declarations: [CustomerSelectionComponent, DotSpinnerComponent],
providers: [
{ provide: AsmService, useClass: MockAsmService },
{ provide: GlobalMessageService, useClass: MockGlobalMessageService },
Expand Down
Loading

0 comments on commit 8190e95

Please sign in to comment.