chore(e2e): delete collectionName key (#2783)

* chore(e2e): delete collectionName key

* test: add test
This commit is contained in:
被雨水过滤的空气-Rain 2023-10-10 15:03:17 +08:00 committed by GitHub
parent b2883ff55b
commit 9085f5ca20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 5 deletions

View File

@ -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",
},
]
`;

View File

@ -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();
});
});

View File

@ -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'])),
};
});
};