Skip to content

Commit

Permalink
fix: adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG committed Feb 23, 2024
1 parent f78c7fe commit 66c2978
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
31 changes: 29 additions & 2 deletions src/app/product-store/app-delete/app-delete.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@ import { NO_ERRORS_SCHEMA } from '@angular/core'
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { TranslateTestingModule } from 'ngx-translate-testing'
import { of } from 'rxjs'

import { PortalMessageService } from '@onecx/portal-integration-angular'
import { MicrofrontendsAPIService } from 'src/app/shared/generated'
import { AppAbstract } from '../app-search/app-search.component'
import { AppDeleteComponent } from './app-delete.component'

describe('AppDeleteComponent', () => {
let component: AppDeleteComponent
let fixture: ComponentFixture<AppDeleteComponent>
const appMfe: AppAbstract = {
id: 'id',
appId: 'appId',
appType: 'MFE',
appName: 'name',
remoteBaseUrl: 'url',
productName: 'productName'
}
const msgServiceSpy = jasmine.createSpyObj<PortalMessageService>('PortalMessageService', ['success', 'error'])
const apiMfeServiceSpy = {
deleteMicrofrontend: jasmine.createSpy('deleteMicrofrontend').and.returnValue(of({}))
}

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
Expand All @@ -19,6 +35,10 @@ describe('AppDeleteComponent', () => {
en: require('src/assets/i18n/en.json')
}).withDefaultLanguage('en')
],
providers: [
{ provide: MicrofrontendsAPIService, useValue: apiMfeServiceSpy },
{ provide: PortalMessageService, useValue: msgServiceSpy }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents()
}))
Expand All @@ -28,6 +48,11 @@ describe('AppDeleteComponent', () => {
component = fixture.componentInstance
fixture.detectChanges()
})
afterEach(() => {
msgServiceSpy.success.calls.reset()
msgServiceSpy.error.calls.reset()
apiMfeServiceSpy.deleteMicrofrontend.calls.reset()
})

it('should create', () => {
expect(component).toBeTruthy()
Expand All @@ -42,10 +67,12 @@ describe('AppDeleteComponent', () => {
})

it('should onConfirmDeletion', () => {
spyOn(console, 'log')
spyOn(component.appDeleted, 'emit')
component.appAbstract = appMfe

component.onConfirmDeletion()

expect(console.log).toHaveBeenCalledWith('onConfirmDeletion')
expect(msgServiceSpy.success).toHaveBeenCalledWith({ summaryKey: 'ACTIONS.DELETE.APP.OK' })
expect(component.appDeleted.emit).toHaveBeenCalledWith(true)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,34 @@
></ng-template>
<ng-template let-app pTemplate="gridItem">
<div class="col-12 sm:col-6 md:col-4 lg:col-4 xl:col-3 p-3" (click)="onDetail($event, app)">
<div class="card relative p-1 flex flex-column justify-content-center hover:bg-gray-200 cursor-pointer">
<div
class="card relative p-1 flex flex-column justify-content-center hover:bg-gray-200 hover:text-color cursor-pointer"
[class.bg-primary]="app.appType === 'MFE'"
>
<span
*ngIf="hasCreatePermission"
*ngIf="app.operator === 'MANUELL' && hasCreatePermission"
[id]="'app_search_data_' + app.appId + '_copy_app'"
class="card-badge-left badge-1 p-2 pi pi-copy pseudo-button-link"
[title]="'ACTIONS.COPY.LABEL' | translate"
(click)="onCopy($event, app)"
></span>
<span
*ngIf="hasDeletePermission"
*ngIf="app.operator === 'MANUELL' && hasDeletePermission"
[id]="'app_search_data_' + app.appId + '_delete_app'"
class="card-badge-left badge-2 p-2 pi pi-trash danger-action-text pseudo-button-link"
[title]="'ACTIONS.DELETE.LABEL' | translate"
(click)="onDelete($event, app)"
></span>
<div class="flex flex-column justify-content-between gap-1 text-center">
<span
*ngIf="app.appType === 'MFE'"
[id]="'app_search_data_icon'"
class="card-badge-right badge-2 p-2 pi pseudo-button-link"
[ngClass]="'pi-' + app.iconName"
[title]="'APP.ICON_NAME' | translate"
></span>
<div class="h-4rem flex flex-column justify-content-between gap-1 text-center">
<div class="font-bold" [title]="'ID: ' + app.appId">{{ limitText(app.appId, 25) }}</div>
<div class="text-sm" [title]="'App Name: ' + app.appName">{{ limitText(app.appName, 30) }}</div>
<div class="text-sm" [title]="'APP.APP_TYPE' | translate">{{ app.appType }}</div>
<div [title]="'Product: ' + app.productName">{{ limitText(app.productName, 25) }}</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('ProductAppsComponent', () => {
})

it('should search microfrontends on searchApps', () => {
const searchSpy = spyOn((component as any).appApi, 'searchMicrofrontends').and.returnValue(
const searchSpy = spyOn((component as any).mfeApi, 'searchMicrofrontends').and.returnValue(
of({
totalElements: 0,
number: 0,
Expand All @@ -97,7 +97,7 @@ describe('ProductAppsComponent', () => {
component.searchApps()

expect(searchSpy).toHaveBeenCalledWith({
mfeAndMsSearchCriteria: { productName: component.product?.name, pageSize: 1000 }
mfeAndMsSearchCriteria: { productName: component.product?.name }
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class ProductAppsComponent implements OnChanges {
public searchApps(): void {
this.searchInProgress = true
this.mfes$ = this.mfeApi
.searchMicrofrontends({ mfeAndMsSearchCriteria: { productName: this.product } as MfeAndMsSearchCriteria })
.searchMicrofrontends({ mfeAndMsSearchCriteria: { productName: this.product?.name } as MfeAndMsSearchCriteria })
.pipe(
startWith({} as MicrofrontendPageResult),
catchError((err) => {
Expand All @@ -85,7 +85,7 @@ export class ProductAppsComponent implements OnChanges {
)

this.mss$ = this.msApi
.searchMicroservice({ mfeAndMsSearchCriteria: { productName: this.product } as MfeAndMsSearchCriteria })
.searchMicroservice({ mfeAndMsSearchCriteria: { productName: this.product?.name } as MfeAndMsSearchCriteria })
.pipe(
startWith({} as MicroservicePageResult),
catchError((err) => {
Expand Down

0 comments on commit 66c2978

Please sign in to comment.