|
@@ -8,6 +8,7 @@ import {
|
|
} from '@/services/backend';
|
|
} from '@/services/backend';
|
|
import { Log } from '$app/utils/log';
|
|
import { Log } from '$app/utils/log';
|
|
import {
|
|
import {
|
|
|
|
+ assert,
|
|
assertFieldName,
|
|
assertFieldName,
|
|
assertNumberOfFields,
|
|
assertNumberOfFields,
|
|
assertNumberOfRows,
|
|
assertNumberOfRows,
|
|
@@ -16,6 +17,8 @@ import {
|
|
createTestDatabaseView,
|
|
createTestDatabaseView,
|
|
editTextCell,
|
|
editTextCell,
|
|
findFirstFieldInfoWithFieldType,
|
|
findFirstFieldInfoWithFieldType,
|
|
|
|
+ makeCheckboxCellController,
|
|
|
|
+ makeDateCellController,
|
|
makeMultiSelectCellController,
|
|
makeMultiSelectCellController,
|
|
makeSingleSelectCellController,
|
|
makeSingleSelectCellController,
|
|
makeTextCellController,
|
|
makeTextCellController,
|
|
@@ -27,6 +30,8 @@ import { TypeOptionController } from '$app/stores/effects/database/field/type_op
|
|
import { None, Some } from 'ts-results';
|
|
import { None, Some } from 'ts-results';
|
|
import { RowBackendService } from '$app/stores/effects/database/row/row_bd_svc';
|
|
import { RowBackendService } from '$app/stores/effects/database/row/row_bd_svc';
|
|
import { makeNumberTypeOptionContext } from '$app/stores/effects/database/field/type_option/type_option_context';
|
|
import { makeNumberTypeOptionContext } from '$app/stores/effects/database/field/type_option/type_option_context';
|
|
|
|
+import { CalendarData } from '$app/stores/effects/database/cell/controller_builder';
|
|
|
|
+import { DatabaseEventMoveField } from '@/services/backend/events/flowy-database';
|
|
|
|
|
|
export const RunAllGridTests = () => {
|
|
export const RunAllGridTests = () => {
|
|
async function run() {
|
|
async function run() {
|
|
@@ -138,6 +143,57 @@ async function testEditURLCell() {
|
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+async function testEditDateCell() {
|
|
|
|
+ const view = await createTestDatabaseView(ViewLayoutTypePB.Grid);
|
|
|
|
+ const databaseController = await openTestDatabase(view.id);
|
|
|
|
+ await databaseController.open().then((result) => result.unwrap());
|
|
|
|
+
|
|
|
|
+ const typeOptionController = new TypeOptionController(view.id, None, FieldType.DateTime);
|
|
|
|
+ await typeOptionController.initialize();
|
|
|
|
+
|
|
|
|
+ const row = databaseController.databaseViewCache.rowInfos[0];
|
|
|
|
+ const dateCellController = await makeDateCellController(typeOptionController.fieldId, row, databaseController).then(
|
|
|
|
+ (result) => result.unwrap()
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ dateCellController.subscribeChanged({
|
|
|
|
+ onCellChanged: (content) => {
|
|
|
|
+ const pb = content.unwrap();
|
|
|
|
+ Log.info('Receive date data:', pb.date, pb.time);
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ const date = new CalendarData(new Date(), true, '13:00');
|
|
|
|
+ await dateCellController.saveCellData(date);
|
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, 200));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+async function testCheckboxCell() {
|
|
|
|
+ const view = await createTestDatabaseView(ViewLayoutTypePB.Grid);
|
|
|
|
+ const databaseController = await openTestDatabase(view.id);
|
|
|
|
+ await databaseController.open().then((result) => result.unwrap());
|
|
|
|
+
|
|
|
|
+ const typeOptionController = new TypeOptionController(view.id, None, FieldType.Checkbox);
|
|
|
|
+ await typeOptionController.initialize();
|
|
|
|
+
|
|
|
|
+ const row = databaseController.databaseViewCache.rowInfos[0];
|
|
|
|
+ const checkboxCellController = await makeCheckboxCellController(
|
|
|
|
+ typeOptionController.fieldId,
|
|
|
|
+ row,
|
|
|
|
+ databaseController
|
|
|
|
+ ).then((result) => result.unwrap());
|
|
|
|
+
|
|
|
|
+ checkboxCellController.subscribeChanged({
|
|
|
|
+ onCellChanged: (content) => {
|
|
|
|
+ const pb = content.unwrap();
|
|
|
|
+ Log.info('Receive checkbox data:', pb);
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ await checkboxCellController.saveCellData('true');
|
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, 200));
|
|
|
|
+}
|
|
|
|
+
|
|
async function testCreateRow() {
|
|
async function testCreateRow() {
|
|
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid);
|
|
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid);
|
|
const databaseController = await openTestDatabase(view.id);
|
|
const databaseController = await openTestDatabase(view.id);
|
|
@@ -196,6 +252,24 @@ async function testCreateOptionInCell() {
|
|
await databaseController.dispose();
|
|
await databaseController.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+async function testMoveField() {
|
|
|
|
+ const view = await createTestDatabaseView(ViewLayoutTypePB.Grid);
|
|
|
|
+ const databaseController = await openTestDatabase(view.id);
|
|
|
|
+ await databaseController.open().then((result) => result.unwrap());
|
|
|
|
+
|
|
|
|
+ databaseController.subscribe({
|
|
|
|
+ onFieldsChanged: (value) => {
|
|
|
|
+ Log.info('Receive fields data:', value);
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ const fieldInfos = [...databaseController.fieldController.fieldInfos];
|
|
|
|
+ const field_id = fieldInfos[0].field.id;
|
|
|
|
+ await databaseController.moveField({ fieldId: field_id, fromIndex: 0, toIndex: 1 });
|
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, 200));
|
|
|
|
+ assert(databaseController.fieldController.fieldInfos[1].field.id === field_id);
|
|
|
|
+}
|
|
|
|
+
|
|
async function testGetSingleSelectFieldData() {
|
|
async function testGetSingleSelectFieldData() {
|
|
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid);
|
|
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid);
|
|
const databaseController = await openTestDatabase(view.id);
|
|
const databaseController = await openTestDatabase(view.id);
|
|
@@ -360,6 +434,12 @@ export const TestEditTextCell = () => {
|
|
export const TestEditURLCell = () => {
|
|
export const TestEditURLCell = () => {
|
|
return TestButton('Test editing URL cell', testEditURLCell);
|
|
return TestButton('Test editing URL cell', testEditURLCell);
|
|
};
|
|
};
|
|
|
|
+export const TestEditDateCell = () => {
|
|
|
|
+ return TestButton('Test editing date cell', testEditDateCell);
|
|
|
|
+};
|
|
|
|
+export const TestEditCheckboxCell = () => {
|
|
|
|
+ return TestButton('Test editing checkbox cell', testCheckboxCell);
|
|
|
|
+};
|
|
export const TestCreateRow = () => {
|
|
export const TestCreateRow = () => {
|
|
return TestButton('Test create row', testCreateRow);
|
|
return TestButton('Test create row', testCreateRow);
|
|
};
|
|
};
|
|
@@ -382,6 +462,9 @@ export const TestSwitchFromMultiSelectToText = () => {
|
|
return TestButton('Test switch from multi-select to text column', testSwitchFromMultiSelectToRichText);
|
|
return TestButton('Test switch from multi-select to text column', testSwitchFromMultiSelectToRichText);
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+export const TestMoveField = () => {
|
|
|
|
+ return TestButton('Test move field', testMoveField);
|
|
|
|
+};
|
|
export const TestEditField = () => {
|
|
export const TestEditField = () => {
|
|
return TestButton('Test edit the column name', testEditField);
|
|
return TestButton('Test edit the column name', testEditField);
|
|
};
|
|
};
|