Skip to content

Commit

Permalink
Remove ux-editor dependencies in shared
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasEng committed Jan 31, 2024
1 parent 67ae7b7 commit d784eb4
Show file tree
Hide file tree
Showing 18 changed files with 3,780 additions and 60 deletions.
2 changes: 1 addition & 1 deletion frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const config = {
},
transformIgnorePatterns: [
`node_modules(\\\\|/)(?!${packagesToTransform})`,
'frontend/packages/ux-editor/src/testing/schemas/',
'\\.schema\\.v1\\.json$',
],
reporters: ['default', 'jest-junit'],
moduleNameMapper: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React, { useCallback, useEffect, useState } from 'react';
import { ErrorMessage, HelpText } from '@digdir/design-system-react';
import classes from './FormField.module.css';
import { useText } from '../../../../ux-editor/src/hooks';
import {
validateProperty,
isPropertyRequired,
} from '../../../../ux-editor/src/utils/formValidationUtils';
import { useTranslation } from 'react-i18next';
import { validateProperty, isPropertyRequired } from '../../utils/formValidationUtils';
import type { TranslationKey } from 'language/type';
import type { JsonSchema } from 'app-shared/types/JsonSchema';

Expand Down Expand Up @@ -53,7 +50,7 @@ export const FormField = <T extends unknown, TT extends unknown>({
customValidationMessages,
renderField,
}: FormFieldProps<T, TT>): JSX.Element => {
const t = useText();
const { t } = useTranslation();

const [propertyId, setPropertyId] = useState(
schema && propertyPath ? `${schema.$id}#/${propertyPath}` : null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import { CheckmarkIcon, TrashIcon, PencilWritingIcon } from '@studio/icons';
import { useText } from '../../../../ux-editor/src/hooks';
import { useTranslation } from 'react-i18next';
import type { ButtonProps } from '@digdir/design-system-react';
import classes from './InputActionWrapper.module.css';
import cn from 'classnames';
Expand Down Expand Up @@ -37,7 +37,7 @@ export const InputActionWrapper = ({
onSaveClick,
...rest
}: InputActionWrapperProps): JSX.Element => {
const t = useText();
const { t } = useTranslation();
const defaultActions = actionGroupMap[mode || 'standBy'];
const [actions, setActions] = useState<AvailableAction[]>(defaultActions);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { queriesMock } from 'app-shared/mocks/queriesMock';
import { renderHookWithMockStore } from '../../../../ux-editor/src/testing/mocks';
import { waitFor } from '@testing-library/react';
import { useTextResourcesQuery } from '../../../../../app-development/hooks/queries';
import { renderHook } from '@testing-library/react';
import type { UpsertTextResourcesMutationArgs } from './useUpsertTextResourcesMutation';
import { useUpsertTextResourcesMutation } from './useUpsertTextResourcesMutation';
import type { ITextResource } from 'app-shared/types/global';
import { createQueryClientMock } from '../../mocks/queryClientMock';
import React from 'react';
import { ServicesContextProvider } from '../../contexts/ServicesContext';

// Test data:
const org = 'org';
Expand All @@ -17,7 +18,7 @@ const args: UpsertTextResourcesMutationArgs = { language, textResources };

describe('useUpsertTextResourcesMutation', () => {
test('Calls upsertTextResources with correct parameters', async () => {
const { result: upsertTextResources } = await renderUpsertTextResourcesMutation();
const { result: upsertTextResources } = renderUpsertTextResourcesMutation();
await upsertTextResources.current.mutateAsync(args);
expect(queriesMock.upsertTextResources).toHaveBeenCalledTimes(1);
expect(queriesMock.upsertTextResources).toHaveBeenCalledWith(org, app, language, {
Expand All @@ -26,10 +27,13 @@ describe('useUpsertTextResourcesMutation', () => {
});
});

const renderUpsertTextResourcesMutation = async () => {
const { result: texts } = renderHookWithMockStore()(() =>
useTextResourcesQuery(org, app),
).renderHookResult;
await waitFor(() => expect(texts.current.isSuccess).toBe(true));
return renderHookWithMockStore()(() => useUpsertTextResourcesMutation(org, app)).renderHookResult;
const renderUpsertTextResourcesMutation = () => {
const client = createQueryClientMock();
return renderHook(() => useUpsertTextResourcesMutation(org, app), {
wrapper: ({ children }) => (
<ServicesContextProvider {...queriesMock} client={client}>
{children}
</ServicesContextProvider>
),
});
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { queriesMock } from '../../mocks/queriesMock';
import { useTextResourcesQuery } from './useTextResourcesQuery';
import { renderHook, waitFor } from '@testing-library/react';
import React from 'react';
import { ServicesContextProvider } from '../../contexts/ServicesContext';
import { createQueryClientMock } from '../../mocks/queryClientMock';

// Test data:
const org = 'org';
const app = 'app';
const languagesMock = ['nb', 'nn', 'en'];

describe('useTextResourcesQuery', () => {
it('Calls getTextResources for each language', async () => {
const getTextLanguages = jest.fn().mockImplementation(() => Promise.resolve(languagesMock));
const client = createQueryClientMock();
const { result: resourcesResult } = renderHook(() => useTextResourcesQuery(org, app), {
wrapper: ({ children }) => (
<ServicesContextProvider
{...queriesMock}
getTextLanguages={getTextLanguages}
client={client}
>
{children}
</ServicesContextProvider>
),
});
await waitFor(() => expect(resourcesResult.current.isSuccess).toBe(true));
expect(getTextLanguages).toHaveBeenCalledTimes(1);
expect(getTextLanguages).toHaveBeenCalledWith(org, app);
expect(queriesMock.getTextResources).toHaveBeenCalledTimes(languagesMock.length);
languagesMock.forEach((language) => {
expect(queriesMock.getTextResources).toHaveBeenCalledWith(org, app, language);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
validate,
validateProperty,
} from './formValidationUtils';
import expressionSchema from '../testing/schemas/json/layout/expression.schema.v1.json';
import numberFormatSchema from '../testing/schemas/json/layout/number-format.schema.v1.json';
import layoutSchema from '../testing/schemas/json/layout/layout.schema.v1.json';
import inputSchema from '../testing/schemas/json/component/Input.schema.v1.json';
import commonDefsSchema from '../testing/schemas/json/component/common-defs.schema.v1.json';
import expressionSchema from './test-data/expression.schema.v1.json';
import numberFormatSchema from './test-data/number-format.schema.v1.json';
import layoutSchema from './test-data/layout.schema.v1.json';
import inputSchema from './test-data/Input.schema.v1.json';
import commonDefsSchema from './test-data/common-defs.schema.v1.json';

describe('formValidationUtils', () => {
beforeAll(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './formValidationUtils';
Loading

0 comments on commit d784eb4

Please sign in to comment.