-
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): file attachment harness (#2930)
- Loading branch information
1 parent
f786095
commit 147498a
Showing
11 changed files
with
892 additions
and
3 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
apps/code-examples/src/app/code-examples/forms/file-attachment/basic/demo.component.html
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
73 changes: 73 additions & 0 deletions
73
apps/code-examples/src/app/code-examples/forms/file-attachment/basic/demo.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,73 @@ | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { | ||
SkyFileAttachmentHarness, | ||
provideSkyFileAttachmentTesting, | ||
} from '@skyux/forms/testing'; | ||
|
||
import { DemoComponent } from './demo.component'; | ||
|
||
describe('Basic file attachment demo', () => { | ||
async function setupTest(options: { dataSkyId: string }): Promise<{ | ||
harness: SkyFileAttachmentHarness; | ||
fixture: ComponentFixture<DemoComponent>; | ||
}> { | ||
TestBed.configureTestingModule({ | ||
providers: [provideSkyFileAttachmentTesting()], | ||
}); | ||
const fixture = TestBed.createComponent(DemoComponent); | ||
const loader = TestbedHarnessEnvironment.loader(fixture); | ||
|
||
const harness = await loader.getHarness( | ||
SkyFileAttachmentHarness.with({ dataSkyId: options.dataSkyId }), | ||
); | ||
|
||
fixture.detectChanges(); | ||
await fixture.whenStable(); | ||
|
||
return { harness, fixture }; | ||
} | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [DemoComponent, NoopAnimationsModule], | ||
}); | ||
}); | ||
|
||
it('should set initial values', async () => { | ||
const { harness } = await setupTest({ | ||
dataSkyId: 'birth-certificate', | ||
}); | ||
|
||
await expectAsync(harness.getLabelText()).toBeResolvedTo( | ||
'Birth certificate', | ||
); | ||
await expectAsync(harness.getHintText()).toBeResolvedTo( | ||
'Attach a .pdf, .gif, .png, or .jpeg file.', | ||
); | ||
await expectAsync(harness.getAcceptedTypes()).toBeResolvedTo( | ||
'application/pdf,image/jpeg,image/png,image/gif', | ||
); | ||
await expectAsync(harness.isRequired()).toBeResolvedTo(true); | ||
|
||
await harness.clickHelpInline(); | ||
|
||
await expectAsync(harness.getHelpPopoverTitle()).toBeResolvedTo( | ||
'Requirements', | ||
); | ||
}); | ||
|
||
it('should throw an error if file begins with the letter a', async () => { | ||
const { harness } = await setupTest({ | ||
dataSkyId: 'birth-certificate', | ||
}); | ||
|
||
const file = new File([], 'art.png', { type: 'image/png' }); | ||
await harness.attachFile(file); | ||
|
||
await expectAsync( | ||
harness.hasCustomError('invalidStartingLetter'), | ||
).toBeResolvedTo(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
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
8 changes: 8 additions & 0 deletions
8
...ms/testing/src/modules/file-attachment/file-attachment/file-attachment-harness-filters.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,8 @@ | ||
import { SkyHarnessFilters } from '@skyux/core/testing'; | ||
|
||
/** | ||
* A set of criteria that can be used to filter a list of `SkyFileAttachmentHarness` instances. | ||
* @internal | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-empty-object-type | ||
export interface SkyFileAttachmentHarnessFilters extends SkyHarnessFilters {} |
Oops, something went wrong.