-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-129015 / 24.10 / Edit scenario on main dashboard (#10068)
- Loading branch information
Showing
14 changed files
with
172 additions
and
92 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
94 changes: 94 additions & 0 deletions
94
src/app/modules/ix-forms/components/ix-icon-group/ix-icon-group.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,94 @@ | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { FormControl } from '@ngneat/reactive-forms'; | ||
import { createHostFactory, SpectatorHost } from '@ngneat/spectator/jest'; | ||
import { IxIconGroupComponent } from 'app/modules/ix-forms/components/ix-icon-group/ix-icon-group.component'; | ||
import { IxIconGroupHarness } from 'app/modules/ix-forms/components/ix-icon-group/ix-icon-group.harness'; | ||
import { IxLabelHarness } from 'app/modules/ix-forms/components/ix-label/ix-label.harness'; | ||
import { IxFormsModule } from 'app/modules/ix-forms/ix-forms.module'; | ||
|
||
describe('IxIconGroupComponent', () => { | ||
let spectator: SpectatorHost<IxIconGroupComponent>; | ||
let loader: HarnessLoader; | ||
let iconGroupHarness: IxIconGroupHarness; | ||
const formControl = new FormControl(); | ||
const createHost = createHostFactory({ | ||
component: IxIconGroupComponent, | ||
imports: [ | ||
ReactiveFormsModule, | ||
IxFormsModule, | ||
], | ||
declareComponent: false, | ||
}); | ||
|
||
beforeEach(async () => { | ||
spectator = createHost( | ||
`<ix-icon-group | ||
[options]="options" | ||
[label]="label" | ||
[tooltip]="tooltip" | ||
[required]="required" | ||
[formControl]="formControl" | ||
></ix-icon-group>`, | ||
{ | ||
hostProps: { | ||
formControl, | ||
options: new Map<string, string>([ | ||
['edit', 'mdi-pencil'], | ||
['delete', 'mdi-delete'], | ||
]), | ||
label: 'Icon group', | ||
tooltip: 'This is a tooltip', | ||
required: true, | ||
}, | ||
}, | ||
); | ||
|
||
loader = TestbedHarnessEnvironment.loader(spectator.fixture); | ||
iconGroupHarness = await loader.getHarness(IxIconGroupHarness); | ||
}); | ||
|
||
describe('rendering', () => { | ||
it('renders ix-label and passes label, hint, tooltip and required', async () => { | ||
const label = await loader.getHarness(IxLabelHarness.with({ label: 'Icon group' })); | ||
|
||
expect(label).toBeTruthy(); | ||
expect(await label.isRequired()).toBe(true); | ||
|
||
const tooltip = await label.getTooltip(); | ||
expect(tooltip).toBeTruthy(); | ||
expect(await tooltip.getMessage()).toBe('This is a tooltip'); | ||
}); | ||
|
||
it('shows buttons for provided options', async () => { | ||
const buttons = await iconGroupHarness.getButtons(); | ||
expect(buttons).toHaveLength(2); | ||
|
||
const icons = await iconGroupHarness.getIcons(); | ||
expect(icons).toHaveLength(2); | ||
expect(await icons[0].getName()).toBe('mdi-pencil'); | ||
expect(await icons[1].getName()).toBe('mdi-delete'); | ||
}); | ||
|
||
it('does not highlight any buttons when no value is set', async () => { | ||
expect(await iconGroupHarness.getValue()).toBe(''); | ||
}); | ||
|
||
it('highlights button with selected value', async () => { | ||
formControl.setValue('edit'); | ||
expect(await iconGroupHarness.getValue()).toBe('edit'); | ||
}); | ||
}); | ||
|
||
it('updates form control value when user presses the button', async () => { | ||
const buttons = await iconGroupHarness.getButtons(); | ||
await buttons[1].click(); | ||
expect(formControl.value).toBe('delete'); | ||
}); | ||
|
||
it('disables buttons when form control is disabled', async () => { | ||
formControl.disable(); | ||
expect(await iconGroupHarness.isDisabled()).toBe(true); | ||
}); | ||
}); |
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
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
66 changes: 0 additions & 66 deletions
66
src/app/modules/ix-forms/components/ix-icon-group/ix-icon-group.spec.ts
This file was deleted.
Oops, something went wrong.
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
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,10 @@ | ||
import { ComponentHarness } from '@angular/cdk/testing'; | ||
|
||
export class IxTooltipHarness extends ComponentHarness { | ||
static hostSelector = 'ix-tooltip'; | ||
|
||
async getMessage(): Promise<string> { | ||
const message = await this.locatorForOptional('.tooltip-message')(); | ||
return message ? message.text() : ''; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.