Skip to content

Commit

Permalink
feat: add test for column header in facade
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed May 28, 2024
1 parent ae75bbe commit fad8abc
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions packages/facade/src/apis/__tests__/facade.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import { beforeEach, describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { ICellData, IStyleData, Nullable } from '@univerjs/core';
import { ICommandService, IUniverInstanceService } from '@univerjs/core';
import { SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand } from '@univerjs/sheets';
import type { Injector } from '@wendellhu/redi';

import type { RenderComponentType, SheetComponent } from '@univerjs/engine-render';
import type { ColumnHeaderLayout, RenderComponentType, SheetComponent, SpreadsheetColumnHeader } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
import { SHEET_VIEW_KEY } from '@univerjs/sheets-ui';
import { RegisterFunctionMutation, SetFormulaCalculationStartMutation, UnregisterFunctionMutation } from '@univerjs/engine-formula';
Expand Down Expand Up @@ -102,6 +102,15 @@ describe('Test FUniver', () => {

return renderComponent;
};

vi.useFakeTimers();
vi.spyOn(window, 'requestAnimationFrame').mockImplementation((callback) => {
return setTimeout(callback, 16); // 假设一帧大约16毫秒
});
});

afterEach(() => {
(window.requestAnimationFrame as any).mockRestore();
});

it('Function onBeforeCommandExecute', () => {
Expand Down Expand Up @@ -267,4 +276,22 @@ describe('Test FUniver', () => {
},
]);
});

it('Function customizeColumnHeader', () => {
const unitId = univerAPI.getActiveWorkbook()?.getId() || '';
const columnRenderComp = getSheetRenderComponent(unitId, SHEET_VIEW_KEY.COLUMN) as SpreadsheetColumnHeader;
if (!columnRenderComp) return;
const columnHeaderExt = columnRenderComp.extensions.get('DefaultColumnHeaderLayoutExtension')! as ColumnHeaderLayout;

const spy = vi.spyOn(columnHeaderExt, 'draw');

univerAPI.customizeColumnHeader({ headerStyle: { backgroundColor: 'pink', fontSize: 9 }, columnsCfg: ['ASC', 'MokaII', undefined, { text: 'Size', textAlign: 'left' }, { text: 'MUJI', fontSize: 15, textAlign: 'right' }, { text: 'SRI-RESOLVE', fontSize: 10, textAlign: 'left', fontColor: 'blue', backgroundColor: 'wheat' }, null, null, 'ss', { fontSize: 29, fontColor: 'red', text: 'hash' }] });
expect(columnHeaderExt.headerStyle.backgroundColor).toBe('pink');
expect(columnHeaderExt.headerStyle.fontSize).toBe(9);
expect(columnHeaderExt.headerStyle.borderColor).toBe('rgb(217,217,217)');
expect(columnHeaderExt.columnsCfg.length).toBe(10);

vi.advanceTimersByTime(16); // 模拟时间流逝
expect(spy).toHaveBeenCalled();
});
});

0 comments on commit fad8abc

Please sign in to comment.