diff --git a/frontend/app-development/features/dataModelling/DataModelling.test.tsx b/frontend/app-development/features/dataModelling/DataModelling.test.tsx index d4ee2ad42ae..cc836136fef 100644 --- a/frontend/app-development/features/dataModelling/DataModelling.test.tsx +++ b/frontend/app-development/features/dataModelling/DataModelling.test.tsx @@ -12,7 +12,7 @@ import type { QueryClient } from '@tanstack/react-query'; import userEvent from '@testing-library/user-event'; import { createApiErrorMock } from 'app-shared/mocks/apiErrorMock'; import { app, org } from '@studio/testing/testids'; - +import { user as userMock } from 'app-shared/mocks/mocks'; // workaround for https://jestjs.io/docs/26.x/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom Object.defineProperty(window, 'matchMedia', { writable: true, @@ -99,7 +99,9 @@ describe('DataModelling', () => { ); queryClient.setQueryData([QueryKey.DataModelsJson, org, app], [jsonMetadata1Mock]); queryClient.setQueryData([QueryKey.DataModelsXsd, org, app], []); + queryClient.setQueryData([QueryKey.CurrentUser], userMock); render({ generateModels }, queryClient); + const errorsPanel = screen.queryByText(textMock('api_errors.DM_01')); expect(errorsPanel).not.toBeInTheDocument(); @@ -125,6 +127,7 @@ describe('DataModelling', () => { ); queryClient.setQueryData([QueryKey.DataModelsJson, org, app], [jsonMetadata1Mock]); queryClient.setQueryData([QueryKey.DataModelsXsd, org, app], []); + queryClient.setQueryData([QueryKey.CurrentUser], userMock); render({ generateModels }, queryClient); const generateModelButton = screen.getByRole('button', { diff --git a/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.test.tsx b/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.test.tsx index c828409a9b2..68d4d6d8e50 100644 --- a/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.test.tsx +++ b/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.test.tsx @@ -100,6 +100,21 @@ describe('SchemaEditor', () => { expect(updatedModel.asArray().length).toBe(uiSchemaNodesMock.length + 1); }); + test('should show context menu when there are no nodes on root', async () => { + const jsonSchema: JsonSchema = { + [Keyword.Properties]: {}, + [Keyword.Definitions]: {}, + }; + const schemaModel = SchemaModel.fromArray(buildUiSchema(jsonSchema)); + renderEditor({ appContextProps: { schemaModel } }); + + const noItemsSelectedMessage = screen.getByText(textMock('schema_editor.no_item_selected')); + expect(noItemsSelectedMessage).toBeInTheDocument(); + + await clickOpenAddNodeButton(); + expect(screen.getByRole('dialog')).toBeInTheDocument(); + }); + test('should show context menu and trigger correct dispatch when adding text field on a specific node', async () => { const jsonSchema: JsonSchema = { [Keyword.Properties]: { mockItem: { [Keyword.Type]: FieldType.Object } }, diff --git a/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx b/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx index a83995b9836..9f8724ab104 100644 --- a/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx +++ b/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx @@ -19,8 +19,6 @@ export const SchemaEditor = () => { const { data: user } = useUserQuery(); const moveProperty = useMoveProperty(); const addReference = useAddReference(); - - if (schemaModel.isEmpty()) return null; const definitions: UiSchemaNodes = schemaModel.getDefinitions(); const selectedType = selectedTypePointer && schemaModel.getNode(selectedTypePointer); diff --git a/frontend/packages/schema-model/src/lib/SchemaModel.test.ts b/frontend/packages/schema-model/src/lib/SchemaModel.test.ts index 7975bec71b7..589ee59c103 100644 --- a/frontend/packages/schema-model/src/lib/SchemaModel.test.ts +++ b/frontend/packages/schema-model/src/lib/SchemaModel.test.ts @@ -84,20 +84,6 @@ describe('SchemaModel', () => { }); }); - describe('isEmpty', () => { - it('Returns true if only the root node is present', () => { - const rootNode = { ...rootNodeMock, children: [] }; - const schema = [rootNode]; - validateTestUiSchema(schema); - const emptyModel = SchemaModel.fromArray(schema); - expect(emptyModel.isEmpty()).toBe(true); - }); - - it('Returns false if additional nodes are present', () => { - expect(schemaModel.isEmpty()).toBe(false); - }); - }); - describe('getRootNode', () => { it('Returns the root node', () => { expect(schemaModel.getRootNode()).toEqual(rootNodeMock); diff --git a/frontend/packages/schema-model/src/lib/SchemaModel.ts b/frontend/packages/schema-model/src/lib/SchemaModel.ts index 33565447428..db1accaf46e 100644 --- a/frontend/packages/schema-model/src/lib/SchemaModel.ts +++ b/frontend/packages/schema-model/src/lib/SchemaModel.ts @@ -64,10 +64,6 @@ export class SchemaModel { return Array.from(this.nodeMap.values()); } - public isEmpty(): boolean { - return this.nodeMap.size <= 1; - } - public getRootNode(): FieldNode | CombinationNode { const rootNode = this.getNode(ROOT_POINTER); if (!isFieldOrCombination(rootNode))