test: add tauri format test (#2229)

This commit is contained in:
Nathan.fooo 2023-04-10 22:50:00 +08:00 committed by GitHub
parent b8ade5af12
commit 341dce67d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 7 deletions

View File

@ -10,7 +10,9 @@ import {
TestEditCell, TestEditCell,
TestEditCheckboxCell, TestEditCheckboxCell,
TestEditDateCell, TestEditDateCell,
TestEditDateFormat,
TestEditField, TestEditField,
TestEditNumberFormat,
TestEditTextCell, TestEditTextCell,
TestEditURLCell, TestEditURLCell,
TestGetSingleSelectFieldData, TestGetSingleSelectFieldData,
@ -48,6 +50,8 @@ export const TestAPI = () => {
<TestMoveField></TestMoveField> <TestMoveField></TestMoveField>
<TestCreateNewField></TestCreateNewField> <TestCreateNewField></TestCreateNewField>
<TestDeleteField></TestDeleteField> <TestDeleteField></TestDeleteField>
<TestEditDateFormat></TestEditDateFormat>
<TestEditNumberFormat></TestEditNumberFormat>
<TestSwitchFromSingleSelectToNumber></TestSwitchFromSingleSelectToNumber> <TestSwitchFromSingleSelectToNumber></TestSwitchFromSingleSelectToNumber>
<TestSwitchFromMultiSelectToText></TestSwitchFromMultiSelectToText> <TestSwitchFromMultiSelectToText></TestSwitchFromMultiSelectToText>
{/*kanban board */} {/*kanban board */}

View File

@ -1,5 +1,13 @@
import React from 'react'; import React from 'react';
import { FieldType, NumberFormat, NumberTypeOptionPB, SelectOptionCellDataPB, ViewLayoutPB } from '@/services/backend'; import {
DateFormat,
FieldType,
NumberFormat,
NumberTypeOptionPB,
SelectOptionCellDataPB,
TimeFormat,
ViewLayoutPB,
} from '@/services/backend';
import { Log } from '$app/utils/log'; import { Log } from '$app/utils/log';
import { import {
assert, assert,
@ -23,9 +31,11 @@ import { SelectOptionCellBackendService } from '$app/stores/effects/database/cel
import { TypeOptionController } from '$app/stores/effects/database/field/type_option/type_option_controller'; import { TypeOptionController } from '$app/stores/effects/database/field/type_option/type_option_controller';
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 {
makeDateTypeOptionContext,
makeNumberTypeOptionContext,
} from '$app/stores/effects/database/field/type_option/type_option_context';
import { CalendarData } from '$app/stores/effects/database/cell/controller_builder'; 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() {
@ -162,6 +172,52 @@ async function testEditDateCell() {
await new Promise((resolve) => setTimeout(resolve, 200)); await new Promise((resolve) => setTimeout(resolve, 200));
} }
async function testEditDateFormat() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap());
// Create date field
const typeOptionController = new TypeOptionController(view.id, None, FieldType.DateTime);
await typeOptionController.initialize();
// update date type option
const dateTypeOptionContext = makeDateTypeOptionContext(typeOptionController);
const typeOption = await dateTypeOptionContext.getTypeOption().then((a) => a.unwrap());
assert(typeOption.date_format === DateFormat.Friendly, 'Date format not match');
assert(typeOption.time_format === TimeFormat.TwentyFourHour, 'Time format not match');
typeOption.date_format = DateFormat.Local;
typeOption.time_format = TimeFormat.TwelveHour;
await dateTypeOptionContext.setTypeOption(typeOption);
const typeOption2 = await dateTypeOptionContext.getTypeOption().then((a) => a.unwrap());
assert(typeOption2.date_format === DateFormat.Local, 'Date format not match');
assert(typeOption2.time_format === TimeFormat.TwelveHour, 'Time format not match');
await new Promise((resolve) => setTimeout(resolve, 200));
}
async function testEditNumberFormat() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap());
// Create date field
const typeOptionController = new TypeOptionController(view.id, None, FieldType.Number);
await typeOptionController.initialize();
// update date type option
const dateTypeOptionContext = makeNumberTypeOptionContext(typeOptionController);
const typeOption = await dateTypeOptionContext.getTypeOption().then((a) => a.unwrap());
typeOption.format = NumberFormat.EUR;
typeOption.name = 'Money';
await dateTypeOptionContext.setTypeOption(typeOption);
const typeOption2 = await dateTypeOptionContext.getTypeOption().then((a) => a.unwrap());
Log.info(typeOption2);
await new Promise((resolve) => setTimeout(resolve, 200));
}
async function testCheckboxCell() { async function testCheckboxCell() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
@ -250,10 +306,13 @@ async function testMoveField() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
const ids = databaseController.fieldController.fieldInfos.map((value) => value.field.id);
Log.info('Receive fields data:', ids);
databaseController.subscribe({ databaseController.subscribe({
onFieldsChanged: (value) => { onFieldsChanged: (values) => {
Log.info('Receive fields data:', value); const new_ids = values.map((value) => value.field.id);
Log.info('Receive fields data:', new_ids);
}, },
}); });
@ -431,6 +490,12 @@ export const TestEditURLCell = () => {
export const TestEditDateCell = () => { export const TestEditDateCell = () => {
return TestButton('Test editing date cell', testEditDateCell); return TestButton('Test editing date cell', testEditDateCell);
}; };
export const TestEditDateFormat = () => {
return TestButton('Test editing date format', testEditDateFormat);
};
export const TestEditNumberFormat = () => {
return TestButton('Test editing number format', testEditNumberFormat);
};
export const TestEditCheckboxCell = () => { export const TestEditCheckboxCell = () => {
return TestButton('Test editing checkbox cell', testCheckboxCell); return TestButton('Test editing checkbox cell', testCheckboxCell);
}; };

View File

@ -1,8 +1,8 @@
import { FieldPB, FieldType, TypeOptionPB } from '@/services/backend'; import { FieldPB, FieldType, TypeOptionPB } from '@/services/backend';
import { ChangeNotifier } from '$app/utils/change_notifier'; import { ChangeNotifier } from '$app/utils/change_notifier';
import { FieldBackendService } from '../field_bd_svc'; import { FieldBackendService, TypeOptionParser } from '../field_bd_svc';
import { Log } from '$app/utils/log'; import { Log } from '$app/utils/log';
import { None, Option, Some } from 'ts-results'; import { None, Ok, Option, Some } from 'ts-results';
import { FieldInfo } from '../field_controller'; import { FieldInfo } from '../field_controller';
import { TypeOptionBackendService } from './type_option_bd_svc'; import { TypeOptionBackendService } from './type_option_bd_svc';