Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheets-conditional-formatting-ui): fix icon set dark mode (#8128)
白熱68710ec77b3b
diff --git a/packages/sheets-conditional-formatting-ui/package.json b/packages/sheets-conditional-formatting-ui/package.jsonindex 0c409cc856..eb6775aa34 100644--- a/packages/sheets-conditional-formatting-ui/package.json+++ b/packages/sheets-conditional-formatting-ui/package.json@@ -88,6 +88,7 @@},"devDependencies": {"@univerjs-infra/shared": "workspace:*",+ "@univerjs/docs": "workspace:*","postcss": "^8.5.32","react": "18.3.1","rxjs": "7.8.2",diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsxindex aa0a874536..6b03b90b1e 100644--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx@@ -17,8 +17,6 @@import type { Workbook } from '@univerjs/core';import type { IIconSet } from '@univerjs/sheets-conditional-formatting';import type { IFormulaEditorRef } from '@univerjs/sheets-formula-ui';-import type { LocaleKey } from '../../../locale/types';-import type { IStyleEditorProps } from './type';import { get, IUniverInstanceService, LocaleService, set, Tools, UniverInstanceType } from '@univerjs/core';import { borderClassName, Checkbox, clsx, Dropdown, Select } from '@univerjs/design';import { MoreDownIcon, SlashDoubleIcon } from '@univerjs/icons';@@ -37,6 +35,8 @@ import {import { FormulaEditor } from '@univerjs/sheets-formula-ui';import { useDependency, useObservable, useSidebarClick } from '@univerjs/ui';import { useEffect, useMemo, useRef, useState } from 'react';+import type { LocaleKey } from '../../../locale/types';+import type { IStyleEditorProps } from './type';import { RuleNumberInput } from './RuleNumberInput';const getIcon = (iconType: IIconSetType, iconId: string | number) => {@@ -111,13 +111,6 @@ const TextInput = (props: {</div>);};-const createDefaultConfigItem = (iconType: IIconSetType, index: number, list: unknown[]): IIconSet['config'][number] => ({- operator: CFNumberOperator.greaterThan,- value: { type: CFValueType.num, value: (list.length - 1 - index) * 10 },- iconType,- iconId: String(index),-});-interface IIconGroupListProps {onClick: (iconType: IIconSetType) => void;iconType?: IIconSetType;@@ -201,7 +194,7 @@ const IconGroupList = (props: IIconGroupListProps) => {);};-const IconItemList = (props: { onClick: (iconType: IIconSetType, iconId: string) => void; iconType?: IIconSetType; iconId: string }) => {+const IconItemList = (props: { onClick: (iconType: IIconSetType, iconId: string) => void }) => {const { onClick } = props;const localeService = useDependency(LocaleService);const direction = useObservable(localeService.direction$, localeService.getDirection());@@ -386,7 +379,7 @@ const IconSetRuleEdit = (props: {<DropdownComponentoverlay={(<div className="univer-rounded-lg univer-p-4">- <IconItemList onClick={handleIconClick} iconId={item.iconId} iconType={item.iconType} />+ <IconItemList onClick={handleIconClick} /></div>)}>@@ -396,7 +389,7 @@ const IconSetRuleEdit = (props: {univer-justify-between univer-rounded-md univer-bg-gray-0 univer-px-4 univer-py-2univer-text-xs univer-text-gray-600 univer-transition-allhover:univer-border-primary-600- dark:!univer-text-gray-200+ dark:!univer-bg-gray-700 dark:!univer-text-gray-0`, borderClassName)}>{icon@@ -417,7 +410,7 @@ const IconSetRuleEdit = (props: {: (<divclassName={`- univer-mt-0 univer-text-sm univer-text-gray-600+ univer-self-center univer-text-sm univer-text-gray-600dark:!univer-text-gray-200`}>@@ -486,6 +479,12 @@ export const IconSet = (props: IStyleEditorProps<unknown, IIconSet>) => {const localeService = useDependency(LocaleService);const direction = useObservable(localeService.direction$, localeService.getDirection());const [errorMap, setErrorMap] = useState<Record<string, string>>({});+ const createDefaultConfigItem = (iconType: IIconSetType, index: number, list: unknown[]): IIconSet['config'][number] => ({+ operator: CFNumberOperator.greaterThan,+ value: { type: CFValueType.num, value: (list.length - 1 - index) * 10 },+ iconType,+ iconId: String(index),+ });const [currentIconType, setCurrentIconType] = useState<IIconSetType>(() => {const defaultV = Object.keys(iconMap)[0] as IIconSetType;if (rule && rule.config.length) {@@ -644,7 +643,12 @@ export const IconSet = (props: IStyleEditorProps<unknown, IIconSet>) => {};return (<div data-u-comp="cf-icon-set-editor" dir={direction}>- <div className="univer-mt-4 univer-text-sm univer-text-gray-600">+ <div+ className="+ univer-mt-4 univer-text-sm univer-text-gray-600+ dark:!univer-text-gray-200+ "+ >{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.styleRule')}</div><div className="univer-mt-3">@@ -664,6 +668,7 @@ export const IconSet = (props: IStyleEditorProps<unknown, IIconSet>) => {univer-justify-between univer-rounded-md univer-bg-gray-0 univer-px-4 univer-py-2univer-text-xs univer-text-gray-600 univer-transition-allhover:univer-border-primary-600+ dark:!univer-bg-gray-700 dark:!univer-text-gray-0`, borderClassName)}>{previewIcon}diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/ColorScale.spec.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/ColorScale.spec.tsxnew file mode 100644index 0000000000..43c16fc996--- /dev/null+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/ColorScale.spec.tsx@@ -0,0 +1,130 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Root } from 'react-dom/client';+import { CFRuleType, CFValueType } from '@univerjs/sheets-conditional-formatting';+import { RediContext } from '@univerjs/ui';+import { act } from 'react';+import { createRoot } from 'react-dom/client';+import { afterEach, describe, expect, it } from 'vitest';+import { ColorScaleStyleEditor } from '../ColorScale';+import { createEditorTestBed, createRuleInterceptorManager, submitRule } from './rule-editor-test-utils';++describe('ColorScaleStyleEditor', () => {+ let root: Root | undefined;+ let container: HTMLDivElement | undefined;+ let currentTestBed: ReturnType<typeof createEditorTestBed> | undefined;++ afterEach(() => {+ act(() => {+ root?.unmount();+ });+ container?.remove();+ currentTestBed?.univer.dispose();+ root = undefined;+ container = undefined;+ currentTestBed = undefined;+ });++ it('submits a two-point color scale when the median value type is disabled', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <ColorScaleStyleEditor+ interceptorManager={interceptorManager}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.colorScale,+ config: [+ { index: 0, value: { type: CFValueType.min } },+ { index: 1, value: { type: CFValueType.max } },+ ],+ });+ });++ it('preserves an existing three-point color scale rule when reopening the editor', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <ColorScaleStyleEditor+ interceptorManager={interceptorManager}+ rule={{+ type: CFRuleType.colorScale,+ config: [+ {+ index: 0,+ color: '#63be7b',+ value: { type: CFValueType.min },+ },+ {+ index: 1,+ color: '#ffeb84',+ value: { type: CFValueType.percentile, value: 50 },+ },+ {+ index: 2,+ color: '#f8696b',+ value: { type: CFValueType.max },+ },+ ],+ }}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.colorScale,+ config: [+ {+ index: 0,+ color: '#63be7b',+ value: { type: CFValueType.min },+ },+ {+ index: 1,+ color: '#ffeb84',+ value: { type: CFValueType.percentile, value: 50 },+ },+ {+ index: 2,+ color: '#f8696b',+ value: { type: CFValueType.max },+ },+ ],+ });+ });+});diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/DataBar.spec.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/DataBar.spec.tsxnew file mode 100644index 0000000000..e35367f202--- /dev/null+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/DataBar.spec.tsx@@ -0,0 +1,114 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Root } from 'react-dom/client';+import { CFRuleType, CFValueType } from '@univerjs/sheets-conditional-formatting';+import { RediContext } from '@univerjs/ui';+import { act } from 'react';+import { createRoot } from 'react-dom/client';+import { afterEach, describe, expect, it } from 'vitest';+import { DataBarStyleEditor } from '../DataBar';+import { createEditorTestBed, createRuleInterceptorManager, submitRule } from './rule-editor-test-utils';++describe('DataBarStyleEditor', () => {+ let root: Root | undefined;+ let container: HTMLDivElement | undefined;+ let currentTestBed: ReturnType<typeof createEditorTestBed> | undefined;++ afterEach(() => {+ act(() => {+ root?.unmount();+ });+ container?.remove();+ currentTestBed?.univer.dispose();+ root = undefined;+ container = undefined;+ currentTestBed = undefined;+ });++ it('submits data bar rule configuration with min/max value types and visibility', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <DataBarStyleEditor+ interceptorManager={interceptorManager}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.dataBar,+ isShowValue: true,+ config: {+ min: { type: CFValueType.min },+ max: { type: CFValueType.max },+ isGradient: false,+ },+ });+ });++ it('preserves custom colors, gradient fill, thresholds, and hidden cell values when reopening a data bar rule', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <DataBarStyleEditor+ interceptorManager={interceptorManager}+ rule={{+ type: CFRuleType.dataBar,+ isShowValue: false,+ config: {+ min: { type: CFValueType.percent, value: 15 },+ max: { type: CFValueType.percentile, value: 85 },+ isGradient: true,+ positiveColor: '#63be7b',+ nativeColor: '#f8696b',+ },+ }}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.dataBar,+ isShowValue: false,+ config: {+ min: { type: CFValueType.percent, value: 15 },+ max: { type: CFValueType.percentile, value: 85 },+ isGradient: true,+ positiveColor: '#63be7b',+ nativeColor: '#f8696b',+ },+ });+ });+});diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/Formula.spec.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/Formula.spec.tsxnew file mode 100644index 0000000000..139f23f7f7--- /dev/null+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/Formula.spec.tsx@@ -0,0 +1,123 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Root } from 'react-dom/client';+import { CFRuleType, CFSubRuleType } from '@univerjs/sheets-conditional-formatting';+import { RediContext } from '@univerjs/ui';+import { act } from 'react';+import { createRoot } from 'react-dom/client';+import { afterEach, describe, expect, it } from 'vitest';+import type { createEditorTestBed } from './rule-editor-test-utils';+import { FormulaStyleEditor } from '../Formula';+import { beforeSubmit } from '../type';+import { createFormulaEditorTestBed, createRuleInterceptorManager, submitRule } from './rule-editor-test-utils';++describe('FormulaStyleEditor', () => {+ let root: Root | undefined;+ let container: HTMLDivElement | undefined;+ let currentTestBed: ReturnType<typeof createEditorTestBed> | undefined;++ afterEach(() => {+ act(() => {+ root?.unmount();+ });+ container?.remove();+ currentTestBed?.univer.dispose();+ root = undefined;+ container = undefined;+ currentTestBed = undefined;+ });++ it('preserves an existing formula highlight rule and validates it through beforeSubmit', async () => {+ currentTestBed = createFormulaEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <FormulaStyleEditor+ interceptorManager={interceptorManager}+ rule={{+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.formula,+ value: '=MOD(ROW(),2)=0',+ style: {+ bg: {+ rgb: '#ddebf7',+ },+ cl: {+ rgb: '#1f4e79',+ },+ },+ }}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);+ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.formula,+ value: '=MOD(ROW(),2)=0',+ style: {+ bg: {+ rgb: '#ddebf7',+ },+ cl: {+ rgb: '#1f4e79',+ },+ },+ });+ });++ it('blocks submitting a reopened formula highlight rule with an invalid formula', async () => {+ currentTestBed = createFormulaEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <FormulaStyleEditor+ interceptorManager={interceptorManager}+ rule={{+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.formula,+ value: '=SUM(',+ style: {+ bg: {+ rgb: '#fce4d6',+ },+ },+ }}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(false);+ });+});diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/HighlightCell.spec.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/HighlightCell.spec.tsxnew file mode 100644index 0000000000..dcf525d385--- /dev/null+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/HighlightCell.spec.tsx@@ -0,0 +1,268 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Root } from 'react-dom/client';+import { CFNumberOperator, CFRuleType, CFSubRuleType, CFTextOperator, CFTimePeriodOperator } from '@univerjs/sheets-conditional-formatting';+import { RediContext } from '@univerjs/ui';+import { act } from 'react';+import { createRoot } from 'react-dom/client';+import { afterEach, describe, expect, it } from 'vitest';+import { HighlightCellStyleEditor } from '../HighlightCell';+import { beforeSubmit } from '../type';+import { createEditorTestBed, createRuleInterceptorManager, inputText, selectOption, submitRule } from './rule-editor-test-utils';++describe('HighlightCellStyleEditor', () => {+ let root: Root | undefined;+ let container: HTMLDivElement | undefined;+ let currentTestBed: ReturnType<typeof createEditorTestBed> | undefined;++ afterEach(() => {+ act(() => {+ root?.unmount();+ });+ container?.remove();+ currentTestBed?.univer.dispose();+ root = undefined;+ container = undefined;+ currentTestBed = undefined;+ });++ it('blocks submitting an empty text condition and submits the entered text condition rule', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();+ let lastRule: unknown;++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <HighlightCellStyleEditor+ interceptorManager={interceptorManager}+ onChange={(rule) => {+ lastRule = rule;+ }}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ let canSubmit: unknown;++ await act(async () => {+ canSubmit = interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null);+ await Promise.resolve();+ });++ expect(canSubmit).toBe(false);++ const textInput = container.querySelector('input[type="text"]') as HTMLInputElement;++ await act(async () => {+ inputText(textInput, 'overdue');+ await Promise.resolve();+ });++ await act(async () => {+ canSubmit = interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null);+ await Promise.resolve();+ });++ expect(canSubmit).toBe(true);+ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.text,+ value: 'overdue',+ });+ expect(lastRule).toMatchObject({+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.text,+ value: 'overdue',+ });+ });++ it('preserves an existing number highlight rule when reopening the editor', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <HighlightCellStyleEditor+ interceptorManager={interceptorManager}+ rule={{+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.number,+ operator: CFNumberOperator.between,+ value: [5, 12],+ style: {+ bg: {+ rgb: '#ffeecc',+ },+ },+ }}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.number,+ operator: CFNumberOperator.between,+ value: [5, 12],+ style: {+ bg: {+ rgb: '#ffeecc',+ },+ },+ });+ });++ it('preserves an existing text highlight rule and validates it through beforeSubmit', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <HighlightCellStyleEditor+ interceptorManager={interceptorManager}+ rule={{+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.text,+ operator: CFTextOperator.endsWith,+ value: '.com',+ style: {+ cl: {+ rgb: '#0070c0',+ },+ },+ }}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);+ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.text,+ operator: CFTextOperator.endsWith,+ value: '.com',+ style: {+ cl: {+ rgb: '#0070c0',+ },+ },+ });+ });++ it('preserves an existing time period highlight rule without requiring an input value', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <HighlightCellStyleEditor+ interceptorManager={interceptorManager}+ rule={{+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.timePeriod,+ operator: CFTimePeriodOperator.last7Days,+ style: {+ bg: {+ rgb: '#fff2cc',+ },+ },+ }}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);+ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.timePeriod,+ operator: CFTimePeriodOperator.last7Days,+ style: {+ bg: {+ rgb: '#fff2cc',+ },+ },+ });+ });++ it('submits a duplicate-values highlight rule after switching the condition type', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();+ let lastRule: unknown;++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <HighlightCellStyleEditor+ interceptorManager={interceptorManager}+ onChange={(rule) => {+ lastRule = rule;+ }}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ await act(async () => {+ await selectOption(0, 'duplicateValues');+ await Promise.resolve();+ });++ expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);+ const submittedRule = submitRule(interceptorManager);+ expect(submittedRule).toMatchObject({+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.duplicateValues,+ });+ expect(submittedRule).not.toHaveProperty('operator');+ expect(lastRule).toMatchObject({+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.duplicateValues,+ });+ expect(lastRule).not.toHaveProperty('operator');+ });+});diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/IconSet.spec.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/IconSet.spec.tsxnew file mode 100644index 0000000000..bb6e192d63--- /dev/null+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/IconSet.spec.tsx@@ -0,0 +1,222 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Root } from 'react-dom/client';+import { LocaleService } from '@univerjs/core';+import { CFNumberOperator, CFRuleType, CFValueType, IIconSetType } from '@univerjs/sheets-conditional-formatting';+import { RediContext } from '@univerjs/ui';+import { act } from 'react';+import { createRoot } from 'react-dom/client';+import { afterEach, describe, expect, it } from 'vitest';+import { IconSet } from '../IconSet';+import { beforeSubmit } from '../type';+import { createEditorTestBed, createRuleInterceptorManager, openDropdown, submitRule } from './rule-editor-test-utils';++describe('IconSet', () => {+ let root: Root | undefined;+ let container: HTMLDivElement | undefined;+ let currentTestBed: ReturnType<typeof createEditorTestBed> | undefined;++ afterEach(() => {+ act(() => {+ root?.unmount();+ });+ container?.remove();+ currentTestBed?.univer.dispose();+ root = undefined;+ container = undefined;+ currentTestBed = undefined;+ });++ it('keeps the icon-set gallery grid RTL when the locale direction is RTL', async () => {+ currentTestBed = createEditorTestBed();+ currentTestBed.get(LocaleService).setDirection('rtl');+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <IconSet interceptorManager={interceptorManager} onChange={() => undefined} />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ await openDropdown(0);++ expect(document.querySelector('[data-u-comp="cf-icon-set-group-grid"]')?.getAttribute('dir')).toBe('rtl');+ expect(document.querySelector('[data-u-comp="cf-icon-set-group-grid"] button > span')?.getAttribute('dir')).toBe('rtl');+ });++ it('submits a valid default icon set rule with visible cell values', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <IconSet+ interceptorManager={interceptorManager}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);+ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.iconSet,+ isShowValue: true,+ config: [+ {+ iconType: '3Arrows',+ iconId: '0',+ value: { type: CFValueType.num, value: 20 },+ },+ {+ iconType: '3Arrows',+ iconId: '1',+ value: { type: CFValueType.num, value: 10 },+ },+ {+ iconType: '3Arrows',+ iconId: '2',+ value: { type: CFValueType.num, value: Number.MAX_SAFE_INTEGER },+ },+ ],+ });+ });++ it('preserves an existing icon set rule with hidden cell values', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <IconSet+ interceptorManager={interceptorManager}+ rule={{+ type: CFRuleType.iconSet,+ isShowValue: false,+ config: [+ {+ iconType: IIconSetType.threeTrafficLights1,+ iconId: '0',+ operator: CFNumberOperator.greaterThanOrEqual,+ value: { type: CFValueType.percent, value: 75 },+ },+ {+ iconType: IIconSetType.threeTrafficLights1,+ iconId: '1',+ operator: CFNumberOperator.greaterThan,+ value: { type: CFValueType.percent, value: 25 },+ },+ {+ iconType: IIconSetType.threeTrafficLights1,+ iconId: '2',+ operator: CFNumberOperator.lessThanOrEqual,+ value: { type: CFValueType.percent, value: Number.MAX_SAFE_INTEGER },+ },+ ],+ }}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);+ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.iconSet,+ isShowValue: false,+ config: [+ {+ iconType: IIconSetType.threeTrafficLights1,+ iconId: '0',+ value: { type: CFValueType.percent, value: 75 },+ },+ {+ iconType: IIconSetType.threeTrafficLights1,+ iconId: '1',+ value: { type: CFValueType.percent, value: 25 },+ },+ {+ iconType: IIconSetType.threeTrafficLights1,+ iconId: '2',+ value: { type: CFValueType.percent, value: Number.MAX_SAFE_INTEGER },+ },+ ],+ });+ });++ it('blocks submitting an icon set whose thresholds are not ordered by their operators', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <IconSet+ interceptorManager={interceptorManager}+ rule={{+ type: CFRuleType.iconSet,+ isShowValue: true,+ config: [+ {+ iconType: IIconSetType.threeArrows,+ iconId: '0',+ operator: CFNumberOperator.greaterThan,+ value: { type: CFValueType.num, value: 20 },+ },+ {+ iconType: IIconSetType.threeArrows,+ iconId: '1',+ operator: CFNumberOperator.greaterThan,+ value: { type: CFValueType.num, value: 30 },+ },+ {+ iconType: IIconSetType.threeArrows,+ iconId: '2',+ operator: CFNumberOperator.lessThanOrEqual,+ value: { type: CFValueType.num, value: Number.MAX_SAFE_INTEGER },+ },+ ],+ }}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(false);+ });+});diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/Rank.spec.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/Rank.spec.tsxnew file mode 100644index 0000000000..74d9a17d58--- /dev/null+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/Rank.spec.tsx@@ -0,0 +1,114 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Root } from 'react-dom/client';+import { CFRuleType, CFSubRuleType } from '@univerjs/sheets-conditional-formatting';+import { RediContext } from '@univerjs/ui';+import { act } from 'react';+import { createRoot } from 'react-dom/client';+import { afterEach, describe, expect, it } from 'vitest';+import { RankStyleEditor } from '../Rank';+import { createEditorTestBed, createRuleInterceptorManager, submitRule } from './rule-editor-test-utils';++describe('RankStyleEditor', () => {+ let root: Root | undefined;+ let container: HTMLDivElement | undefined;+ let currentTestBed: ReturnType<typeof createEditorTestBed> | undefined;++ afterEach(() => {+ act(() => {+ root?.unmount();+ });+ container?.remove();+ currentTestBed?.univer.dispose();+ root = undefined;+ container = undefined;+ currentTestBed = undefined;+ });++ it('submits the configured rank rule instead of a generic highlight rule', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <RankStyleEditor+ interceptorManager={interceptorManager}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.rank,+ isBottom: false,+ isPercent: false,+ value: 10,+ });+ });++ it('preserves an existing bottom percent rank rule when reopening the editor', async () => {+ currentTestBed = createEditorTestBed();+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ const interceptorManager = createRuleInterceptorManager();++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <RankStyleEditor+ interceptorManager={interceptorManager}+ rule={{+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.rank,+ isBottom: true,+ isPercent: true,+ value: 15,+ style: {+ cl: {+ rgb: '#c00000',+ },+ },+ }}+ onChange={() => undefined}+ />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(submitRule(interceptorManager)).toMatchObject({+ type: CFRuleType.highlightCell,+ subType: CFSubRuleType.rank,+ isBottom: true,+ isPercent: true,+ value: 15,+ style: {+ cl: {+ rgb: '#c00000',+ },+ },+ });+ });+});diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/RuleEditors.spec.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/RuleEditors.spec.tsxdeleted file mode 100644index 65d53d3464..0000000000--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/RuleEditors.spec.tsx+++ /dev/null@@ -1,925 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { IConditionalFormattingRuleConfig } from '@univerjs/sheets-conditional-formatting';-import type { Root } from 'react-dom/client';-import { createIdentifier, InterceptorManager, LocaleService, LocaleType } from '@univerjs/core';-import { LexerTreeBuilder } from '@univerjs/engine-formula';-import { IRenderManagerService } from '@univerjs/engine-render';-import { IRefSelectionsService } from '@univerjs/sheets';-import {- CFNumberOperator,- CFRuleType,- CFSubRuleType,- CFTextOperator,- CFTimePeriodOperator,- CFValueType,- IIconSetType,-} from '@univerjs/sheets-conditional-formatting';-import { IContextMenuService, IDialogService, ILayoutService, IShortcutService, RediContext } from '@univerjs/ui';-import { act } from 'react';-import { createRoot } from 'react-dom/client';-import { of, Subject } from 'rxjs';-import { afterEach, describe, expect, it } from 'vitest';-import { createCfUiTestBed } from '../../../../__tests__/create-cf-ui-test-bed';-import enUS from '../../../../locale/en-US';-import { ColorScaleStyleEditor } from '../ColorScale';-import { DataBarStyleEditor } from '../DataBar';-import { FormulaStyleEditor } from '../Formula';-import { HighlightCellStyleEditor } from '../HighlightCell';-import { IconSet } from '../IconSet';-import { RankStyleEditor } from '../Rank';-import { beforeSubmit, submit } from '../type';--(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;--const IEditorService = createIdentifier<TestEditorService>('univer.editor.service');-const IDescriptionService = createIdentifier<TestDescriptionService>('formula.description-service');--class TestLayoutService {- readonly rootContainerElement = document.body;-}--class TestEditorService {- register() {- return { dispose() {} };- }-- getEditor() {- return undefined;- }-- getFocusId() {- return undefined;- }-- focus(): void {}-- blur(): void {}-}--class TestRenderManagerService {- getRenderUnitById() {- return undefined;- }-}--class TestDocSelectionManagerService {- readonly textSelection$ = new Subject();-}--class TestDescriptionService {- hasDefinedNameDescription() {- return false;- }-}--class TestDialogService {- open() {- return { dispose: () => {} };- }-- close(): void {}-- closeAll(): void {}-- getDialogs$() {- return of([]);- }-}--class TestRefSelectionsService {- setSelections(): void {}-- clear(): void {}-}--class TestShortcutService {- registerShortcut() {- return { dispose() {} };- }-}--class TestContextMenuService {- disable(): void {}-- enable(): void {}-}--function createEditorTestBed() {- const testBed = createCfUiTestBed();- testBed.injector.add([ILayoutService, { useClass: TestLayoutService as never }]);- testBed.injector.add([IEditorService, { useClass: TestEditorService as never }]);- testBed.injector.add([IRenderManagerService, { useClass: TestRenderManagerService as never }]);- testBed.injector.add([IDescriptionService, { useClass: TestDescriptionService as never }]);- testBed.injector.add([IDialogService, { useClass: TestDialogService }]);- testBed.injector.add([IRefSelectionsService, { useClass: TestRefSelectionsService as never }]);- testBed.injector.add([IShortcutService, { useClass: TestShortcutService as never }]);- testBed.injector.add([IContextMenuService, { useClass: TestContextMenuService as never }]);- testBed.injector.add([LexerTreeBuilder]);- testBed.get(LocaleService).load({ [LocaleType.EN_US]: enUS, [LocaleType.ZH_CN]: {} });-- return testBed;-}--async function createFormulaEditorTestBed() {- const testBed = createEditorTestBed();- const docsSelectionServiceUrl = new URL('../docs/src/services/doc-selection-manager.service.ts', `file://${process.cwd()}/`).href;- const { DocSelectionManagerService } = await import(/* @vite-ignore */ docsSelectionServiceUrl);- testBed.injector.add([DocSelectionManagerService, { useClass: TestDocSelectionManagerService as never }]);-- return testBed;-}--function createRuleInterceptorManager() {- return new InterceptorManager({ beforeSubmit, submit });-}--function submitRule(interceptorManager: ReturnType<typeof createRuleInterceptorManager>) {- return interceptorManager.fetchThroughInterceptors(submit)(null, null) as IConditionalFormattingRuleConfig | null;-}--function inputText(input: HTMLInputElement, value: string) {- const valueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;- valueSetter?.call(input, value);- input.dispatchEvent(new Event('input', { bubbles: true }));-}--async function selectOption(selectIndex: number, optionText: string) {- const select = Array.from(document.querySelectorAll<HTMLElement>('[data-u-comp="select"]'))[selectIndex];- select.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 }));- select.dispatchEvent(new MouseEvent('click', { bubbles: true }));- await Promise.resolve();-- const option = Array.from(document.querySelectorAll<HTMLElement>('[data-slot="dropdown-menu-radio-item"], [role="menuitemradio"]'))- .find((item) => item.textContent?.includes(optionText));-- if (!option) {- throw new Error(`Rule editor option ${optionText} was not rendered`);- }-- option.dispatchEvent(new MouseEvent('click', { bubbles: true }));-}--async function openDropdown(dropdownIndex: number) {- const dropdown = Array.from(document.querySelectorAll<HTMLElement>('[data-slot="popover-trigger"]'))[dropdownIndex];- if (!dropdown) {- throw new Error(`Dropdown ${dropdownIndex} was not rendered`);- }-- dropdown.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 }));- dropdown.dispatchEvent(new MouseEvent('click', { bubbles: true }));- await Promise.resolve();-}--describe('conditional formatting rule editors', () => {- let root: Root | undefined;- let container: HTMLDivElement | undefined;- let currentTestBed: ReturnType<typeof createEditorTestBed> | undefined;-- afterEach(() => {- act(() => {- root?.unmount();- });- container?.remove();- currentTestBed?.univer.dispose();- root = undefined;- container = undefined;- currentTestBed = undefined;- });-- it('keeps the icon-set gallery grid RTL when the locale direction is RTL', async () => {- currentTestBed = createEditorTestBed();- currentTestBed.get(LocaleService).setDirection('rtl');- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <IconSet interceptorManager={interceptorManager} onChange={() => undefined} />- </RediContext.Provider>- );- await Promise.resolve();- });-- await openDropdown(0);-- expect(document.querySelector('[data-u-comp="cf-icon-set-group-grid"]')?.getAttribute('dir')).toBe('rtl');- expect(document.querySelector('[data-u-comp="cf-icon-set-group-grid"] button')?.className).toContain('univer-justify-start');- expect(document.querySelector('[data-u-comp="cf-icon-set-group-grid"] button > span')?.getAttribute('dir')).toBe('rtl');- expect(document.querySelector('[data-u-comp="cf-icon-set-group-grid"] button > span')?.className).not.toContain('univer-flex-row-reverse');- });-- it('blocks submitting an empty text condition and submits the entered text condition rule', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();- let lastRule: unknown;-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <HighlightCellStyleEditor- interceptorManager={interceptorManager}- onChange={(rule) => {- lastRule = rule;- }}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- let canSubmit: unknown;-- await act(async () => {- canSubmit = interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null);- await Promise.resolve();- });-- expect(canSubmit).toBe(false);-- const textInput = container.querySelector('input[type="text"]') as HTMLInputElement;-- await act(async () => {- inputText(textInput, 'overdue');- await Promise.resolve();- });-- await act(async () => {- canSubmit = interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null);- await Promise.resolve();- });-- expect(canSubmit).toBe(true);- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.highlightCell,- subType: CFSubRuleType.text,- value: 'overdue',- });- expect(lastRule).toMatchObject({- type: CFRuleType.highlightCell,- subType: CFSubRuleType.text,- value: 'overdue',- });- });-- it('submits the configured rank rule instead of a generic highlight rule', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <RankStyleEditor- interceptorManager={interceptorManager}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.highlightCell,- subType: CFSubRuleType.rank,- isBottom: false,- isPercent: false,- value: 10,- });- });-- it('preserves an existing bottom percent rank rule when reopening the editor', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <RankStyleEditor- interceptorManager={interceptorManager}- rule={{- type: CFRuleType.highlightCell,- subType: CFSubRuleType.rank,- isBottom: true,- isPercent: true,- value: 15,- style: {- cl: {- rgb: '#c00000',- },- },- }}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.highlightCell,- subType: CFSubRuleType.rank,- isBottom: true,- isPercent: true,- value: 15,- style: {- cl: {- rgb: '#c00000',- },- },- });- });-- it('submits data bar rule configuration with min/max value types and visibility', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <DataBarStyleEditor- interceptorManager={interceptorManager}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.dataBar,- isShowValue: true,- config: {- min: { type: CFValueType.min },- max: { type: CFValueType.max },- isGradient: false,- },- });- });-- it('preserves custom colors, gradient fill, thresholds, and hidden cell values when reopening a data bar rule', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <DataBarStyleEditor- interceptorManager={interceptorManager}- rule={{- type: CFRuleType.dataBar,- isShowValue: false,- config: {- min: { type: CFValueType.percent, value: 15 },- max: { type: CFValueType.percentile, value: 85 },- isGradient: true,- positiveColor: '#63be7b',- nativeColor: '#f8696b',- },- }}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.dataBar,- isShowValue: false,- config: {- min: { type: CFValueType.percent, value: 15 },- max: { type: CFValueType.percentile, value: 85 },- isGradient: true,- positiveColor: '#63be7b',- nativeColor: '#f8696b',- },- });- });-- it('submits a two-point color scale when the median value type is disabled', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <ColorScaleStyleEditor- interceptorManager={interceptorManager}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.colorScale,- config: [- { index: 0, value: { type: CFValueType.min } },- { index: 1, value: { type: CFValueType.max } },- ],- });- });-- it('preserves an existing three-point color scale rule when reopening the editor', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <ColorScaleStyleEditor- interceptorManager={interceptorManager}- rule={{- type: CFRuleType.colorScale,- config: [- {- index: 0,- color: '#63be7b',- value: { type: CFValueType.min },- },- {- index: 1,- color: '#ffeb84',- value: { type: CFValueType.percentile, value: 50 },- },- {- index: 2,- color: '#f8696b',- value: { type: CFValueType.max },- },- ],- }}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.colorScale,- config: [- {- index: 0,- color: '#63be7b',- value: { type: CFValueType.min },- },- {- index: 1,- color: '#ffeb84',- value: { type: CFValueType.percentile, value: 50 },- },- {- index: 2,- color: '#f8696b',- value: { type: CFValueType.max },- },- ],- });- });-- it('submits a valid default icon set rule with visible cell values', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <IconSet- interceptorManager={interceptorManager}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.iconSet,- isShowValue: true,- config: [- {- iconType: '3Arrows',- iconId: '0',- value: { type: CFValueType.num, value: 20 },- },- {- iconType: '3Arrows',- iconId: '1',- value: { type: CFValueType.num, value: 10 },- },- {- iconType: '3Arrows',- iconId: '2',- value: { type: CFValueType.num, value: Number.MAX_SAFE_INTEGER },- },- ],- });- });-- it('preserves an existing number highlight rule when reopening the editor', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <HighlightCellStyleEditor- interceptorManager={interceptorManager}- rule={{- type: CFRuleType.highlightCell,- subType: CFSubRuleType.number,- operator: CFNumberOperator.between,- value: [5, 12],- style: {- bg: {- rgb: '#ffeecc',- },- },- }}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.highlightCell,- subType: CFSubRuleType.number,- operator: CFNumberOperator.between,- value: [5, 12],- style: {- bg: {- rgb: '#ffeecc',- },- },- });- });-- it('preserves an existing text highlight rule and validates it through beforeSubmit', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <HighlightCellStyleEditor- interceptorManager={interceptorManager}- rule={{- type: CFRuleType.highlightCell,- subType: CFSubRuleType.text,- operator: CFTextOperator.endsWith,- value: '.com',- style: {- cl: {- rgb: '#0070c0',- },- },- }}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.highlightCell,- subType: CFSubRuleType.text,- operator: CFTextOperator.endsWith,- value: '.com',- style: {- cl: {- rgb: '#0070c0',- },- },- });- });-- it('preserves an existing time period highlight rule without requiring an input value', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <HighlightCellStyleEditor- interceptorManager={interceptorManager}- rule={{- type: CFRuleType.highlightCell,- subType: CFSubRuleType.timePeriod,- operator: CFTimePeriodOperator.last7Days,- style: {- bg: {- rgb: '#fff2cc',- },- },- }}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.highlightCell,- subType: CFSubRuleType.timePeriod,- operator: CFTimePeriodOperator.last7Days,- style: {- bg: {- rgb: '#fff2cc',- },- },- });- });-- it('submits a duplicate-values highlight rule after switching the condition type', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();- let lastRule: unknown;-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <HighlightCellStyleEditor- interceptorManager={interceptorManager}- onChange={(rule) => {- lastRule = rule;- }}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- await act(async () => {- await selectOption(0, 'duplicateValues');- await Promise.resolve();- });-- expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);- const submittedRule = submitRule(interceptorManager);- expect(submittedRule).toMatchObject({- type: CFRuleType.highlightCell,- subType: CFSubRuleType.duplicateValues,- });- expect(submittedRule).not.toHaveProperty('operator');- expect(lastRule).toMatchObject({- type: CFRuleType.highlightCell,- subType: CFSubRuleType.duplicateValues,- });- expect(lastRule).not.toHaveProperty('operator');- });-- it('preserves an existing formula highlight rule and validates it through beforeSubmit', async () => {- currentTestBed = await createFormulaEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <FormulaStyleEditor- interceptorManager={interceptorManager}- rule={{- type: CFRuleType.highlightCell,- subType: CFSubRuleType.formula,- value: '=MOD(ROW(),2)=0',- style: {- bg: {- rgb: '#ddebf7',- },- cl: {- rgb: '#1f4e79',- },- },- }}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.highlightCell,- subType: CFSubRuleType.formula,- value: '=MOD(ROW(),2)=0',- style: {- bg: {- rgb: '#ddebf7',- },- cl: {- rgb: '#1f4e79',- },- },- });- });-- it('blocks submitting a reopened formula highlight rule with an invalid formula', async () => {- currentTestBed = await createFormulaEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <FormulaStyleEditor- interceptorManager={interceptorManager}- rule={{- type: CFRuleType.highlightCell,- subType: CFSubRuleType.formula,- value: '=SUM(',- style: {- bg: {- rgb: '#fce4d6',- },- },- }}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(false);- });-- it('preserves an existing icon set rule with hidden cell values', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <IconSet- interceptorManager={interceptorManager}- rule={{- type: CFRuleType.iconSet,- isShowValue: false,- config: [- {- iconType: IIconSetType.threeTrafficLights1,- iconId: '0',- operator: CFNumberOperator.greaterThanOrEqual,- value: { type: CFValueType.percent, value: 75 },- },- {- iconType: IIconSetType.threeTrafficLights1,- iconId: '1',- operator: CFNumberOperator.greaterThan,- value: { type: CFValueType.percent, value: 25 },- },- {- iconType: IIconSetType.threeTrafficLights1,- iconId: '2',- operator: CFNumberOperator.lessThanOrEqual,- value: { type: CFValueType.percent, value: Number.MAX_SAFE_INTEGER },- },- ],- }}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(true);- expect(submitRule(interceptorManager)).toMatchObject({- type: CFRuleType.iconSet,- isShowValue: false,- config: [- {- iconType: IIconSetType.threeTrafficLights1,- iconId: '0',- value: { type: CFValueType.percent, value: 75 },- },- {- iconType: IIconSetType.threeTrafficLights1,- iconId: '1',- value: { type: CFValueType.percent, value: 25 },- },- {- iconType: IIconSetType.threeTrafficLights1,- iconId: '2',- value: { type: CFValueType.percent, value: Number.MAX_SAFE_INTEGER },- },- ],- });- });-- it('blocks submitting an icon set whose thresholds are not ordered by their operators', async () => {- currentTestBed = createEditorTestBed();- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);- const interceptorManager = createRuleInterceptorManager();-- await act(async () => {- root!.render(- <RediContext.Provider value={{ injector: currentTestBed!.injector }}>- <IconSet- interceptorManager={interceptorManager}- rule={{- type: CFRuleType.iconSet,- isShowValue: true,- config: [- {- iconType: IIconSetType.threeArrows,- iconId: '0',- operator: CFNumberOperator.greaterThan,- value: { type: CFValueType.num, value: 20 },- },- {- iconType: IIconSetType.threeArrows,- iconId: '1',- operator: CFNumberOperator.greaterThan,- value: { type: CFValueType.num, value: 30 },- },- {- iconType: IIconSetType.threeArrows,- iconId: '2',- operator: CFNumberOperator.lessThanOrEqual,- value: { type: CFValueType.num, value: Number.MAX_SAFE_INTEGER },- },- ],- }}- onChange={() => undefined}- />- </RediContext.Provider>- );- await Promise.resolve();- });-- expect(interceptorManager.fetchThroughInterceptors(beforeSubmit)(true, null)).toBe(false);- });-});diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/rule-editor-test-utils.ts b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/rule-editor-test-utils.tsnew file mode 100644index 0000000000..98fee061fc--- /dev/null+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/rule-editor-test-utils.ts@@ -0,0 +1,166 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { IConditionalFormattingRuleConfig } from '@univerjs/sheets-conditional-formatting';+import { createIdentifier, InterceptorManager, LocaleService, LocaleType } from '@univerjs/core';+import { DocSelectionManagerService } from '@univerjs/docs';+import { LexerTreeBuilder } from '@univerjs/engine-formula';+import { IRenderManagerService } from '@univerjs/engine-render';+import { IRefSelectionsService } from '@univerjs/sheets';+import { IContextMenuService, IDialogService, ILayoutService, IShortcutService } from '@univerjs/ui';+import { of, Subject } from 'rxjs';+import { createCfUiTestBed } from '../../../../__tests__/create-cf-ui-test-bed';+import enUS from '../../../../locale/en-US';+import { beforeSubmit, submit } from '../type';++(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++const IEditorService = createIdentifier<TestEditorService>('univer.editor.service');+const IDescriptionService = createIdentifier<TestDescriptionService>('formula.description-service');++class TestLayoutService {+ readonly rootContainerElement = document.body;+}++class TestEditorService {+ register() {+ return { dispose() {} };+ }++ getEditor() {+ return undefined;+ }++ getFocusId() {+ return undefined;+ }++ focus(): void {}++ blur(): void {}+}++class TestRenderManagerService {+ getRenderUnitById() {+ return undefined;+ }+}++class TestDocSelectionManagerService {+ readonly textSelection$ = new Subject();+}++class TestDescriptionService {+ hasDefinedNameDescription() {+ return false;+ }+}++class TestDialogService {+ open() {+ return { dispose: () => {} };+ }++ close(): void {}++ closeAll(): void {}++ getDialogs$() {+ return of([]);+ }+}++class TestRefSelectionsService {+ setSelections(): void {}++ clear(): void {}+}++class TestShortcutService {+ registerShortcut() {+ return { dispose() {} };+ }+}++class TestContextMenuService {+ disable(): void {}++ enable(): void {}+}++export function createEditorTestBed() {+ const testBed = createCfUiTestBed();+ testBed.injector.add([ILayoutService, { useClass: TestLayoutService as never }]);+ testBed.injector.add([IEditorService, { useClass: TestEditorService as never }]);+ testBed.injector.add([IRenderManagerService, { useClass: TestRenderManagerService as never }]);+ testBed.injector.add([IDescriptionService, { useClass: TestDescriptionService as never }]);+ testBed.injector.add([IDialogService, { useClass: TestDialogService }]);+ testBed.injector.add([IRefSelectionsService, { useClass: TestRefSelectionsService as never }]);+ testBed.injector.add([IShortcutService, { useClass: TestShortcutService as never }]);+ testBed.injector.add([IContextMenuService, { useClass: TestContextMenuService as never }]);+ testBed.injector.add([LexerTreeBuilder]);+ testBed.get(LocaleService).load({ [LocaleType.EN_US]: enUS, [LocaleType.ZH_CN]: {} });++ return testBed;+}++export function createFormulaEditorTestBed() {+ const testBed = createEditorTestBed();+ testBed.injector.add([DocSelectionManagerService, { useClass: TestDocSelectionManagerService as never }]);++ return testBed;+}++export function createRuleInterceptorManager() {+ return new InterceptorManager({ beforeSubmit, submit });+}++export function submitRule(interceptorManager: ReturnType<typeof createRuleInterceptorManager>) {+ return interceptorManager.fetchThroughInterceptors(submit)(null, null) as IConditionalFormattingRuleConfig | null;+}++export function inputText(input: HTMLInputElement, value: string) {+ const valueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;+ valueSetter?.call(input, value);+ input.dispatchEvent(new Event('input', { bubbles: true }));+}++export async function selectOption(selectIndex: number, optionText: string) {+ const select = Array.from(document.querySelectorAll<HTMLElement>('[data-u-comp="select"]'))[selectIndex];+ select.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 }));+ select.dispatchEvent(new MouseEvent('click', { bubbles: true }));+ await Promise.resolve();++ const option = Array.from(document.querySelectorAll<HTMLElement>('[data-slot="dropdown-menu-radio-item"], [role="menuitemradio"]'))+ .find((item) => item.textContent?.includes(optionText));++ if (!option) {+ throw new Error(`Rule editor option ${optionText} was not rendered`);+ }++ option.dispatchEvent(new MouseEvent('click', { bubbles: true }));+}++export async function openDropdown(dropdownIndex: number) {+ const dropdown = Array.from(document.querySelectorAll<HTMLElement>('[data-slot="popover-trigger"]'))[dropdownIndex];+ if (!dropdown) {+ throw new Error(`Dropdown ${dropdownIndex} was not rendered`);+ }++ dropdown.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 }));+ dropdown.dispatchEvent(new MouseEvent('click', { bubbles: true }));+ await Promise.resolve();+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 478f63fd38..4db27f27fe 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1547,6 +1547,9 @@ importers:'@univerjs-infra/shared':specifier: workspace:*version: link:../../common/shared+ '@univerjs/docs':+ specifier: workspace:*+ version: link:../docspostcss:specifier: ^8.5.32version: 8.5.32