chore(e2e): delete collectionName key (#2783)
* chore(e2e): delete collectionName key * test: add test
This commit is contained in:
parent
b2883ff55b
commit
9085f5ca20
@ -0,0 +1,32 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`omitSomeFields > should omit key & collectionName 1`] = `
|
||||
[
|
||||
{
|
||||
"description": null,
|
||||
"fields": [
|
||||
{
|
||||
"allowNull": false,
|
||||
"autoIncrement": true,
|
||||
"description": null,
|
||||
"interface": "id",
|
||||
"name": "id",
|
||||
"parentKey": null,
|
||||
"primaryKey": true,
|
||||
"reverseKey": null,
|
||||
"type": "bigInt",
|
||||
"uiSchema": {
|
||||
"title": "{{t(\\"ID\\")}}",
|
||||
"type": "number",
|
||||
"x-component": "InputNumber",
|
||||
"x-read-pretty": true,
|
||||
},
|
||||
},
|
||||
],
|
||||
"hidden": false,
|
||||
"inherit": false,
|
||||
"name": "t_0a1w7khj0y7",
|
||||
"title": "a",
|
||||
},
|
||||
]
|
||||
`;
|
@ -0,0 +1,39 @@
|
||||
import { omitSomeFields } from '../e2eUtils';
|
||||
|
||||
describe('omitSomeFields', () => {
|
||||
test('should omit key & collectionName', () => {
|
||||
const collections = [
|
||||
{
|
||||
key: 'y7yd3v18l4t',
|
||||
name: 't_0a1w7khj0y7',
|
||||
title: 'a',
|
||||
inherit: false,
|
||||
hidden: false,
|
||||
description: null,
|
||||
fields: [
|
||||
{
|
||||
key: '1anm4syjvjt',
|
||||
name: 'id',
|
||||
type: 'bigInt',
|
||||
interface: 'id',
|
||||
description: null,
|
||||
collectionName: 't_0a1w7khj0y7',
|
||||
parentKey: null,
|
||||
reverseKey: null,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
uiSchema: {
|
||||
type: 'number',
|
||||
title: '{{t("ID")}}',
|
||||
'x-component': 'InputNumber',
|
||||
'x-read-pretty': true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
expect(omitSomeFields(collections)).toMatchSnapshot();
|
||||
});
|
||||
});
|
@ -129,7 +129,7 @@ class NocoPage {
|
||||
|
||||
async init() {
|
||||
if (this.options?.collections?.length) {
|
||||
const collections: any = deleteKeyOfCollection(this.options.collections);
|
||||
const collections: any = omitSomeFields(this.options.collections);
|
||||
this.collectionsName = collections.map((item) => item.name);
|
||||
|
||||
await createCollections(collections);
|
||||
@ -191,7 +191,9 @@ export const test = base.extend<{
|
||||
let collectionsName = [];
|
||||
|
||||
const _createCollections = async (collectionSettings: CollectionSetting | CollectionSetting[]) => {
|
||||
collectionSettings = Array.isArray(collectionSettings) ? collectionSettings : [collectionSettings];
|
||||
collectionSettings = omitSomeFields(
|
||||
Array.isArray(collectionSettings) ? collectionSettings : [collectionSettings],
|
||||
);
|
||||
collectionsName = collectionSettings.map((item) => item.name);
|
||||
await createCollections(collectionSettings);
|
||||
};
|
||||
@ -356,15 +358,15 @@ const deleteCollections = async (collectionNames: string[]) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 如果不删除 key 会报错
|
||||
* 删除一些不需要的字段,如 key
|
||||
* @param collectionSettings
|
||||
* @returns
|
||||
*/
|
||||
const deleteKeyOfCollection = (collectionSettings: CollectionSetting[]) => {
|
||||
export const omitSomeFields = (collectionSettings: CollectionSetting[]): any[] => {
|
||||
return collectionSettings.map((collection) => {
|
||||
return {
|
||||
..._.omit(collection, ['key']),
|
||||
fields: collection.fields.map((field) => _.omit(field, ['key'])),
|
||||
fields: collection.fields.map((field) => _.omit(field, ['key', 'collectionName'])),
|
||||
};
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user