From d04a60d386fd4823840e24d567293b118e6daa2a Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 27 Mar 2024 12:03:00 +0800 Subject: [PATCH] fix: e2e-failed (#3828) * fix: e2e-failed * fix: ci * fix: ci bug * fix: ci(skip server ci) * fix: ci [skip ci] * fix: ci(skip server ci) * fix: ci * fix: ci * fix: remove skip if --------- Co-authored-by: dream2023 <1098626505@qq.com> --- .github/workflows/nocobase-test-backend.yml | 8 ++--- .github/workflows/nocobase-test-e2e.yml | 1 - .github/workflows/nocobase-test-frontend.yml | 1 - .../antd/input-number/ReadPretty.tsx | 29 ++++++++++++++----- .../__tests__/input-number.test.tsx | 17 +++++++---- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/.github/workflows/nocobase-test-backend.yml b/.github/workflows/nocobase-test-backend.yml index 4a0a38009..0224ac2dd 100644 --- a/.github/workflows/nocobase-test-backend.yml +++ b/.github/workflows/nocobase-test-backend.yml @@ -13,6 +13,8 @@ on: - 'packages/core/acl/**' - 'packages/core/actions/**' - 'packages/core/database/**' + - 'packages/core/resourcer/**' + - 'packages/core/data-source-manager/**' - 'packages/core/server/**' - 'packages/core/utils/**' - 'packages/plugins/**/src/server/**' @@ -23,6 +25,8 @@ on: - 'packages/core/acl/**' - 'packages/core/actions/**' - 'packages/core/database/**' + - 'packages/core/resourcer/**' + - 'packages/core/data-source-manager/**' - 'packages/core/server/**' - 'packages/core/utils/**' - 'packages/plugins/**/src/server/**' @@ -30,7 +34,6 @@ on: jobs: sqlite-test: - if: "!contains(github.event.head_commit.message, 'skip server ci'))" strategy: matrix: node_version: ['18'] @@ -68,7 +71,6 @@ jobs: timeout-minutes: 40 postgres-test: - if: "!contains(github.event.head_commit.message, 'skip server ci'))" strategy: matrix: node_version: ['18'] @@ -133,7 +135,6 @@ jobs: timeout-minutes: 40 mysql-test: - if: "!contains(github.event.head_commit.message, 'skip server ci'))" strategy: matrix: node_version: ['18'] @@ -184,7 +185,6 @@ jobs: DB_TEST_PREFIX: test_ timeout-minutes: 40 mariadb-test: - if: "!contains(github.event.head_commit.message, 'skip server ci'))" strategy: matrix: node_version: ['18'] diff --git a/.github/workflows/nocobase-test-e2e.yml b/.github/workflows/nocobase-test-e2e.yml index a3f6149e0..3edbbecf4 100644 --- a/.github/workflows/nocobase-test-e2e.yml +++ b/.github/workflows/nocobase-test-e2e.yml @@ -21,7 +21,6 @@ on: jobs: e2e-test-postgres: - if: "!contains(github.event.head_commit.message, 'skip e2e ci'))" strategy: matrix: node_version: ['18'] diff --git a/.github/workflows/nocobase-test-frontend.yml b/.github/workflows/nocobase-test-frontend.yml index 934b49e5b..799f84ff2 100644 --- a/.github/workflows/nocobase-test-frontend.yml +++ b/.github/workflows/nocobase-test-frontend.yml @@ -29,7 +29,6 @@ on: jobs: frontend-test: - if: "!contains(github.event.head_commit.message, 'skip client ci'))" strategy: matrix: node_version: [ '18' ] diff --git a/packages/core/client/src/schema-component/antd/input-number/ReadPretty.tsx b/packages/core/client/src/schema-component/antd/input-number/ReadPretty.tsx index 91eb12e37..0f5debc66 100644 --- a/packages/core/client/src/schema-component/antd/input-number/ReadPretty.tsx +++ b/packages/core/client/src/schema-component/antd/input-number/ReadPretty.tsx @@ -2,9 +2,9 @@ import { isValid } from '@formily/shared'; import { toFixedByStep } from '@nocobase/utils/client'; import type { InputProps } from 'antd/es/input'; import type { InputNumberProps } from 'antd/es/input-number'; +import { format } from 'd3-format'; import * as math from 'mathjs'; import React, { useMemo } from 'react'; -import { format } from 'd3-format'; function countDecimalPlaces(value) { const number = Number(value); @@ -20,7 +20,7 @@ const separators = { '0.00': { thousands: '', decimal: '.' }, // 没有千位分隔符 }; //分隔符换算 -export function formatNumberWithSeparator(number, format = '0,0.00', step = 1) { +export function formatNumberWithSeparator(number, format = '0.00', step = 1) { let formattedNumber = ''; if (separators[format]) { @@ -75,20 +75,23 @@ export function scientificNotation(number, decimalPlaces, separator = '.') { const result = formattedNumber.replace(/e([+-]?\d+)/, (match, exponent) => { if (exponent.startsWith('+')) { // 正数指数,不显示符号 - return ` × 10${exponent.slice(1)}`; + return `×10${exponent.slice(1)}`; } else { // 负数指数,显示 "-" 符号 - return ` × 10-${exponent.slice(1)}`; + return `×10-${exponent.slice(1)}`; } }); return result; } -export const ReadPretty: React.FC = (props: any) => { - const { step, formatStyle, value, addonBefore, addonAfter, unitConversion, unitConversionType, separator } = props; - if (!isValid(props.value)) { + +export function formatNumber(props) { + const { step, formatStyle, value, unitConversion, unitConversionType, separator = '0.00' } = props; + + if (!isValid(value)) { return null; } + //单位换算 const unitData = formatUnitConversion(value, unitConversionType, unitConversion); //精度换算 @@ -100,10 +103,20 @@ export const ReadPretty: React.FC = (props: any) //科学计数显示 result = scientificNotation(Number(unitData), countDecimalPlaces(step), separators?.[separator]?.['decimal']); } + return result; +} - if (!result) { +export const ReadPretty: React.FC = (props: any) => { + const { step, formatStyle, value, addonBefore, addonAfter, unitConversion, unitConversionType, separator } = props; + + const result = useMemo(() => { + return formatNumber({ step, formatStyle, value, unitConversion, unitConversionType, separator }); + }, [step, formatStyle, value, unitConversion, unitConversionType, separator]); + + if (!isValid(result)) { return null; } + return (
{addonBefore} diff --git a/packages/core/client/src/schema-component/antd/input-number/__tests__/input-number.test.tsx b/packages/core/client/src/schema-component/antd/input-number/__tests__/input-number.test.tsx index 01adf6902..8793b2232 100644 --- a/packages/core/client/src/schema-component/antd/input-number/__tests__/input-number.test.tsx +++ b/packages/core/client/src/schema-component/antd/input-number/__tests__/input-number.test.tsx @@ -1,9 +1,9 @@ import { fireEvent, render, screen } from '@nocobase/test/client'; import React from 'react'; +import { formatNumberWithSeparator, formatUnitConversion, scientificNotation } from '../ReadPretty'; import App2 from '../demos/addonBefore&addonAfter'; import App3 from '../demos/highPrecisionDecimals'; import App1 from '../demos/inputNumber'; -import { formatNumberWithSeparator, formatUnitConversion, scientificNotation } from '../ReadPretty'; describe('InputNumber', () => { it('should display the title', () => { @@ -81,13 +81,13 @@ describe('ReadPretty:formatNumberWithSeparator', () => { // Test case 1: Format a number with default format '0,0.00' test('Format number with default separator', () => { const formatted = formatNumberWithSeparator(1234567.89); - expect(formatted).toBe('1,234,567.9'); + expect(formatted).toBe('1234567.9'); }); // Test case 2: Format a number with custom format '0.00' test('Format number with custom separator', () => { - const formatted = formatNumberWithSeparator(1234567.89, '0.00', 1); - expect(formatted).toBe('1234567.9'); + const formatted = formatNumberWithSeparator(1234567.89, '0,0.00', 1); + expect(formatted).toBe('1,234,567.9'); }); }); describe('ReadPretty:formatUnitConversion', () => { @@ -101,18 +101,23 @@ describe('ReadPretty:formatUnitConversion', () => { const result = formatUnitConversion(10, '/', 0); expect(result).toBe(10); }); + + test('0.1*0.2', () => { + const result = formatUnitConversion(0.1, '*', 0.2); + expect(result).toBe(0.02); + }); }); describe('ReadPretty:scientificNotation', () => { // Test case 1: Format a number into scientific notation with 2 decimal places test('Format number into scientific notation', () => { const formatted = scientificNotation(1234567.89, 2); - expect(formatted).toBe('1.23 × 106'); + expect(formatted).toBe('1.23×106'); }); // Test case 2: Format a number into scientific notation with custom separator '.' test('Format number into scientific notation with custom separator', () => { const formatted = scientificNotation(1234567.89, 2, '.'); - expect(formatted).toBe('1.23 × 106'); + expect(formatted).toBe('1.23×106'); }); });