Skip to content

Commit

Permalink
Adjust tests (#90)
Browse files Browse the repository at this point in the history
* fix: finish theme search

* fix: improve theme designer tests

* fix: finish theme designer tests

* fix: finish theme import tests

* fix: label resolver tests

* fix: theme detail lang test

* fix: theme designer test

---------

Co-authored-by: Christian Badura <[email protected]>
Co-authored-by: Henry Täschner <[email protected]>
Co-authored-by: Henry Taeschner <[email protected]>
  • Loading branch information
4 people authored Mar 13, 2024
1 parent d4f6187 commit 80ef257
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 105 deletions.
11 changes: 11 additions & 0 deletions src/app/shared/label.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ describe('LabelResolver', () => {
expect(result).toBe('path')
expect(translateServiceSpy.get).toHaveBeenCalledTimes(0)
})

it('should return an empty string if neither breadcrumb nor route.routeConfig.path are present', () => {
const routeConfigSpy = Object.getOwnPropertyDescriptor(activatedRouteSpy, 'routeConfig')?.get as jasmine.Spy<
() => {}
>
routeConfigSpy.and.returnValue({})
const result = labelResolver.resolve(activatedRouteSpy, routerStateSpy)

expect(result).toBe('')
expect(translateServiceSpy.get).toHaveBeenCalledTimes(0)
})
})
27 changes: 26 additions & 1 deletion src/app/shared/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { filterObject, limitText } from './utils'
import { SelectItem } from 'primeng/api'
import { dropDownSortItemsByLabel, filterObject, limitText } from './utils'

describe('utils', () => {
it('should limit text if text too long', () => {
Expand All @@ -18,4 +19,28 @@ describe('utils', () => {
isVisible: true
})
})

describe('dropDownSortItemsByLabel', () => {
it('should correctly sort items by label', () => {
const items: SelectItem[] = [
{ label: 'label2', value: 2 },
{ label: 'label1', value: 1 }
]

const sortedItems = items.sort(dropDownSortItemsByLabel)

expect(sortedItems[0].label).toEqual('label1')
})
it("should treat falsy values for SelectItem.label as ''", () => {
const items: SelectItem[] = [
{ label: undefined, value: 1 },
{ label: undefined, value: 2 },
{ label: 'label1', value: 2 }
]

const sortedItems = items.sort(dropDownSortItemsByLabel)

expect(sortedItems[0].label).toEqual(undefined)
})
})
})
2 changes: 1 addition & 1 deletion src/app/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function dropDownSortItemsByLabel(a: SelectItem, b: SelectItem): number {
b.label ? (b.label as string).toUpperCase() : ''
)
}
export function dropDownGetLabelByValue(ddArray: SelectItem[], val: string): string | undefined {
export function dropDownGetLabelByValue(ddArray: SelectItem[], val: string): string {
const a: any = ddArray.find((item: SelectItem) => {
return item?.value == val
})
Expand Down
Loading

0 comments on commit 80ef257

Please sign in to comment.