-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components/forms): add method to
SkyFormErrorHarness
to get er…
…ror text (#2992) (#2994) Original contribution: #2992 Co-authored-by: Blackbaud-NickGlyder <46350119+Blackbaud-NickGlyder@users.noreply.github.com> Co-authored-by: Nicklaus Glyder <Nicklaus.Glyder@blackbaud.me>
- Loading branch information
1 parent
7530a56
commit 65aa2e8
Showing
3 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
libs/components/forms/testing/src/modules/form-error/form-error-harness.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,79 @@ | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { Component } from '@angular/core'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { SKY_FORM_ERRORS_ENABLED, SkyFormErrorModule } from '@skyux/forms'; | ||
|
||
import { SkyFormErrorHarness } from './form-error-harness'; | ||
|
||
//#region Test component | ||
@Component({ | ||
selector: 'sky-form-error-test', | ||
providers: [ | ||
{ | ||
provide: SKY_FORM_ERRORS_ENABLED, | ||
useValue: true, | ||
}, | ||
], | ||
template: ` | ||
<sky-form-error [errorName]="errorName" [errorText]="errorText" /> | ||
<sky-form-error | ||
data-sky-id="other-error" | ||
[errorName]="errorNameSkyId" | ||
[errorText]="errorTextSkyId" | ||
/> | ||
`, | ||
standalone: false, | ||
}) | ||
class TestComponent { | ||
public errorName = 'error'; | ||
public errorText = 'some-error'; | ||
public errorNameSkyId = 'error-sky-id'; | ||
public errorTextSkyId = 'some-error-sky-id'; | ||
} | ||
//#endregion Test component | ||
|
||
describe('Form error harness', () => { | ||
async function setupTest(options: { dataSkyId?: string } = {}): Promise<{ | ||
formErrorHarness: SkyFormErrorHarness; | ||
fixture: ComponentFixture<TestComponent>; | ||
loader: HarnessLoader; | ||
pageLoader: HarnessLoader; | ||
}> { | ||
await TestBed.configureTestingModule({ | ||
declarations: [TestComponent], | ||
imports: [SkyFormErrorModule], | ||
}).compileComponents(); | ||
const fixture = TestBed.createComponent(TestComponent); | ||
const loader = TestbedHarnessEnvironment.loader(fixture); | ||
const pageLoader = TestbedHarnessEnvironment.documentRootLoader(fixture); | ||
const formErrorHarness: SkyFormErrorHarness = options.dataSkyId | ||
? await loader.getHarness( | ||
SkyFormErrorHarness.with({ dataSkyId: options.dataSkyId }), | ||
) | ||
: await loader.getHarness(SkyFormErrorHarness); | ||
return { formErrorHarness, fixture, loader, pageLoader }; | ||
} | ||
|
||
it('should get form error text', async () => { | ||
const { formErrorHarness, fixture } = await setupTest(); | ||
|
||
fixture.detectChanges(); | ||
|
||
await expectAsync(formErrorHarness.getErrorText()).toBeResolvedTo( | ||
fixture.componentInstance.errorText, | ||
); | ||
}); | ||
|
||
it('should get form error text by its data-sky-id', async () => { | ||
const { formErrorHarness, fixture } = await setupTest({ | ||
dataSkyId: 'other-error', | ||
}); | ||
|
||
fixture.detectChanges(); | ||
|
||
await expectAsync(formErrorHarness.getErrorText()).toBeResolvedTo( | ||
fixture.componentInstance.errorTextSkyId, | ||
); | ||
}); | ||
}); |
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