-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2266 from abpframework/test/theme-shared
test(theme-shared): add sort-order-icon component test
- Loading branch information
Showing
2 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
npm/ng-packs/packages/theme-shared/src/lib/tests/sort-order-icon.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createHostFactory, SpectatorHost } from '@ngneat/spectator/jest'; | ||
import { SortOrderIconComponent } from '../components/sort-order-icon/sort-order-icon.component'; | ||
|
||
describe('SortOrderIconComponent', () => { | ||
let spectator: SpectatorHost<SortOrderIconComponent>; | ||
let component: SortOrderIconComponent; | ||
const createHost = createHostFactory(SortOrderIconComponent); | ||
|
||
beforeEach(() => { | ||
spectator = createHost( | ||
'<abp-sort-order-icon key="testKey" [(selectedSortKey)]="selectedSortKey" [(order)]="order"></abp-sort-order-icon>', | ||
{ | ||
hostProps: { | ||
selectedSortKey: '', | ||
order: '', | ||
}, | ||
}, | ||
); | ||
component = spectator.component; | ||
}); | ||
|
||
test('should have correct icon class when selectedSortKey and sortKey are the same', () => { | ||
const newKey = 'testKey'; | ||
component.sort(newKey); | ||
expect(component.selectedSortKey).toBe(newKey); | ||
expect(component.order).toBe('asc'); | ||
expect(component.icon).toBe('fa-sort-asc'); | ||
}); | ||
|
||
test("shouldn't have any icon class when sortKey and selectedSortKey are different", () => { | ||
const newKey = 'otherKey'; | ||
component.sort(newKey); | ||
expect(component.selectedSortKey).toBe(newKey); | ||
expect(component.order).toBe('asc'); | ||
expect(component.icon).toBe(''); | ||
}); | ||
|
||
test('should change order correctly when sort function called', () => { | ||
component.sort('testKey'); | ||
expect(component.order).toBe('asc'); | ||
component.sort('testKey'); | ||
expect(component.order).toBe('desc'); | ||
component.sort('testKey'); | ||
expect(component.order).toBe(''); | ||
}); | ||
}); |