d07c27a907
Replace generic JSON scalar with a typed GraphQL union CommandMenuItemPayload (PathNavigationPayload | ObjectMetadataNavigationPayload) for the CommandMenuItem.payload field
258 lines
8.6 KiB
TypeScript
258 lines
8.6 KiB
TypeScript
import { faker } from '@faker-js/faker';
|
|
import { createCommandMenuItem } from 'test/integration/metadata/suites/command-menu-item/utils/create-command-menu-item.util';
|
|
import { deleteCommandMenuItem } from 'test/integration/metadata/suites/command-menu-item/utils/delete-command-menu-item.util';
|
|
import { createFrontComponent } from 'test/integration/metadata/suites/front-component/utils/create-front-component.util';
|
|
import { deleteFrontComponent } from 'test/integration/metadata/suites/front-component/utils/delete-front-component.util';
|
|
import { seedBuiltFrontComponentFile } from 'test/integration/metadata/suites/front-component/utils/seed-built-front-component-file.util';
|
|
import { findManyObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/find-many-object-metadata.util';
|
|
import { jestExpectToBeDefined } from 'test/utils/jest-expect-to-be-defined.util.test';
|
|
|
|
import { CommandMenuItemAvailabilityType } from 'src/engine/metadata-modules/command-menu-item/enums/command-menu-item-availability-type.enum';
|
|
import { EngineComponentKey } from 'src/engine/metadata-modules/command-menu-item/enums/engine-component-key.enum';
|
|
|
|
describe('CommandMenuItem creation should succeed', () => {
|
|
let createdCommandMenuItemId: string;
|
|
let createdFrontComponentId: string | undefined;
|
|
let cleanupBuiltFile: (() => void) | undefined;
|
|
let companyObjectMetadataId: string;
|
|
let personObjectMetadataId: string;
|
|
|
|
beforeAll(async () => {
|
|
const { cleanup } = await seedBuiltFrontComponentFile({
|
|
builtComponentPath: 'src/front-components/index.mjs',
|
|
});
|
|
|
|
cleanupBuiltFile = cleanup;
|
|
|
|
const { objects } = await findManyObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
filter: {},
|
|
paging: { first: 1000 },
|
|
},
|
|
gqlFields: `
|
|
id
|
|
nameSingular
|
|
`,
|
|
});
|
|
|
|
jestExpectToBeDefined(objects);
|
|
|
|
const companyObjectMetadata = objects.find(
|
|
(object: { nameSingular: string }) => object.nameSingular === 'company',
|
|
);
|
|
const personObjectMetadata = objects.find(
|
|
(object: { nameSingular: string }) => object.nameSingular === 'person',
|
|
);
|
|
|
|
jestExpectToBeDefined(companyObjectMetadata);
|
|
jestExpectToBeDefined(personObjectMetadata);
|
|
|
|
companyObjectMetadataId = companyObjectMetadata.id;
|
|
personObjectMetadataId = personObjectMetadata.id;
|
|
});
|
|
|
|
afterAll(async () => {
|
|
cleanupBuiltFile?.();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
if (createdCommandMenuItemId) {
|
|
await deleteCommandMenuItem({
|
|
expectToFail: false,
|
|
input: { id: createdCommandMenuItemId },
|
|
});
|
|
createdCommandMenuItemId = undefined as unknown as string;
|
|
}
|
|
if (createdFrontComponentId) {
|
|
await deleteFrontComponent({
|
|
expectToFail: false,
|
|
input: { id: createdFrontComponentId },
|
|
});
|
|
createdFrontComponentId = undefined;
|
|
}
|
|
});
|
|
|
|
it('should create a basic command menu item with minimal input', async () => {
|
|
const workflowVersionId = faker.string.uuid();
|
|
|
|
const { data } = await createCommandMenuItem({
|
|
expectToFail: false,
|
|
input: {
|
|
workflowVersionId,
|
|
engineComponentKey: EngineComponentKey.TRIGGER_WORKFLOW_VERSION,
|
|
label: 'Test Command Menu Item',
|
|
},
|
|
});
|
|
|
|
createdCommandMenuItemId = data?.createCommandMenuItem?.id;
|
|
|
|
expect(data.createCommandMenuItem).toMatchObject({
|
|
id: expect.any(String),
|
|
workflowVersionId,
|
|
label: 'Test Command Menu Item',
|
|
icon: null,
|
|
isPinned: false,
|
|
availabilityType: CommandMenuItemAvailabilityType.GLOBAL,
|
|
availabilityObjectMetadataId: null,
|
|
});
|
|
});
|
|
|
|
it('should create command menu item with all optional fields', async () => {
|
|
const workflowVersionId = faker.string.uuid();
|
|
|
|
const { data } = await createCommandMenuItem({
|
|
expectToFail: false,
|
|
input: {
|
|
workflowVersionId,
|
|
engineComponentKey: EngineComponentKey.TRIGGER_WORKFLOW_VERSION,
|
|
label: 'Full Command Menu Item',
|
|
icon: 'IconSparkles',
|
|
isPinned: true,
|
|
availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,
|
|
availabilityObjectMetadataId: companyObjectMetadataId,
|
|
},
|
|
});
|
|
|
|
createdCommandMenuItemId = data?.createCommandMenuItem?.id;
|
|
|
|
expect(data.createCommandMenuItem).toMatchObject({
|
|
id: expect.any(String),
|
|
workflowVersionId,
|
|
label: 'Full Command Menu Item',
|
|
icon: 'IconSparkles',
|
|
isPinned: true,
|
|
availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,
|
|
availabilityObjectMetadataId: companyObjectMetadataId,
|
|
});
|
|
});
|
|
|
|
it('should create command menu item with BULK_RECORDS availability', async () => {
|
|
const workflowVersionId = faker.string.uuid();
|
|
|
|
const { data } = await createCommandMenuItem({
|
|
expectToFail: false,
|
|
input: {
|
|
workflowVersionId,
|
|
engineComponentKey: EngineComponentKey.TRIGGER_WORKFLOW_VERSION,
|
|
label: 'Bulk Records Command',
|
|
availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,
|
|
availabilityObjectMetadataId: personObjectMetadataId,
|
|
},
|
|
});
|
|
|
|
createdCommandMenuItemId = data?.createCommandMenuItem?.id;
|
|
|
|
expect(data.createCommandMenuItem).toMatchObject({
|
|
id: expect.any(String),
|
|
workflowVersionId,
|
|
label: 'Bulk Records Command',
|
|
availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,
|
|
availabilityObjectMetadataId: personObjectMetadataId,
|
|
});
|
|
});
|
|
|
|
it('should create command menu item with GLOBAL availability (default)', async () => {
|
|
const workflowVersionId = faker.string.uuid();
|
|
|
|
const { data } = await createCommandMenuItem({
|
|
expectToFail: false,
|
|
input: {
|
|
workflowVersionId,
|
|
engineComponentKey: EngineComponentKey.TRIGGER_WORKFLOW_VERSION,
|
|
label: 'Global Command',
|
|
},
|
|
});
|
|
|
|
createdCommandMenuItemId = data?.createCommandMenuItem?.id;
|
|
|
|
expect(data.createCommandMenuItem).toMatchObject({
|
|
id: expect.any(String),
|
|
workflowVersionId,
|
|
label: 'Global Command',
|
|
availabilityType: CommandMenuItemAvailabilityType.GLOBAL,
|
|
});
|
|
});
|
|
|
|
it('should create NAVIGATION command menu item with path payload', async () => {
|
|
const { data } = await createCommandMenuItem({
|
|
expectToFail: false,
|
|
input: {
|
|
engineComponentKey: EngineComponentKey.NAVIGATION,
|
|
label: 'Go to Settings',
|
|
payload: { path: '/settings/accounts' },
|
|
},
|
|
});
|
|
|
|
createdCommandMenuItemId = data?.createCommandMenuItem?.id;
|
|
|
|
expect(data.createCommandMenuItem).toMatchObject({
|
|
id: expect.any(String),
|
|
engineComponentKey: EngineComponentKey.NAVIGATION,
|
|
label: 'Go to Settings',
|
|
payload: {
|
|
path: '/settings/accounts',
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should create NAVIGATION command menu item with objectMetadataItemId payload', async () => {
|
|
const { data } = await createCommandMenuItem({
|
|
expectToFail: false,
|
|
input: {
|
|
engineComponentKey: EngineComponentKey.NAVIGATION,
|
|
label: 'Go to Companies',
|
|
payload: { objectMetadataItemId: companyObjectMetadataId },
|
|
},
|
|
});
|
|
|
|
createdCommandMenuItemId = data?.createCommandMenuItem?.id;
|
|
|
|
expect(data.createCommandMenuItem).toMatchObject({
|
|
id: expect.any(String),
|
|
engineComponentKey: EngineComponentKey.NAVIGATION,
|
|
label: 'Go to Companies',
|
|
payload: {
|
|
objectMetadataItemId: companyObjectMetadataId,
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should create command menu item with frontComponentId', async () => {
|
|
const { data: frontComponentData } = await createFrontComponent({
|
|
expectToFail: false,
|
|
input: {
|
|
name: 'Test Front Component',
|
|
componentName: 'TestFrontComponent',
|
|
sourceComponentPath: 'src/front-components/index.tsx',
|
|
builtComponentPath: 'src/front-components/index.mjs',
|
|
builtComponentChecksum: 'abc123',
|
|
},
|
|
});
|
|
|
|
createdFrontComponentId = frontComponentData?.createFrontComponent?.id;
|
|
jestExpectToBeDefined(createdFrontComponentId);
|
|
|
|
const { data } = await createCommandMenuItem({
|
|
expectToFail: false,
|
|
input: {
|
|
frontComponentId: createdFrontComponentId,
|
|
engineComponentKey: EngineComponentKey.FRONT_COMPONENT_RENDERER,
|
|
label: 'Front Component Command',
|
|
},
|
|
});
|
|
|
|
createdCommandMenuItemId = data?.createCommandMenuItem?.id;
|
|
|
|
expect(data.createCommandMenuItem).toMatchObject({
|
|
id: expect.any(String),
|
|
frontComponentId: createdFrontComponentId,
|
|
label: 'Front Component Command',
|
|
frontComponent: {
|
|
id: createdFrontComponentId,
|
|
name: 'Test Front Component',
|
|
},
|
|
});
|
|
});
|
|
});
|