Skip to content

Commit 1ea3bf3

Browse files
committed
fix PR comments
1 parent e33e8d1 commit 1ea3bf3

File tree

7 files changed

+69
-18
lines changed

7 files changed

+69
-18
lines changed

frontend/libs/studio-components/src/components/StudioIconTextfield/StudioIconTextfield.test.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import type { RenderResult } from '@testing-library/react';
23
import { render, screen } from '@testing-library/react';
34
import { StudioIconTextfield } from './StudioIconTextfield';
45
import type { StudioIconTextfieldProps } from './StudioIconTextfield';
@@ -7,6 +8,8 @@ import userEvent from '@testing-library/user-event';
78
import { testCustomAttributes } from '../../test-utils/testCustomAttributes';
89

910
describe('StudioIconTextfield', () => {
11+
afterEach(jest.clearAllMocks);
12+
1013
it('render the icon', async () => {
1114
renderStudioIconTextfield();
1215
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
@@ -40,6 +43,6 @@ const defaultProps: StudioIconTextfieldProps = {
4043
onChange,
4144
};
4245

43-
const renderStudioIconTextfield = (props: Partial<StudioIconTextfieldProps> = {}) => {
46+
const renderStudioIconTextfield = (props: Partial<StudioIconTextfieldProps> = {}): RenderResult => {
4447
return render(<StudioIconTextfield {...defaultProps} {...props} />);
4548
};

frontend/libs/studio-components/src/components/StudioToggleableTextfield/StudioTextfieldToggleView/StudioTextfieldToggleView.test.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import type { RenderResult } from '@testing-library/react';
23
import { render, screen } from '@testing-library/react';
34
import { StudioTextfieldToggleView } from './StudioTextfieldToggleView';
45
import type { StudioTextfieldToggleViewProps } from './StudioTextfieldToggleView';
@@ -44,6 +45,8 @@ const defaultProps: StudioTextfieldToggleViewProps = {
4445
Icon: KeyVerticalIcon,
4546
};
4647

47-
const renderStudioTextfieldToggleView = (props: Partial<StudioTextfieldToggleViewProps> = {}) => {
48+
const renderStudioTextfieldToggleView = (
49+
props: Partial<StudioTextfieldToggleViewProps> = {},
50+
): RenderResult => {
4851
return render(<StudioTextfieldToggleView {...defaultProps} {...props} />);
4952
};

frontend/libs/studio-components/src/components/StudioToggleableTextfield/StudioToggleableTextfield.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('StudioToggleableTextfield', () => {
6262
renderStudioTextField({ error });
6363
await user.click(screen.getByRole('button', { name: value }));
6464
await user.tab();
65-
expect(screen.getByRole('textbox', { name: label })).toHaveAttribute('aria-invalid', 'true');
65+
expect(screen.getByRole('textbox', { name: label })).toBeInvalid();
6666
expect(screen.getByText(error)).toBeInTheDocument();
6767
expect(screen.queryByRole('button', { name: value })).not.toBeInTheDocument();
6868
});

frontend/libs/studio-components/src/components/StudioToggleableTextfield/StudioToggleableTextfield.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import React, { forwardRef, useEffect, useState } from 'react';
22
import { StudioTextfieldToggleView } from './StudioTextfieldToggleView';
3+
import type { StudioIconTextfieldProps } from '../StudioIconTextfield';
34
import { StudioIconTextfield } from '../StudioIconTextfield';
45
import { KeyVerticalIcon } from '../../../../studio-icons';
56

67
export type StudioToggleableTextfieldProps = {
78
customValidation?: (value: string) => string | undefined;
8-
error?: string;
9-
Icon?: React.ComponentType<React.SVGProps<SVGSVGElement>>;
10-
label: string;
11-
onBlur?: (event: React.ChangeEvent<HTMLInputElement>) => void;
12-
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
139
onIsViewMode?: (isViewMode: boolean) => void;
14-
title?: string;
15-
value: string;
16-
};
10+
} & StudioIconTextfieldProps;
1711

1812
export const StudioToggleableTextfield = forwardRef<HTMLDivElement, StudioToggleableTextfieldProps>(
1913
(

frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/EditComponentIdRow/EditComponentIdRow.test.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import type { RenderResult } from '@testing-library/react';
23
import { screen } from '@testing-library/react';
34
import { renderWithProviders } from '../../../../testing/mocks';
45
import { EditComponentIdRow, type EditComponentIdRowProps } from './EditComponentIdRow';
@@ -130,7 +131,9 @@ const defaultProps: EditComponentIdRowProps = {
130131
helpText,
131132
};
132133

133-
const renderEditComponentIdRow = async (props: Partial<EditComponentIdRowProps> = {}) => {
134+
const renderEditComponentIdRow = async (
135+
props: Partial<EditComponentIdRowProps> = {},
136+
): RenderResult => {
134137
queryClientMock.setQueryData([QueryKey.FormLayouts, org, app, layoutSetName], layouts);
135138
return renderWithProviders(<EditComponentIdRow {...defaultProps} {...props} />);
136139
};

frontend/packages/ux-editor/src/components/config/editModal/EditImage/ExternalImage/ExternalImage.test.tsx

+47-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
33
import { renderWithProviders } from '../../../../../testing/mocks';
44
import type { ExternalImageProps } from './ExternalImage';
5-
import { ExternalImage } from './ExternalImage';
5+
import { calculateViewValue, ExternalImage } from './ExternalImage';
66
import { textMock } from '@studio/testing/mocks/i18nMock';
77
import { createQueryClientMock } from 'app-shared/mocks/queryClientMock';
88
import { QueryKey } from 'app-shared/types/QueryKey';
@@ -252,3 +252,49 @@ const renderExternalImage = (
252252
) => {
253253
renderWithProviders(<ExternalImage {...defaultProps} {...props} />, { queries, queryClient });
254254
};
255+
256+
describe('calculateViewValue', () => {
257+
const noUrlText = 'No URL Provided';
258+
259+
it('should return the URL when URL is provided and view mode is false', () => {
260+
const url = 'http://example.com';
261+
const result = calculateViewValue(url, noUrlText, false);
262+
expect(result).toBe(url);
263+
});
264+
265+
it('should return the URL when URL is provided and view mode is true', () => {
266+
const url = 'http://example.com';
267+
const result = calculateViewValue(url, noUrlText, true);
268+
expect(result).toBe(url);
269+
});
270+
271+
it('should return undefined when URL is empty and view mode is false', () => {
272+
const result = calculateViewValue('', noUrlText, false);
273+
expect(result).toBe(undefined);
274+
});
275+
276+
it('should return noUrlText when URL is empty and view mode is true', () => {
277+
const result = calculateViewValue('', noUrlText, true);
278+
expect(result).toBe(noUrlText);
279+
});
280+
281+
it('should return undefined when URL is undefined and view mode is false', () => {
282+
const result = calculateViewValue(undefined, noUrlText, false);
283+
expect(result).toBe(undefined);
284+
});
285+
286+
it('should return noUrlText when URL is undefined and view mode is true', () => {
287+
const result = calculateViewValue(undefined, noUrlText, true);
288+
expect(result).toBe(noUrlText);
289+
});
290+
291+
it('should return undefined when URL is equal to noUrlText and view mode is false', () => {
292+
const result = calculateViewValue(noUrlText, noUrlText, false);
293+
expect(result).toBe(undefined);
294+
});
295+
296+
it('should return noUrlText when URL is equal to noUrlText and view mode is true', () => {
297+
const result = calculateViewValue(noUrlText, noUrlText, true);
298+
expect(result).toBe(noUrlText);
299+
});
300+
});

frontend/packages/ux-editor/src/components/config/editModal/EditImage/ExternalImage/ExternalImage.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,16 @@ const EditUrl = ({ url, existingImageUrl, onBlur }: EditUrlProps): React.ReactEl
9292
);
9393
};
9494

95-
const isBLurInitialWithEmptyInput = (existingUrl: string, newUrl: string) =>
95+
const isBLurInitialWithEmptyInput = (existingUrl: string | undefined, newUrl: string): boolean =>
9696
newUrl === '' && existingUrl === undefined;
9797

98-
const isInitialUrlProvided = (url: string, existingImageUrl: string) =>
99-
url !== undefined || !!existingImageUrl;
98+
const isInitialUrlProvided = (
99+
url: string | undefined,
100+
existingImageUrl: string | undefined,
101+
): boolean => url !== undefined || !!existingImageUrl;
100102

101-
const calculateViewValue = (
102-
url: string,
103+
export const calculateViewValue = (
104+
url: string | undefined,
103105
noUrlText: string,
104106
isViewMode: boolean,
105107
): string | undefined => {

0 commit comments

Comments
 (0)