Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Gebov committed Dec 19, 2023
1 parent b4413c3 commit 17c100d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/nextjs-framework/rest-sdk/rest-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export class RestService {
public static uploadItem(args: UploadMediaArgs): Promise<SdkItem> {
const wholeUrl = `${RestService.buildItemBaseUrl(args.Type)}${RestService.buildQueryParams(args.AdditionalQueryParams)}`;
const headers = args.AdditionalHeaders || {};
const data = Object.assign({}, args.Fields, { Title: args.Title, ParentId: args.ParentId });
const data = Object.assign({}, args.Fields, { Title: args.Title, ParentId: args.ParentId, UrlName: args.UrlName });

headers['X-Sf-Properties'] = JSON.stringify(data);
headers['X-File-Name'] = args.FileName;
Expand Down
1 change: 1 addition & 0 deletions src/nextjs-framework/rest-sdk/services/args/upload-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CommonArgs } from './common-args';

export interface UploadMediaArgs extends CommonArgs {
Title: string;
UrlName?: string;
FileName: string;
ParentId: string;
Fields?: Dictionary
Expand Down
25 changes: 24 additions & 1 deletion tests/__snapshots__/image.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,32 @@ exports[`Image rendered with original size 1`] = `
<span>
<img
loading="lazy"
src="/images/default-source/default-album/imagee7f8cd11-dafa-41c6-95bb-7100514c09dd.jpg?sfvrsn=87c70c89_2"
src="https://systemvalforsnapshot"
title="custom title"
/>
</span>
</div>
`;

exports[`Image with selected image item 1`] = `
<div>
<picture
class="d-inline-block"
>
<source
height="160"
media="(max-width: 160px)"
srcset="https://systemvalforsnapshot"
type="image/jpeg"
width="160"
/>
<img
alt=""
class="d-inline-block"
loading="lazy"
src="https://systemvalforsnapshot"
title="Image"
/>
</picture>
</div>
`;
10 changes: 7 additions & 3 deletions tests/image.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { ImageEntity } from '../src/nextjs-framework/widgets/image/image';
import { ImageDisplayMode } from '../src/nextjs-framework/widgets/image/interfaces/ImageDisplayMode';

let sdkItem: SdkItem;
beforeAll(async () => {
beforeEach(async () => {
const base64Image = fs.readFileSync('./tests/data/1.jpg', { encoding: 'base64' });

let libraryId = '4BA7AD46-F29B-4e65-BE17-9BF7CE5BA1FB';
sdkItem = await RestService.uploadItem({
Title: 'Image',
UrlName: 'image-test',
Type: RestSdkTypes.Image,
ContentType: 'image/jpeg',
FileName: 'test.jpg',
Expand All @@ -34,6 +35,9 @@ test('Image rendered with original size', async () => {
},
assert: async (element) => {
await waitFor(() => {
const imgElement = element.querySelector('img');
expect(imgElement?.getAttribute('src')).toBeDefined();
imgElement?.setAttribute('src', 'https://systemvalforsnapshot');
expect(element).toMatchSnapshot();
});
}
Expand All @@ -55,11 +59,11 @@ test('Image with selected image item', async () => {

// remove dynamic elements from snapshot assert
expect(sourceElement?.getAttribute('srcset')).toBeDefined();
sourceElement?.removeAttribute('srcset');
sourceElement?.setAttribute('srcset', 'https://systemvalforsnapshot');

const imgElement = element.querySelector('img');
expect(imgElement?.getAttribute('src')).toBeDefined();
imgElement?.removeAttribute('src');
imgElement?.setAttribute('src', 'https://systemvalforsnapshot');

expect(element).toMatchSnapshot();
});
Expand Down

0 comments on commit 17c100d

Please sign in to comment.