Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandhya Raja Sabeson committed Jan 15, 2025
1 parent 40230b2 commit 131faf5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Basic file drop demo', () => {
);
await expectAsync(harness.isStacked()).toBeResolvedTo(true);

const linkUploadHarness = await harness.getLinkUpload();
const linkUploadHarness = await harness.getLinkUploadHarness();

await expectAsync(linkUploadHarness.getHintText()).toBeResolvedTo(
'Start with http:// or https://',
Expand Down Expand Up @@ -95,7 +95,10 @@ describe('Basic file drop demo', () => {
).toBeResolvedTo(false);
expect(formControl.valid).toBe(true);

await harness.uploadLink('link.to.upload');
const uploadLinkHarness = await harness.getLinkUploadHarness();
await uploadLinkHarness.enterText('foo.bar');
await uploadLinkHarness.clickDoneButton();

expect(formControl.value?.length).toBe(4);
await expectAsync(
harness.hasCustomError('maxNumberOfFilesReached'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('File drop harness', () => {
);
spyOn(input, 'click');

await harness.clickFileUploadButton();
await harness.clickFileDropTarget();
expect(input.click).toHaveBeenCalled();
});

Expand Down Expand Up @@ -211,18 +211,6 @@ describe('File drop harness', () => {
await expectAsync(harness.getLabelText()).toBeResolvedTo('File upload');
});

it('should load a file', async () => {
const { fixture, harness } = await setupTest();

await harness.uploadLink('foo.bar');

expect(fixture.componentInstance.fileDrop.value).toEqual([
{
url: 'foo.bar',
},
]);
});

it('should get whether the label is hidden', async () => {
const { fixture, harness } = await setupTest();

Expand Down Expand Up @@ -262,7 +250,7 @@ describe('File drop harness', () => {
fixture.componentInstance.required = true;
fixture.detectChanges();

const input = await (await harness.getLinkUpload()).getInput();
const input = await (await harness.getLinkUploadHarness()).getInput();

await input.focus();
await input.blur();
Expand Down Expand Up @@ -349,7 +337,7 @@ describe('File drop harness', () => {
fixture.detectChanges();

await expectAsync(
(await harness.getLinkUpload()).getAriaLabel(),
(await harness.getLinkUploadHarness()).getAriaLabel(),
).toBeResolvedTo('upload aria-label');
});

Expand All @@ -360,15 +348,15 @@ describe('File drop harness', () => {
fixture.detectChanges();

await expectAsync(
(await harness.getLinkUpload()).getHintText(),
(await harness.getLinkUploadHarness()).getHintText(),
).toBeResolvedTo('link hint text');
});

it('should throw an error clicking a disabled upload link button', async () => {
const { harness } = await setupTest();

await expectAsync(
(await harness.getLinkUpload()).clickDoneButton(),
(await harness.getLinkUploadHarness()).clickDoneButton(),
).toBeRejectedWithError('Done button is disabled and cannot be clicked.');
});

Expand All @@ -378,10 +366,25 @@ describe('File drop harness', () => {
fixture.componentInstance.allowLinks = false;
fixture.detectChanges();

await expectAsync(harness.getLinkUpload()).toBeRejectedWithError(
await expectAsync(harness.getLinkUploadHarness()).toBeRejectedWithError(
'Link upload cannot be found. Set `allowLinks` property to `true`.',
);
});

it('should upload a link', async () => {
const { fixture, harness } = await setupTest();

const linkUploadHarness = await harness.getLinkUploadHarness();

await linkUploadHarness.enterText('foo.bar');
await linkUploadHarness.clickDoneButton();

expect(fixture.componentInstance.fileDrop.value).toEqual([
{
url: 'foo.bar',
},
]);
});
});

describe('sky file item harness', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export class SkyFileDropHarness extends SkyComponentHarness {
}

/**
* Clicks the file upload button.
* Clicks the file drop target.
*/
public async clickFileUploadButton(): Promise<void> {
public async clickFileDropTarget(): Promise<void> {
return await (await this.#fileUploadButton()).click();
}

Expand Down Expand Up @@ -102,8 +102,8 @@ export class SkyFileDropHarness extends SkyComponentHarness {
/**
* Gets the link upload harness.
*/
public async getLinkUpload(): Promise<SkyFileDropLinkUploadHarness> {
return await this.#getLinkUpload();
public async getLinkUploadHarness(): Promise<SkyFileDropLinkUploadHarness> {
return await this.#getLinkUploadHarness();
}

/**
Expand Down Expand Up @@ -178,14 +178,6 @@ export class SkyFileDropHarness extends SkyComponentHarness {
return await this.#dropFiles(files);
}

/**
* Uploads a link.
*/
public async uploadLink(link: string): Promise<void> {
await (await this.getLinkUpload()).enterLink(link);
await (await this.getLinkUpload()).clickDoneButton();
}

async #dropFiles(files: File[] | null): Promise<void> {
const dropTarget = await this.#getDropTarget();

Expand Down Expand Up @@ -216,7 +208,7 @@ export class SkyFileDropHarness extends SkyComponentHarness {
throw Error('No help inline found.');
}

async #getLinkUpload(): Promise<SkyFileDropLinkUploadHarness> {
async #getLinkUploadHarness(): Promise<SkyFileDropLinkUploadHarness> {
const linkUpload = await this.locatorForOptional(
SkyFileDropLinkUploadHarness,
)();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SkyInputBoxHarness } from '../../input-box/input-box-harness';
import { SkyFileDropLinkUploadInputHarness } from './file-drop-link-upload-input-harness';

/**
* Harness for interacting with a file drop link upload component in tests.
* Harness for interacting with file drop component's link upload feature in tests.
*/
export class SkyFileDropLinkUploadHarness extends SkyComponentHarness {
/**
Expand All @@ -28,9 +28,9 @@ export class SkyFileDropLinkUploadHarness extends SkyComponentHarness {
}

/**
* Sets the input value.
* Enters text into the link upload input.
*/
public async enterLink(link: string): Promise<void> {
public async enterText(link: string): Promise<void> {
return await (await this.#input()).setValue(link);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { SkyHarnessFilters } from '@skyux/core/testing';

/**
* A set of criteria that can be used to filter a list of `SkyFileItemHarness` instances.
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-empty-object-type
export interface SkyFileItemHarnessFilters extends SkyHarnessFilters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class SkyFileItemHarness extends ComponentHarness {
filters: SkyFileItemHarnessFilters,
): HarnessPredicate<SkyFileItemHarness> {
return new HarnessPredicate(SkyFileItemHarness, filters).addOption(
'name',
'fileName',
filters.fileName,
async (harness, fileName) => {
const harnessFileName = await harness.getFileName();
Expand Down

0 comments on commit 131faf5

Please sign in to comment.