Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG committed Dec 19, 2024
1 parent 98fb101 commit 9c88488
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'
import { provideHttpClient, HttpClient } from '@angular/common/http'
import { provideHttpClientTesting } from '@angular/common/http/testing'
import { FormControl, FormGroup } from '@angular/forms'
import { By } from '@angular/platform-browser'
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'
import { of, throwError } from 'rxjs'
import { SelectItem } from 'primeng/api'
Expand Down Expand Up @@ -35,6 +36,7 @@ const parameter: Parameter = {
describe('ParameterDetailComponent', () => {
let component: ParameterDetailComponent
let fixture: ComponentFixture<ParameterDetailComponent>
let appDropdownElement: any

const msgServiceSpy = jasmine.createSpyObj<PortalMessageService>('PortalMessageService', ['success', 'error'])
const apiServiceSpy = {
Expand Down Expand Up @@ -249,6 +251,15 @@ describe('ParameterDetailComponent', () => {
})

describe('onChangeProductName', () => {
beforeEach(() => {
appDropdownElement = fixture.debugElement.query(By.css('#pm_detail_form_app_id')).nativeElement
})
it('should reject update appIdOptions if no product name is provided', () => {
component.onChangeProductName(null, appDropdownElement)

expect(component.appIdOptions).toEqual([])
})

it('should update appIdOptions based on the product name', () => {
component.allProducts = [
{ productName: 'productA', applications: ['app1', 'app2'] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ export class ParameterDetailComponent implements OnChanges {
}

// load appId dropdown with app ids from product
public onChangeProductName(name: string, subElement?: Dropdown) {
public onChangeProductName(name: string | null, subElement?: Dropdown) {
this.appIdOptions = []
subElement?.clear()
if (subElement?.clear) subElement.clear()
this.formGroup.controls['productName'].setValue(name)
if (!name) return
this.allProducts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'
import { provideHttpClient, HttpClient } from '@angular/common/http'
import { provideHttpClientTesting } from '@angular/common/http/testing'
import { FormControl, FormGroup } from '@angular/forms'
import { By } from '@angular/platform-browser'
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'
import { SelectItem } from 'primeng/api'

Expand Down Expand Up @@ -34,6 +35,7 @@ const usedProductsSI: SelectItem[] = [
describe('ParameterCriteriaComponent', () => {
let component: ParameterCriteriaComponent
let fixture: ComponentFixture<ParameterCriteriaComponent>
let appDropdownElement: any

const mockUserService = { lang$: { getValue: jasmine.createSpy('getValue') } }

Expand Down Expand Up @@ -115,12 +117,21 @@ describe('ParameterCriteriaComponent', () => {
})

describe('onChangeProductName', () => {
beforeEach(() => {
appDropdownElement = fixture.debugElement.query(By.css('#pm_search_criteria_application_id')).nativeElement
})
it('should reject update appIdOptions if no product name is provided', () => {
component.onChangeProductName(null, appDropdownElement)

expect(component.appIdOptions).toEqual([])
})

it('should update appIdOptions based on the product name', () => {
component.usedProducts = [
{ productName: 'productA', applications: ['app1', 'app2'] },
{ productName: 'productB', displayName: 'Prouct B', applications: ['app3'] }
]
component.onChangeProductName('productA')
component.onChangeProductName(component.usedProducts[0].productName!, appDropdownElement)

expect(component.appIdOptions).toEqual([
{ label: 'app1', value: 'app1' },
Expand All @@ -130,7 +141,9 @@ describe('ParameterCriteriaComponent', () => {

it('should clear appIdOptions if productName does not match', () => {
component.usedProducts = [{ productName: 'Product A', applications: ['App1', 'App2'] }]
component.onChangeProductName('Product C')

if (appDropdownElement) appDropdownElement.click()
component.onChangeProductName('Product C', appDropdownElement)

expect(component.appIdOptions).toEqual([])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export class ParameterCriteriaComponent implements OnChanges {
this.resetSearchEmitter.emit(true)
}

public onChangeProductName(name: string, subElement: Dropdown) {
public onChangeProductName(name: string | null, subElement?: Dropdown) {
this.appIdOptions = []
subElement.clear()
if (subElement?.clear) subElement.clear()
if (!name) return
this.usedProducts
.filter((p) => p.productName === name)
Expand Down

0 comments on commit 9c88488

Please sign in to comment.