fix(dateVariable): fix default value issue in chart filter block (#5405)
Some checks failed
Auto merge main -> next / push-commit (push) Waiting to run
Build docker image / build-and-push (push) Waiting to run
Build pro image / build-and-push (push) Waiting to run
Deploy client docs / Build (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase frontEnd test / frontend-test (18) (push) Waiting to run
NocoBase backend test / sqlite-test (20, false) (push) Has been cancelled
NocoBase backend test / sqlite-test (20, true) (push) Has been cancelled
NocoBase backend test / postgres-test (public, 20, nocobase, false) (push) Has been cancelled
NocoBase backend test / postgres-test (public, 20, nocobase, true) (push) Has been cancelled
NocoBase backend test / postgres-test (public, 20, public, false) (push) Has been cancelled
NocoBase backend test / postgres-test (public, 20, public, true) (push) Has been cancelled
NocoBase backend test / postgres-test (user_schema, 20, nocobase, false) (push) Has been cancelled
NocoBase backend test / postgres-test (user_schema, 20, nocobase, true) (push) Has been cancelled
NocoBase backend test / postgres-test (user_schema, 20, public, false) (push) Has been cancelled
NocoBase backend test / postgres-test (user_schema, 20, public, true) (push) Has been cancelled
NocoBase backend test / mysql-test (20, false) (push) Has been cancelled
NocoBase backend test / mysql-test (20, true) (push) Has been cancelled
NocoBase backend test / mariadb-test (20, false) (push) Has been cancelled
NocoBase backend test / mariadb-test (20, true) (push) Has been cancelled

* fix(dateVariable): fix default value issue in chart filter block

* test: add e2e test

* chore: update unit test
This commit is contained in:
Zeke Zhang 2024-10-13 16:58:32 +08:00 committed by GitHub
parent 0d4e2237b8
commit 30febb30be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 48 additions and 4 deletions

View File

@ -217,9 +217,9 @@ export const getDateRanges = (props?: {
};
function withParams(value: any[], params: { fieldOperator?: string; isParsingVariable?: boolean }) {
if (params?.fieldOperator === '$dateBetween' || !params?.isParsingVariable) {
return value;
if (params?.isParsingVariable && params?.fieldOperator && params.fieldOperator !== '$dateBetween') {
return value[0];
}
return value[0];
return value;
}

View File

@ -298,7 +298,11 @@ describe('useVariables', () => {
});
await waitFor(async () => {
expect(await result.current.parseVariable('{{ $date.today }}').then(({ value }) => typeof value)).toBe('string');
expect(
await result.current
.parseVariable('{{ $date.today }}', [], { fieldOperator: '$dateOn' })
.then(({ value }) => typeof value),
).toBe('string');
expect(
Array.isArray(
await result.current

View File

@ -0,0 +1,40 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { expect, test } from '@nocobase/test/e2e';
test.describe('defaultValue', () => {
test('date variables', async ({ page, mockPage }) => {
await mockPage().goto();
// 1. First, create a chart filter block and add a custom date field (date range)
await page.getByLabel('schema-initializer-Grid-page:').hover();
await page.getByRole('menuitem', { name: 'line-chart Charts' }).click();
await page.getByLabel('schema-initializer-Grid-charts:addBlock').hover();
await page.getByRole('menuitem', { name: 'Filter' }).click();
await page.getByTestId('configure-fields-button-of-chart-filter-item').hover();
await page.getByRole('menuitem', { name: 'Custom' }).click();
await page.getByLabel('block-item-Input-Field title').getByRole('textbox').fill('date');
await page.getByLabel('block-item-Select-Field').getByTestId('select-single').click();
await page.getByRole('option', { name: 'Date range' }).click();
await page.getByRole('button', { name: 'OK' }).click();
// 2. Set a date variable default value for the custom field, after saving, the date input box should display the default value
await page.getByLabel('block-item-DatePicker.').hover();
await page.getByLabel('designer-schema-settings-DatePicker.RangePicker-ChartFilterItemDesigner').hover();
await page.getByRole('menuitem', { name: 'Set default value' }).click();
await page.getByLabel('variable-button').click();
await page.getByRole('menuitemcheckbox', { name: 'Date variables right' }).click();
await page.getByRole('menuitemcheckbox', { name: 'Last week' }).click();
await page.getByRole('button', { name: 'OK' }).click();
await expect(page.getByPlaceholder('Start date')).toHaveValue(/[0-9]{4}-[0-9]{2}-[0-9]{2}/);
await expect(page.getByPlaceholder('End date')).toHaveValue(/[0-9]{4}-[0-9]{2}-[0-9]{2}/);
});
});