@aws-amplify/amplify-util-uibuilder 1.5.0 → 1.6.0-cdkv2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/amplify-plugin.json +10 -3
  3. package/lib/clients/amplify-studio-client.d.ts +13 -2
  4. package/lib/clients/amplify-studio-client.d.ts.map +1 -1
  5. package/lib/clients/amplify-studio-client.js +85 -17
  6. package/lib/clients/amplify-studio-client.js.map +1 -1
  7. package/lib/commands/generateComponents.d.ts.map +1 -1
  8. package/lib/commands/generateComponents.js +33 -15
  9. package/lib/commands/generateComponents.js.map +1 -1
  10. package/lib/commands/help.d.ts +1 -1
  11. package/lib/commands/help.d.ts.map +1 -1
  12. package/lib/commands/help.js +2 -2
  13. package/lib/commands/help.js.map +1 -1
  14. package/lib/commands/utils/codegenResources.d.ts +12 -2
  15. package/lib/commands/utils/codegenResources.d.ts.map +1 -1
  16. package/lib/commands/utils/codegenResources.js +70 -3
  17. package/lib/commands/utils/codegenResources.js.map +1 -1
  18. package/lib/commands/utils/featureFlags.d.ts +2 -0
  19. package/lib/commands/utils/featureFlags.d.ts.map +1 -0
  20. package/lib/commands/utils/featureFlags.js +35 -0
  21. package/lib/commands/utils/featureFlags.js.map +1 -0
  22. package/lib/commands/utils/getUiBuilderComponentsPath.d.ts.map +1 -1
  23. package/lib/commands/utils/getUiBuilderComponentsPath.js.map +1 -1
  24. package/lib/commands/utils/shouldRenderComponents.d.ts +1 -1
  25. package/lib/commands/utils/shouldRenderComponents.d.ts.map +1 -1
  26. package/lib/commands/utils/shouldRenderComponents.js +14 -8
  27. package/lib/commands/utils/shouldRenderComponents.js.map +1 -1
  28. package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts +12 -20
  29. package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts.map +1 -1
  30. package/lib/commands/utils/syncAmplifyUiBuilderComponents.js +36 -3
  31. package/lib/commands/utils/syncAmplifyUiBuilderComponents.js.map +1 -1
  32. package/lib/commands/version.d.ts +1 -1
  33. package/lib/commands/version.d.ts.map +1 -1
  34. package/lib/commands/version.js +2 -2
  35. package/lib/commands/version.js.map +1 -1
  36. package/lib/event-handlers/handle-PostEnvAdd.d.ts +1 -1
  37. package/lib/event-handlers/handle-PostEnvAdd.d.ts.map +1 -1
  38. package/lib/event-handlers/handle-PostEnvAdd.js +4 -6
  39. package/lib/event-handlers/handle-PostEnvAdd.js.map +1 -1
  40. package/lib/event-handlers/handle-PostPull.d.ts +1 -1
  41. package/lib/event-handlers/handle-PostPull.d.ts.map +1 -1
  42. package/lib/event-handlers/handle-PostPull.js +4 -3
  43. package/lib/event-handlers/handle-PostPull.js.map +1 -1
  44. package/lib/event-handlers/handle-PostPush.d.ts +3 -0
  45. package/lib/event-handlers/handle-PostPush.d.ts.map +1 -0
  46. package/lib/event-handlers/handle-PostPush.js +15 -0
  47. package/lib/event-handlers/handle-PostPush.js.map +1 -0
  48. package/package.json +7 -6
  49. package/src/__tests__/cloneComponentsFromEnv.test.ts +17 -6
  50. package/src/__tests__/createUiBuilderComponent.test.ts +21 -3
  51. package/src/__tests__/generateComponents.test.ts +43 -15
  52. package/src/__tests__/getAmplifyDataSchema.test.ts +51 -19
  53. package/src/__tests__/shouldRenderComponents.test.ts +51 -4
  54. package/src/__tests__/syncAmplifyUiComponents.test.ts +113 -8
  55. package/src/__tests__/utils.ts +70 -0
  56. package/src/clients/amplify-studio-client.ts +157 -69
  57. package/src/commands/generateComponents.ts +43 -16
  58. package/src/commands/help.ts +5 -2
  59. package/src/commands/utils/codegenResources.ts +108 -4
  60. package/src/commands/utils/featureFlags.ts +62 -0
  61. package/src/commands/utils/getUiBuilderComponentsPath.ts +7 -2
  62. package/src/commands/utils/shouldRenderComponents.ts +20 -8
  63. package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +76 -29
  64. package/src/commands/version.ts +5 -2
  65. package/src/event-handlers/handle-PostEnvAdd.ts +8 -6
  66. package/src/event-handlers/handle-PostPull.ts +7 -3
  67. package/src/event-handlers/handle-PostPush.ts +15 -0
  68. package/tsconfig.tsbuildinfo +1 -1
  69. package/src/__tests__/handleEvents.test.ts +0 -21
@@ -1,6 +1,7 @@
1
1
  import aws from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies
2
- import { AmplifyCategories, AmplifySupportedService } from 'amplify-cli-core'; // eslint-disable-line import/no-extraneous-dependencies
2
+ import { AmplifyCategories, AmplifySupportedService, FeatureFlags } from 'amplify-cli-core'; // eslint-disable-line import/no-extraneous-dependencies
3
3
  import { printer } from 'amplify-prompts'; // eslint-disable-line import/no-extraneous-dependencies
4
+ import { mocked } from 'ts-jest/utils';
4
5
  import { AmplifyStudioClient } from '../clients';
5
6
  import { getAmplifyDataSchema } from '../commands/utils';
6
7
 
@@ -17,14 +18,19 @@ jest.mock('amplify-cli-core', () => ({
17
18
  },
18
19
  },
19
20
  })),
21
+ getCLIJSON: jest.fn().mockReturnValue({ features: { graphqltransformer: { transformerversion: 1 } } }),
22
+ setCLIJSON: jest.fn(),
20
23
  },
21
24
  FeatureFlags: {
22
- getBoolean: () => false,
23
- getNumber: () => 0,
25
+ getBoolean: () => true,
26
+ getNumber: jest.fn(),
27
+ reloadValues: jest.fn(),
24
28
  },
25
29
  }));
26
30
  jest.mock('amplify-prompts');
27
31
 
32
+ const mockedFeatureFlags = mocked(FeatureFlags);
33
+
28
34
  const getMockedSchema = jest.fn(
29
35
  // eslint-disable-next-line no-useless-escape, spellcheck/spell-checker
30
36
  () => `export const schema = {\n \"models\": {\n \"Blog\": {\n \"name\": \"Blog\",\n \"fields\": {\n \"id\": {\n \"name\": \"id\",\n \"isArray\": false,\n \"type\": \"ID\",\n \"isRequired\": true,\n \"attributes\": []\n },\n \"title\": {\n \"name\": \"title\",\n \"isArray\": false,\n \"type\": \"String\",\n \"isRequired\": false,\n \"attributes\": []\n },\n \"content\": {\n \"name\": \"content\",\n \"isArray\": false,\n \"type\": \"String\",\n \"isRequired\": false,\n \"attributes\": []\n },\n \"status\": {\n \"name\": \"status\",\n \"isArray\": false,\n \"type\": {\n \"enum\": \"Status\"\n },\n \"isRequired\": false,\n \"attributes\": []\n },\n \"createdAt\": {\n \"name\": \"createdAt\",\n \"isArray\": false,\n \"type\": \"AWSDateTime\",\n \"isRequired\": false,\n \"attributes\": [],\n \"isReadOnly\": true\n },\n \"updatedAt\": {\n \"name\": \"updatedAt\",\n \"isArray\": false,\n \"type\": \"AWSDateTime\",\n \"isRequired\": false,\n \"attributes\": [],\n \"isReadOnly\": true\n }\n },\n \"syncable\": true,\n \"pluralName\": \"Blogs\",\n \"attributes\": [\n {\n \"type\": \"model\",\n \"properties\": {}\n },\n {\n \"type\": \"auth\",\n \"properties\": {\n \"rules\": [\n {\n \"allow\": \"public\",\n \"operations\": [\n \"create\",\n \"update\",\n \"delete\",\n \"read\"\n ]\n }\n ]\n }\n }\n ]\n }\n },\n \"enums\": {\n \"Status\": {\n \"name\": \"Status\",\n \"values\": [\n \"ENABLED\",\n \"DISABLED\"\n ]\n }\n },\n \"nonModels\": {},\n \"version\": \"demo\"\n};`,
@@ -33,6 +39,20 @@ const getMockedSchema = jest.fn(
33
39
  describe('should sync amplify backend models', () => {
34
40
  let context: any;
35
41
 
42
+ beforeAll(() => {
43
+ // set metadata response
44
+ awsMock.AmplifyUIBuilder = jest.fn(() => ({
45
+ getMetadata: jest.fn(() => ({
46
+ promise: jest.fn(() => ({
47
+ features: {
48
+ autoGenerateForms: 'true',
49
+ autoGenerateViews: 'true',
50
+ },
51
+ })),
52
+ })),
53
+ }));
54
+ });
55
+
36
56
  beforeEach(() => {
37
57
  context = {
38
58
  exeInfo: {
@@ -56,17 +76,21 @@ describe('should sync amplify backend models', () => {
56
76
  envName: 'testEnvName',
57
77
  },
58
78
  },
79
+ print: { warning: jest.fn() },
59
80
  };
60
- });
61
81
 
62
- it('should getAmplifyBackendModels', async () => {
63
- awsMock.AmplifyBackend = jest.fn(() => ({
64
- getBackendAPIModels: jest.fn(() => ({
82
+ mockedFeatureFlags.getNumber.mockReturnValue(2);
83
+ getMockedSchema.mockClear();
84
+ awsMock.AmplifyBackend = jest.fn().mockReturnValue({
85
+ getBackendAPIModels: jest.fn().mockReturnValue({
65
86
  promise: () => ({
66
87
  Models: getMockedSchema(),
67
88
  }),
68
- })),
69
- }));
89
+ }),
90
+ });
91
+ });
92
+
93
+ it('should getAmplifyBackendModels', async () => {
70
94
  const client = await AmplifyStudioClient.setClientInfo(context);
71
95
  const dataSchema = await getAmplifyDataSchema(client);
72
96
  expect(getMockedSchema).toBeCalled();
@@ -74,14 +98,22 @@ describe('should sync amplify backend models', () => {
74
98
  expect(Object.keys(dataSchema!.models)).toContain('Blog');
75
99
  });
76
100
 
101
+ it('should not getAmplifyBackendModels and return undefined if graphQLTransformer version not supported', async () => {
102
+ mockedFeatureFlags.getNumber.mockReturnValue(1);
103
+ const client = await AmplifyStudioClient.setClientInfo(context);
104
+ const dataSchema = await getAmplifyDataSchema(client);
105
+ expect(getMockedSchema).not.toBeCalled();
106
+ expect(dataSchema).toBeUndefined();
107
+ });
108
+
77
109
  it('should handle Models not found', async () => {
78
- awsMock.AmplifyBackend = jest.fn(() => ({
79
- getBackendAPIModels: jest.fn(() => ({
80
- promise: jest.fn(() => ({
110
+ awsMock.AmplifyBackend = jest.fn().mockReturnValue({
111
+ getBackendAPIModels: jest.fn().mockReturnValue({
112
+ promise: () => ({
81
113
  Models: undefined,
82
- })),
83
- })),
84
- }));
114
+ }),
115
+ }),
116
+ });
85
117
  const client = await AmplifyStudioClient.setClientInfo(context);
86
118
  const dataSchema = await getAmplifyDataSchema(client);
87
119
  expect(dataSchema).toBeUndefined();
@@ -89,11 +121,11 @@ describe('should sync amplify backend models', () => {
89
121
  });
90
122
 
91
123
  it('should handle network error', async () => {
92
- awsMock.AmplifyBackend = jest.fn(() => ({
93
- getBackendAPIModels: jest.fn(() => ({
124
+ awsMock.AmplifyBackend = jest.fn().mockReturnValue({
125
+ getBackendAPIModels: jest.fn().mockReturnValue({
94
126
  promise: jest.fn().mockRejectedValue(new Error('Network Error')),
95
- })),
96
- }));
127
+ }),
128
+ });
97
129
  const client = await AmplifyStudioClient.setClientInfo(context);
98
130
  const dataSchema = await getAmplifyDataSchema(client);
99
131
  expect(dataSchema).toBeUndefined();
@@ -1,13 +1,60 @@
1
- import { $TSContext } from 'amplify-cli-core';
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+ import {
3
+ $TSContext, AmplifyCategories, AmplifySupportedService, CloudformationProviderFacade,
4
+ } from 'amplify-cli-core';
5
+ import aws from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies
2
6
  import { shouldRenderComponents } from '../commands/utils/shouldRenderComponents';
3
7
 
8
+ const awsMock = aws as any;
9
+
10
+ jest.mock('amplify-cli-core', () => ({
11
+ ...jest.requireActual('amplify-cli-core'),
12
+ stateManager: {
13
+ getMeta: jest.fn(() => ({
14
+ [AmplifyCategories.API]: {
15
+ MyResourceName: {
16
+ service: AmplifySupportedService.APPSYNC,
17
+ },
18
+ },
19
+ })),
20
+ // eslint-disable-next-line spellcheck/spell-checker
21
+ getCLIJSON: jest.fn().mockReturnValue({ features: { graphqltransformer: { transformerversion: 2 } } }),
22
+ setCLIJSON: jest.fn(),
23
+ },
24
+ FeatureFlags: {
25
+ getBoolean: () => true,
26
+ getNumber: jest.fn().mockReturnValue(2),
27
+ reloadValues: jest.fn(),
28
+ },
29
+ }));
30
+ CloudformationProviderFacade.isAmplifyAdminApp = jest.fn().mockReturnValue({
31
+ isAdminApp: true,
32
+ });
33
+
4
34
  describe('should render components', () => {
5
35
  let context: $TSContext | any;
6
- beforeEach(() => {
36
+
37
+ beforeAll(async () => {
38
+ // set metadata response
39
+ awsMock.AmplifyUIBuilder = jest.fn(() => ({
40
+ getMetadata: jest.fn(() => ({
41
+ promise: jest.fn(() => ({
42
+ features: {
43
+ autoGenerateForms: 'true',
44
+ autoGenerateViews: 'true',
45
+ },
46
+ })),
47
+ })),
48
+ }));
7
49
  context = {
50
+ amplify: {
51
+ invokePluginMethod: () => ({}),
52
+ },
8
53
  input: {
9
54
  options: {
10
55
  'no-codegen': false,
56
+ appId: 'testAppId',
57
+ envName: 'testEnvName',
11
58
  },
12
59
  },
13
60
  exeInfo: {
@@ -35,12 +82,12 @@ describe('should render components', () => {
35
82
  const shouldIt = await shouldRenderComponents(context);
36
83
  expect(shouldIt).toBe(false);
37
84
  });
38
- it("doesn't work if the frontend is not javascript", async () => {
85
+ it('should return false if frontend is ios', async () => {
39
86
  context.exeInfo.projectConfig.frontend = 'ios';
40
87
  const shouldIt = await shouldRenderComponents(context);
41
88
  expect(shouldIt).toBe(false);
42
89
  });
43
- it("doesn't work if the frontend is not javascript", async () => {
90
+ it('should return false if frontend is vue', async () => {
44
91
  context.exeInfo.projectConfig.javascript.framework = 'vue';
45
92
  const shouldIt = await shouldRenderComponents(context);
46
93
  expect(shouldIt).toBe(false);
@@ -6,9 +6,11 @@ import {
6
6
  getEnvName,
7
7
  getAppId,
8
8
  resolveAppId,
9
+ generateUiBuilderForms,
9
10
  } from '../commands/utils';
10
11
  import { AmplifyStudioClient } from '../clients';
11
12
  import * as createUiBuilderComponentDependency from '../commands/utils/codegenResources';
13
+ import { exampleSchema } from './utils';
12
14
 
13
15
  jest.mock('amplify-cli-core', () => ({
14
16
  ...jest.requireActual('amplify-cli-core'),
@@ -17,6 +19,9 @@ jest.mock('amplify-cli-core', () => ({
17
19
  getNumber: () => 0,
18
20
  },
19
21
  }));
22
+ jest.mock('../commands/utils/featureFlags', () => ({
23
+ getTransformerVersion: jest.fn().mockReturnValue(2),
24
+ }));
20
25
 
21
26
  const awsMock = aws as any;
22
27
  const stateManagerMock = stateManager as any;
@@ -64,12 +69,12 @@ describe('should sync amplify ui builder components', () => {
64
69
  promise: jest.fn(() => ({
65
70
  entities: [
66
71
  {
67
- appId: 'd37nrm8rzt3oek',
72
+ appId: 'd37nrm8rzt3oek', // eslint-disable-line spellcheck/spell-checker
68
73
  bindingProperties: {},
69
74
  componentType: 'Box',
70
75
  environmentName: 'staging',
71
- id: 's-s4mU579Ycf6JGHwhqT',
72
- name: 'aawwdd',
76
+ id: 's-s4mU579Ycf6JGHwhqT', // eslint-disable-line spellcheck/spell-checker
77
+ name: 'aawwdd', // eslint-disable-line spellcheck/spell-checker
73
78
  overrides: {},
74
79
  properties: {},
75
80
  variants: [],
@@ -82,10 +87,62 @@ describe('should sync amplify ui builder components', () => {
82
87
  entities: [{}],
83
88
  })),
84
89
  })),
90
+ exportForms: jest.fn(() => ({
91
+ promise: jest.fn(() => ({
92
+ entities: [{
93
+ name: 'BasicFormCreate',
94
+ formActionType: 'create',
95
+ dataType: {
96
+ dataSourceType: 'Custom',
97
+ dataTypeName: 'Post',
98
+ },
99
+ fields: {
100
+ name: {
101
+ inputType: {
102
+ required: true,
103
+ type: 'TextField',
104
+ name: 'name',
105
+ defaultValue: 'John Doe',
106
+ },
107
+ label: 'name',
108
+ },
109
+ },
110
+ sectionalElements: {},
111
+ style: {},
112
+ }],
113
+ })),
114
+ })),
115
+ exportViews: jest.fn(() => ({
116
+ promise: jest.fn(() => ({
117
+ entities: [{
118
+ appId: '23342',
119
+ dataSource: { type: 'Custom' },
120
+ environmentName: 'staging',
121
+ id: 'id',
122
+ name: 'ProductTable',
123
+ // TODO: replace with export when Codegen updated
124
+ schemaVersion: '1.0',
125
+ style: {},
126
+ viewConfiguration: {
127
+ type: 'Table',
128
+ },
129
+ }],
130
+ })),
131
+ })),
132
+ getMetadata: jest.fn(() => ({
133
+ promise: jest.fn(() => ({
134
+ features: {
135
+ autoGenerateForms: 'true',
136
+ autoGenerateViews: 'true',
137
+ },
138
+ })),
139
+ })),
85
140
  }));
86
141
 
87
142
  createUiBuilderComponentDependencyMock.createUiBuilderComponent = jest.fn();
88
143
  createUiBuilderComponentDependencyMock.createUiBuilderTheme = jest.fn();
144
+ createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn();
145
+ createUiBuilderComponentDependencyMock.createUiBuilderView = jest.fn();
89
146
  });
90
147
 
91
148
  it('pulls components from aws-sdk and passes them to createUiBuilderComponent', () => {
@@ -94,14 +151,14 @@ describe('should sync amplify ui builder components', () => {
94
151
 
95
152
  it('does not throw an error when createUiBuilderComponent fails', () => {
96
153
  createUiBuilderComponentDependencyMock.createUiBuilderComponent = jest.fn(() => {
97
- throw new Error('ahhh!');
154
+ throw new Error('ahhh!'); // eslint-disable-line spellcheck/spell-checker
98
155
  });
99
156
  expect(async () => generateUiBuilderComponents(context, [])).not.toThrow();
100
157
  });
101
158
 
102
159
  it('does not throw an error when createUiBuilderThemes fails', () => {
103
160
  createUiBuilderComponentDependencyMock.createUiBuilderComponent = jest.fn(() => {
104
- throw new Error('ahhh!');
161
+ throw new Error('ahhh!'); // eslint-disable-line spellcheck/spell-checker
105
162
  });
106
163
  expect(async () => generateUiBuilderThemes(context, [])).not.toThrow();
107
164
  });
@@ -113,19 +170,30 @@ describe('should sync amplify ui builder components', () => {
113
170
  expect(Object.keys(client)).toEqual(expect.arrayContaining([
114
171
  'listComponents',
115
172
  'listThemes',
173
+ 'listForms',
116
174
  'getModels',
175
+ 'loadMetadata',
117
176
  'createComponent',
118
177
  ]));
178
+ expect(client.metadata).toEqual(expect.objectContaining({
179
+ autoGenerateForms: true,
180
+ autoGenerateViews: true,
181
+ }));
182
+ });
183
+ it('can list components', async () => {
184
+ const client = await AmplifyStudioClient.setClientInfo(context);
185
+ const components = await client.listComponents();
186
+ expect(components.entities).toHaveLength(1);
119
187
  });
120
188
  it('can list themes', async () => {
121
189
  const client = await AmplifyStudioClient.setClientInfo(context);
122
190
  const themes = await client.listThemes();
123
191
  expect(themes.entities).toHaveLength(1);
124
192
  });
125
- it('can listUiBuilderComponents', async () => {
193
+ it('can list forms', async () => {
126
194
  const client = await AmplifyStudioClient.setClientInfo(context);
127
- const components = await client.listThemes();
128
- expect(components.entities).toHaveLength(1);
195
+ const forms = await client.listForms();
196
+ expect(forms.entities).toHaveLength(1);
129
197
  });
130
198
  it('can getAppId', async () => {
131
199
  const appId = getAppId(context);
@@ -169,4 +237,41 @@ describe('should sync amplify ui builder components', () => {
169
237
  const themes = generateUiBuilderThemes(context, [{}, {}]);
170
238
  expect(themes.every(theme => theme.resultType === 'FAILURE')).toBeTruthy();
171
239
  });
240
+ it('can generate ui builder forms', async () => {
241
+ createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn().mockImplementation(() => ({}));
242
+ const forms = generateUiBuilderForms(context, [{}, {}]);
243
+ expect(forms.every(form => form.resultType === 'SUCCESS')).toBeTruthy();
244
+ });
245
+ it('can handle failed generation generate ui builder forms', async () => {
246
+ createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn().mockImplementation(() => {
247
+ throw new Error('ahh!');
248
+ });
249
+ const forms = generateUiBuilderForms(context, [{}, {}]);
250
+ expect(forms.every(form => form.resultType === 'FAILURE')).toBeTruthy();
251
+ });
252
+ it('can generate uibuilder forms from data schema if autogen true', async () => {
253
+ createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn().mockImplementation(() => ({}));
254
+ const forms = generateUiBuilderForms(context, [], exampleSchema, true);
255
+ expect(forms.every(form => form.resultType === 'SUCCESS')).toBeTruthy();
256
+ // create & update form for author model
257
+ expect(forms.length).toEqual(2);
258
+ });
259
+
260
+ it('should not autogen forms for join tables or unsupported models', async () => {
261
+ expect(Object.keys(exampleSchema.models)).toStrictEqual(['Author', 'JoinTable', 'EmptyModel']);
262
+ createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn().mockImplementation(
263
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
264
+ (_ctx, schema, _dataSchema) => ({ name: schema.dataType.dataTypeName }),
265
+ );
266
+ const forms = generateUiBuilderForms(context, [], exampleSchema, true);
267
+ expect(forms.every(form => form.resultType === 'SUCCESS')).toBeTruthy();
268
+ // only create & update form for author model
269
+ expect(forms.map(f => (f.schema as any).name)).toStrictEqual(['Author', 'Author']);
270
+ });
271
+
272
+ it('does not generate uibuilder forms from data schema if autogen false', async () => {
273
+ createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn().mockImplementation(() => ({}));
274
+ const forms = generateUiBuilderForms(context, [], exampleSchema, false);
275
+ expect(forms.length).toEqual(0);
276
+ });
172
277
  });
@@ -0,0 +1,70 @@
1
+ import type { GenericDataSchema } from '@aws-amplify/codegen-ui';
2
+
3
+ export const exampleSchema: GenericDataSchema = {
4
+ dataSourceType: 'DataStore',
5
+ models: {
6
+ Author: {
7
+ fields: {
8
+ id: {
9
+ dataType: 'ID',
10
+ required: true,
11
+ readOnly: false,
12
+ isArray: false,
13
+ },
14
+ name: {
15
+ dataType: 'String',
16
+ required: false,
17
+ readOnly: false,
18
+ isArray: false,
19
+ },
20
+ profileImageSrc: {
21
+ dataType: 'AWSURL',
22
+ required: false,
23
+ readOnly: false,
24
+ isArray: false,
25
+ },
26
+ description: {
27
+ dataType: 'String',
28
+ required: false,
29
+ readOnly: false,
30
+ isArray: false,
31
+ },
32
+ books: {
33
+ dataType: 'String',
34
+ required: false,
35
+ readOnly: false,
36
+ isArray: true,
37
+ },
38
+ createdAt: {
39
+ dataType: 'AWSDateTime',
40
+ required: false,
41
+ readOnly: true,
42
+ isArray: false,
43
+ },
44
+ updatedAt: {
45
+ dataType: 'AWSDateTime',
46
+ required: false,
47
+ readOnly: true,
48
+ isArray: false,
49
+ },
50
+ },
51
+ },
52
+ JoinTable: {
53
+ fields: {
54
+ id: {
55
+ dataType: 'ID',
56
+ required: true,
57
+ readOnly: false,
58
+ isArray: false,
59
+ },
60
+ },
61
+ isJoinTable: true
62
+ },
63
+ EmptyModel: {
64
+ fields: {
65
+ },
66
+ },
67
+ },
68
+ enums: {}, // eslint-disable-line spellcheck/spell-checker
69
+ nonModels: {},
70
+ };