-
Notifications
You must be signed in to change notification settings - Fork 11
feat: show selected item's icon in trigger label if applicable #884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
89b8f27
feat: show selected item's icon in trigger label if applicable
arjunlalb b30f50d
fix: explicit undefined check
arjunlalb 4f23fc9
fix: typedef
arjunlalb cfcbda3
fix: update logic
arjunlalb 1b69a18
simplify logic. update test
arjunlalb b8f0dc3
fix: override no-null
arjunlalb 3aa2e25
fix: remove unused module
arjunlalb fd47b9c
Merge branch 'main' into update-select
arjunlalb 16983c3
fix: update behaviour
arjunlalb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { fakeAsync, flush } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { IconLibraryTestingModule, IconType } from '@hypertrace/assets-library'; | ||
import { NavigationService } from '@hypertrace/common'; | ||
import { IconComponent } from '@hypertrace/components'; | ||
import { createHostFactory, mockProvider, SpectatorHost } from '@ngneat/spectator/jest'; | ||
import { MockComponent } from 'ng-mocks'; | ||
import { EMPTY } from 'rxjs'; | ||
import { SelectControlOptionPosition } from './select-control-option.component'; | ||
import { SelectJustify } from './select-justify'; | ||
|
@@ -14,6 +17,7 @@ describe('Select Component', () => { | |
component: SelectComponent, | ||
imports: [SelectModule, HttpClientTestingModule, IconLibraryTestingModule], | ||
declareComponent: false, | ||
declarations: [MockComponent(IconComponent)], | ||
providers: [ | ||
mockProvider(NavigationService, { | ||
navigation$: EMPTY, | ||
|
@@ -27,7 +31,7 @@ describe('Select Component', () => { | |
const selectionOptions = [ | ||
{ label: 'first', value: 'first-value' }, | ||
{ label: 'second', value: 'second-value' }, | ||
{ label: 'third', value: 'third-value', selectedLabel: 'Third Value!!!' } | ||
{ label: 'third', value: 'third-value', selectedLabel: 'Third Value!!!', icon: 'test-icon', iconColor: 'red' } | ||
]; | ||
|
||
test('should display initial selection', fakeAsync(() => { | ||
|
@@ -146,12 +150,56 @@ describe('Select Component', () => { | |
const optionElements = spectator.queryAll('.select-option', { root: true }); | ||
spectator.click(optionElements[2]); | ||
|
||
expect(onChange).toHaveBeenCalledTimes(1); | ||
expect(onChange).toHaveBeenCalledWith(selectionOptions[2].value); | ||
expect(spectator.query('.trigger-content')).toHaveText(selectionOptions[2].selectedLabel!); | ||
flush(); | ||
})); | ||
|
||
test('should set trigger-prefix-icon correctly', fakeAsync(() => { | ||
spectator = hostFactory( | ||
` | ||
<ht-select [icon]="icon"> | ||
<ht-select-option *ngFor="let option of options" [label]="option.label" [value]="option.value" [icon]="option.icon" [iconColor]="option.iconColor"> | ||
</ht-select-option> | ||
</ht-select>`, | ||
{ | ||
hostProps: { | ||
options: selectionOptions, | ||
icon: 'select-level-icon' | ||
} | ||
} | ||
); | ||
spectator.tick(); | ||
|
||
// No selection -> select component level icon and no color | ||
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.icon).toBe( | ||
'select-level-icon' | ||
); | ||
// tslint:disable-next-line:no-null-keyword | ||
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.color).toBe(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
|
||
// Selection with no icon -> default icon and no color | ||
spectator.click('.trigger-content'); | ||
let optionElements = spectator.queryAll('.select-option', { root: true }); | ||
spectator.click(optionElements[1]); | ||
spectator.tick(); | ||
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.icon).toBe( | ||
'select-level-icon' | ||
); | ||
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.color).toBe(undefined); | ||
|
||
// Selection with icon and color | ||
spectator.click('.trigger-content'); | ||
optionElements = spectator.queryAll('.select-option', { root: true }); | ||
spectator.click(optionElements[2]); | ||
spectator.tick(); | ||
|
||
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.icon).toBe('test-icon'); | ||
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.color).toBe('red'); | ||
|
||
flush(); | ||
})); | ||
|
||
test('should set correct label alignment', fakeAsync(() => { | ||
spectator = hostFactory( | ||
` | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason to use debug element querying rather than spectator querying ? is it because spectator doesn't give you access to the component on root queries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. wanted to access component to verify the contents of it.