From c0875ac7b88ddcdc1d3ee49561aef1eb2728057f Mon Sep 17 00:00:00 2001 From: lijinke666 Date: Wed, 13 Nov 2024 11:47:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=B4=A7=E5=87=91?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8B,=20=E6=96=87=E6=9C=AC=E5=B8=A6?= =?UTF-8?q?=E6=9C=89=20'\n'=20=E6=8D=A2=E8=A1=8C=E7=AC=A6=E6=97=B6=20maxLi?= =?UTF-8?q?nes=20=E9=85=8D=E7=BD=AE=E6=9C=AA=E7=94=9F=E6=95=88=E5=92=8C?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=BA=A2=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20closes=20#2963=20#2900?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/data/data-issue-2385.json | 4 +- .../spreadsheet/compare-layout-spec.ts | 56 +++++++++++++++---- .../spreadsheet/multi-line-text-spec.ts | 2 + packages/s2-core/src/utils/merge.ts | 13 +---- 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/packages/s2-core/__tests__/data/data-issue-2385.json b/packages/s2-core/__tests__/data/data-issue-2385.json index e77dd0305c..25429692be 100644 --- a/packages/s2-core/__tests__/data/data-issue-2385.json +++ b/packages/s2-core/__tests__/data/data-issue-2385.json @@ -11,7 +11,7 @@ "province": "浙江", "city": "杭州", "type": "纸张", - "price": "2", + "price": "哈哈哈\n哈哈哈", "cost": "1.5" }, { @@ -153,7 +153,7 @@ "type": "圆规", "province": "吉林", "city": "白山", - "price": "111", + "price": "aa", "cost": "1.5" } ], diff --git a/packages/s2-core/__tests__/spreadsheet/compare-layout-spec.ts b/packages/s2-core/__tests__/spreadsheet/compare-layout-spec.ts index a6c65ffbe7..5e02981bb9 100644 --- a/packages/s2-core/__tests__/spreadsheet/compare-layout-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/compare-layout-spec.ts @@ -43,25 +43,54 @@ describe('Compare Layout Tests', () => { test.each([ { showDefaultHeaderActionIcon: true }, { showDefaultHeaderActionIcon: false }, + ])( + 'should get max col width for pivot sheet and same font size by %o', + async (options) => { + const s2 = new PivotSheet(getContainer(), mockDataConfig, { + ...s2Options, + ...options, + }); + + await s2.render(); + + const colLeafNodes = s2.facet.getColLeafNodes(); + + expect(Math.floor(colLeafNodes[0].width)).toBeCloseTo(122); + expect(Math.floor(colLeafNodes[1].width)).toEqual(95); + expectTextOverflowing(s2); + }, + ); + + // 覆盖 (数值/中文/英文) 三种场景 + test.each([ + { showDefaultHeaderActionIcon: true, fontSize: 20 }, + { showDefaultHeaderActionIcon: true, fontSize: 12 }, + { showDefaultHeaderActionIcon: false, fontSize: 20 }, + { showDefaultHeaderActionIcon: false, fontSize: 12 }, ])('should get max col width for pivot sheet by %o', async (options) => { const s2 = new PivotSheet(getContainer(), mockDataConfig, { ...s2Options, - ...options, + showDefaultHeaderActionIcon: options.showDefaultHeaderActionIcon, }); s2.setTheme({ dataCell: { text: { - fontSize: 20, + fontSize: options.fontSize, }, }, }); await s2.render(); + const isLargeFontSize = options.fontSize === 20; const colLeafNodes = s2.facet.getColLeafNodes(); - expect(Math.floor(colLeafNodes[0].width)).toBeCloseTo(191); - expect(Math.floor(colLeafNodes[1].width)).toEqual(92); + expect(Math.floor(colLeafNodes[0].width)).toBeCloseTo( + isLargeFontSize ? 191 : 122, + ); + expect(Math.floor(colLeafNodes[1].width)).toEqual( + isLargeFontSize ? 145 : 95, + ); expectTextOverflowing(s2); }); @@ -90,13 +119,15 @@ describe('Compare Layout Tests', () => { await s2.render(); const colLeafNodes = s2.facet.getColLeafNodes(); - - expect(Math.floor(colLeafNodes[0].width)).toBeCloseTo(183); - expectTextOverflowing(s2); const { dataCellWidthList, colLeafNodeWidthList } = mapWidthList(s2); + const expectWidth = 183; - expect(dataCellWidthList.every((width) => width === 183)).toBeTruthy(); - expect(colLeafNodeWidthList).toEqual([183]); + expect(Math.floor(colLeafNodes[0].width)).toBeCloseTo(expectWidth); + expect( + dataCellWidthList.every((width) => width === expectWidth), + ).toBeTruthy(); + expect(colLeafNodeWidthList).toEqual([expectWidth]); + expectTextOverflowing(s2); }); test.each([ @@ -137,12 +168,13 @@ describe('Compare Layout Tests', () => { expect(dataCellWidthList).toEqual( options.showDefaultHeaderActionIcon - ? [209, 209, 209, 209, 110, 110, 110, 110, 85, 85, 85, 85] - : [209, 209, 209, 209, 110, 110, 110, 110, 69, 69, 69, 69], + ? [209, 209, 209, 209, 163, 163, 163, 163, 85, 85, 85, 85] + : [209, 209, 209, 209, 163, 163, 163, 163, 69, 69, 69, 69], ); expect(colLeafNodeWidthList).toEqual( - options.showDefaultHeaderActionIcon ? [209, 110, 85] : [209, 110, 69], + options.showDefaultHeaderActionIcon ? [209, 163, 85] : [209, 163, 69], ); + expectTextOverflowing(s2); }, ); }); diff --git a/packages/s2-core/__tests__/spreadsheet/multi-line-text-spec.ts b/packages/s2-core/__tests__/spreadsheet/multi-line-text-spec.ts index dd2cd4f234..c9bfbbe2f6 100644 --- a/packages/s2-core/__tests__/spreadsheet/multi-line-text-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/multi-line-text-spec.ts @@ -214,6 +214,7 @@ describe('SpreadSheet Multi Line Text Tests', () => { // wordWrap 关闭时, 不会渲染省略号 cells.forEach((cell) => { expect(cell.getActualText()).not.toContain('...'); + expect(cell.isTextOverflowing()).toBeFalsy(); }); }); expectColHierarchyHeight(90); @@ -629,6 +630,7 @@ describe('SpreadSheet Multi Line Text Tests', () => { // wordWrap 关闭时, 不会渲染省略号 cells.forEach((cell) => { expect(cell.getActualText()).not.toContain('...'); + expect(cell.isTextOverflowing()).toBeFalsy(); }); }); }); diff --git a/packages/s2-core/src/utils/merge.ts b/packages/s2-core/src/utils/merge.ts index 173a84607d..ad42bae6ff 100644 --- a/packages/s2-core/src/utils/merge.ts +++ b/packages/s2-core/src/utils/merge.ts @@ -1,6 +1,6 @@ import { isArray, isEmpty, isEqual, isString, mergeWith, uniq } from 'lodash'; import { DEFAULT_DATA_CONFIG } from '../common/constant/dataConfig'; -import { DEFAULT_OPTIONS, LayoutWidthType } from '../common/constant/options'; +import { DEFAULT_OPTIONS } from '../common/constant/options'; import type { CustomHeaderFields, Fields, @@ -68,14 +68,5 @@ export const setupDataConfig = ( export const setupOptions = ( options: Partial | null | undefined, ): S2Options => { - const mergedOptions = customMerge(DEFAULT_OPTIONS, options); - - if ( - mergedOptions.style?.layoutWidthType === LayoutWidthType.Compact && - mergedOptions.style?.dataCell!.maxLines! <= 1 - ) { - mergedOptions.style.dataCell!.wordWrap = false; - } - - return mergedOptions; + return customMerge(DEFAULT_OPTIONS, options); };