Skip to content

Commit

Permalink
Raise test coverage (#141)
Browse files Browse the repository at this point in the history
* fix: app detail test

* fix: app search tests

* fix: role detail tests

* fix: role detail tests

* fix: raise deps

---------

Co-authored-by: Christian Badura <[email protected]>
  • Loading branch information
cbadura and Christian Badura authored Aug 1, 2024
1 parent 571be09 commit 806b9d1
Show file tree
Hide file tree
Showing 10 changed files with 421 additions and 224 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "none" }],
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-types": [
"error",
{
Expand Down
290 changes: 182 additions & 108 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"@angular-architects/module-federation": "18.0.4",
"@angular/animations": "^18.1.2",
"@angular/cdk": "^18.1.2",
"@angular/cdk": "^18.1.3",
"@angular/common": "^18.1.2",
"@angular/compiler": "^18.1.2",
"@angular/core": "^18.1.2",
Expand Down Expand Up @@ -76,15 +76,15 @@
"devDependencies": {
"@angular-devkit/build-angular": "^18.1.2",
"@angular-devkit/core": "^18.1.2",
"@angular-devkit/schematics": "^18.1.2",
"@angular-devkit/schematics": "^18.1.3",
"@angular-eslint/builder": "^18.1.0",
"@angular-eslint/eslint-plugin": "^18.1.0",
"@angular-eslint/eslint-plugin-template": "^18.1.0",
"@angular-eslint/schematics": "^18.1.0",
"@angular-eslint/schematics": "^18.2.0",
"@angular-eslint/template-parser": "^18.1.0",
"@angular/cli": "~18.1.2",
"@angular/compiler-cli": "^18.1.2",
"@angular/language-service": "^18.1.2",
"@angular/language-service": "^18.1.3",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@docusaurus/module-type-aliases": "~3.4.0",
Expand Down
2 changes: 2 additions & 0 deletions src/app/permission/app-detail/app-detail.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,12 @@ describe('AppDetailComponent', () => {
statusText: 'Not Found'
})
wsApiSpy.getDetailsByWorkspaceName.and.returnValue(throwError(() => err))
spyOn(console, 'error')

component.ngOnInit()

expect(component.loadingExceptionKey).toBe('EXCEPTIONS.HTTP_STATUS_' + err.status + '.WORKSPACE')
expect(console.error).toHaveBeenCalledWith('getDetailsByWorkspaceName() => unknown response:', err)
})

xit('should catch non-HttpErrorResponse error if workspace detail load fails', () => {
Expand Down
11 changes: 7 additions & 4 deletions src/app/permission/app-detail/app-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,13 @@ export class AppDetailComponent implements OnInit, OnDestroy {
private loadWorkspaceDetails() {
this.workspaceApi
.getDetailsByWorkspaceName({ workspaceName: this.currentApp.appId! })
.pipe(catchError((error) => of(error)))
.pipe(
catchError((error) => {
this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_0.WORKSPACE'
console.error('getDetailsByWorkspaceName() => unknown response:', error)
return of(error)
})
)
.subscribe((result) => {
if (result instanceof HttpErrorResponse) {
this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_' + result.status + '.WORKSPACE'
Expand All @@ -268,9 +274,6 @@ export class AppDetailComponent implements OnInit, OnDestroy {
this.currentApp.workspaceDetails?.products?.map((product) => this.fillProductApps(product))
this.prepareActionButtons()
this.loadRolesAndPermissions()
} else {
this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_0.WORKSPACE'
console.error('getDetailsByWorkspaceName() => unknown response:', result)
}
})
}
Expand Down
113 changes: 74 additions & 39 deletions src/app/permission/app-search/app-search.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
Application
} from 'src/app/shared/generated'
import { App, AppSearchComponent } from './app-search.component'
import { RowListGridData } from '@onecx/angular-accelerator'

const wsAbstract: WorkspaceAbstract = {
name: 'wsName'
Expand Down Expand Up @@ -87,6 +88,23 @@ describe('AppSearchComponent', () => {
expect(component).toBeTruthy()
})

it('should add filters when component is initialized', (done) => {
component.typeFilterValue$.next('filterValue')
component.textFilterValue$.next('textFilterValue')

component.filters$.subscribe({
next: (filters) => {
expect(filters).toContain(
jasmine.objectContaining({ columnId: 'appType', value: 'filterValue', mode: 'equals' })
)
expect(filters).toContain(
jasmine.objectContaining({ columnId: 'displayName', value: 'textFilterValue', mode: 'contains' })
)
done()
}
})
})

/**
* SEARCH
*/
Expand Down Expand Up @@ -325,19 +343,34 @@ describe('AppSearchComponent', () => {
expect(mockRouter.navigate).toHaveBeenCalledWith(['./', 'app', app.appId], { relativeTo: undefined })
})

// it('should update filterBy and filterValue onQuickFilterChange: ALL', () => {
// component.onQuickFilterChange({ value: 'ALL' })
describe('onQuickFilterChange', () => {
it('should set typeFilterValue$ to an empty string when value is "ALL"', () => {
const event = { value: 'ALL' }
spyOn(component.typeFilterValue$, 'next')

component.onQuickFilterChange(event)

expect(component.typeFilterValue$.next).toHaveBeenCalledWith('')
})

// expect(component.filterBy).toBe(component.filterValueDefault)
// expect(component.filterValue).toBe('')
// })
it('should set typeFilterValue$ to given value when value is not "ALL" and is truthy', () => {
const event = { value: 'SOME_VALUE' }
spyOn(component.typeFilterValue$, 'next')

// it('should update filterBy and filterValue onQuickFilterChange: other', () => {
// component.onQuickFilterChange({ value: 'other' })
component.onQuickFilterChange(event)

// expect(component.filterValue).toBe('other')
// expect(component.filterBy).toBe('appType')
// })
expect(component.typeFilterValue$.next).toHaveBeenCalledWith('SOME_VALUE')
})

it('should not call typeFilterValue$.next when value is falsy', () => {
const event = { value: '' }
spyOn(component.typeFilterValue$, 'next')

component.onQuickFilterChange(event)

expect(component.typeFilterValue$.next).not.toHaveBeenCalled()
})
})

it('should disable name input field is app type on search is ALL', () => {
component.onAppTypeFilterChange({ value: 'ALL' })
Expand All @@ -347,31 +380,33 @@ describe('AppSearchComponent', () => {
expect(component.appSearchCriteriaGroup.controls['name'].enabled).toBeTrue()
})

// it('should call filter table onFilterChange', () => {
// component.dv = jasmine.createSpyObj('test', ['filter'])
it('should update textFilterValue$ when onFilterChange is called', () => {
const filterValue = 'newFilter'
spyOn(component.textFilterValue$, 'next')

// component.onFilterChange('test')
component.onFilterChange(filterValue)

// expect(component.filter).toBe('test')
// expect(component.dv?.filter).toHaveBeenCalledWith('test', 'contains')
// })
expect(component.textFilterValue$.next).toHaveBeenCalledWith(filterValue)
})

it('should set correct values onSortChange', () => {
component.onSortChange('field')

expect(component.sortField).toEqual('field')
})

it('should set correct values onSortDirChange', () => {
component.onSortDirChange(true)
describe('onSortDirChange', () => {
it('should set correct values onSortDirChange', () => {
component.onSortDirChange(true)

expect(component.sortOrder).toEqual(-1)
})
expect(component.sortOrder).toEqual(-1)
})

it('should set correct values onSortDirChange', () => {
component.onSortDirChange(false)
it('should set correct values onSortDirChange', () => {
component.onSortDirChange(false)

expect(component.sortOrder).toEqual(1)
expect(component.sortOrder).toEqual(1)
})
})

it('should searchApps when search button is clicked', () => {
Expand All @@ -382,20 +417,20 @@ describe('AppSearchComponent', () => {
expect(component.searchApps).toHaveBeenCalled()
})

// it('should reset search criteria group and assign empty array to apps observable', (done) => {
// spyOn(component.appSearchCriteriaGroup, 'reset')

// component.onSearchReset()

// expect(component.appSearchCriteriaGroup.reset).toHaveBeenCalledOnceWith({ appType: 'ALL' })
// component.apps$.subscribe({
// next: (res) => {
// if (res) {
// expect(res).toEqual([] as App[])
// }
// done()
// },
// error: done.fail
// })
// })
it('should reset search criteria group and assign empty array to apps observable', (done) => {
spyOn(component.appSearchCriteriaGroup, 'reset')

component.onSearchReset()

expect(component.appSearchCriteriaGroup.reset).toHaveBeenCalledOnceWith({ appType: 'ALL' })
component.apps$.subscribe({
next: (res) => {
if (res) {
expect(res).toEqual([] as (App & RowListGridData)[])
}
done()
},
error: done.fail
})
})
})
6 changes: 3 additions & 3 deletions src/app/permission/app-search/app-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class AppSearchComponent implements OnInit, OnDestroy {
finalize(() => (this.searchInProgress = false))
)
return this.workspaces$.pipe(
map((result: any) => {
map((result) => {
return result.stream
? result.stream
?.map((w: WorkspaceAbstract) => {
Expand Down Expand Up @@ -176,7 +176,7 @@ export class AppSearchComponent implements OnInit, OnDestroy {
finalize(() => (this.searchInProgress = false))
)
return this.papps$.pipe(
map((result: any) => {
map((result) => {
if (!result.stream) return []
const productNames: string[] = []
const apps: (App & RowListGridData)[] = []
Expand Down Expand Up @@ -247,7 +247,7 @@ export class AppSearchComponent implements OnInit, OnDestroy {
'ACTIONS.SEARCH.SORT_DIRECTION_DESC'
])
.pipe(
map((data: any) => {
map((data) => {
this.dataViewControlsTranslations = {
sortDropdownPlaceholder: data['ACTIONS.SEARCH.SORT_BY'],
filterInputPlaceholder: data['ACTIONS.SEARCH.FILTER.LABEL'],
Expand Down
Loading

0 comments on commit 806b9d1

Please sign in to comment.