Skip to content

Commit

Permalink
refactor!: remove runOnLifecycle and add smoking tests (#3672)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Actions <[email protected]>
  • Loading branch information
wzhudev and actions-user authored Oct 10, 2024
1 parent a2f2215 commit f5e97b1
Show file tree
Hide file tree
Showing 275 changed files with 1,458 additions and 1,442 deletions.
10 changes: 4 additions & 6 deletions common/storybook/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
* limitations under the License.
*/

import React from 'react';
import type { Preview } from '@storybook/react';
import { ConfigProvider, defaultTheme, greenTheme, themeInstance } from '@univerjs/design';
import zhCN from '@univerjs/design/locale/zh-CN';
import enUS from '@univerjs/design/locale/en-US';
import {
CommandService,
ConfigService,
Expand All @@ -35,7 +31,6 @@ import {
IResourceManagerService,
IUndoRedoService,
IUniverInstanceService,
LifecycleInitializerService,
LifecycleService,
LocaleService,
LocaleType,
Expand All @@ -46,7 +41,11 @@ import {
ThemeService,
UniverInstanceService,
} from '@univerjs/core';
import { ConfigProvider, defaultTheme, greenTheme, themeInstance } from '@univerjs/design';
import enUS from '@univerjs/design/locale/en-US';
import zhCN from '@univerjs/design/locale/zh-CN';
import { DesktopLocalStorageService } from '@univerjs/ui';
import React from 'react';

export const themes: Record<string, Record<string, string>> = {
default: defaultTheme,
Expand Down Expand Up @@ -94,7 +93,6 @@ const preview: Preview = {
[LocaleService],
[ThemeService],
[LifecycleService],
[LifecycleInitializerService],
[ILogService, { useClass: DesktopLogService, lazy: true }],
[ICommandService, { useClass: CommandService, lazy: true }],
[IUndoRedoService, { useClass: LocalUndoRedoService, lazy: true }],
Expand Down
1 change: 0 additions & 1 deletion e2e/disposing/disposing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ test('no error on constructing and disposing sheet unit', async ({ page }) => {
});

test('no error when dispose a unit', async ({ page }) => {
// test.setTimeout(40 * 1000);
let errored = false;

page.on('pageerror', (error) => {
Expand Down
6 changes: 6 additions & 0 deletions e2e/smoking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Notes on Smoking

These tests make sure that all the demo pages can be loaded without any errors. Some demos are implemented in visual comparison tests, so they are not included in this suite.

- docs
- sheets
31 changes: 31 additions & 0 deletions e2e/smoking/mobile-s/mobile-s-smoking.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* 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 { expect, test } from '@playwright/test';

test('ensure mobile-s boots up without errors', async ({ page }) => {
let errored = false;

page.on('pageerror', (error) => {
console.error('Page error:', error);
errored = true;
});

await page.goto('http://localhost:3000/mobile-s/');
await page.waitForTimeout(10000);

expect(errored).toBeFalsy();
});
31 changes: 31 additions & 0 deletions e2e/smoking/sheets-multi/sheets-multi-smoking.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* 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 { expect, test } from '@playwright/test';

test('ensure sheets-multi boots up without errors', async ({ page }) => {
let errored = false;

page.on('pageerror', (error) => {
console.error('Page error:', error);
errored = true;
});

await page.goto('http://localhost:3000/sheets-multi/');
await page.waitForTimeout(10000);

expect(errored).toBeFalsy();
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@
* limitations under the License.
*/

import { Disposable, Inject, LifecycleStages, LocaleService, OnLifecycle } from '@univerjs/core';
import { expect, test } from '@playwright/test';

@OnLifecycle(LifecycleStages.Rendered, NumfmtI18nController)
export class NumfmtI18nController extends Disposable {
constructor(@Inject(LocaleService) private _localeService: LocaleService) {
super();
}
}
test('ensure uni boots up without errors', async ({ page }) => {
let errored = false;

page.on('pageerror', (error) => {
console.error('Page error:', error);
errored = true;
});

await page.goto('http://localhost:3000/uni/');
await page.waitForTimeout(10000);

expect(errored).toBeFalsy();
});
4 changes: 3 additions & 1 deletion e2e/visual-comparison/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Notes on visual comparison
# Notes on Visual Comparison

You should set `maxDiffPixels` on a minimum value. The cursor may be different in snapshots because it is blinking,
especially in rich-text editors.

For more instructions, please read related part in [CONTRIBUTING.md](../../CONTRIBUTING.md).
8 changes: 8 additions & 0 deletions e2e/visual-comparison/docs/docs-visual-comparison.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ import { expect, test } from '@playwright/test';
import { generateSnapshotName } from '../const';

test('diff default doc content', async ({ page }) => {
let errored = false;

page.on('pageerror', (error) => {
console.error('Page error:', error);
errored = true;
});

await page.goto('http://localhost:3000/docs/');
await page.waitForTimeout(2000);

await page.evaluate(() => window.E2EControllerAPI.loadDefaultDoc());
await page.waitForTimeout(5000);

await expect(page).toHaveScreenshot(generateSnapshotName('default-doc'), { maxDiffPixels: 30 });
expect(errored).toBeFalsy();
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ test('diff default sheet content', async ({ page }) => {
});

test('diff demo sheet content', async ({ page }) => {
let errored = false;

page.on('pageerror', (error) => {
console.error('Page error:', error);
errored = true;
});

await page.goto('http://localhost:3000/sheets/');
await page.waitForTimeout(2000);

await page.evaluate(() => window.E2EControllerAPI.loadDemoSheet());
await page.waitForTimeout(5000);

await expect(page).toHaveScreenshot(generateSnapshotName('demo-sheet'), { maxDiffPixels: 5 });
expect(errored).toBeFalsy();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions examples/src/mobile-s/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';
import { UniverSheetsPlugin } from '@univerjs/sheets';
import { UniverSheetsConditionalFormattingMobileUIPlugin } from '@univerjs/sheets-conditional-formatting-ui';
import { UniverSheetsDataValidationPlugin } from '@univerjs/sheets-data-validation';
import { UniverSheetsDataValidationMobileUIPlugin } from '@univerjs/sheets-data-validation-ui';
import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';
import { UniverSheetsFilterMobileUIPlugin } from '@univerjs/sheets-filter-ui';
import { UniverSheetsFormulaMobilePlugin } from '@univerjs/sheets-formula';
import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula';
import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';
import { UniverSheetsMobileUIPlugin } from '@univerjs/sheets-ui';
import { UniverMobileUIPlugin } from '@univerjs/ui';
Expand Down Expand Up @@ -65,9 +66,10 @@ univer.registerPlugin(UniverSheetsMobileUIPlugin);
univer.registerPlugin(UniverSheetsFilterPlugin);
univer.registerPlugin(UniverSheetsFilterMobileUIPlugin);
univer.registerPlugin(UniverSheetsNumfmtPlugin);
univer.registerPlugin(UniverSheetsFormulaMobilePlugin);
univer.registerPlugin(UniverSheetsFormulaPlugin);
univer.registerPlugin(UniverSheetsConditionalFormattingMobileUIPlugin);
univer.registerPlugin(UniverSheetsDataValidationPlugin);
univer.registerPlugin(UniverSheetsDataValidationMobileUIPlugin);

const mockUser = {
userID: 'Owner_qxVnhPbQ',
Expand Down
4 changes: 3 additions & 1 deletion examples/src/sheets-multi/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { defaultTheme } from '@univerjs/design';

import { UniverDocsPlugin } from '@univerjs/docs';
import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
import { DEFAULT_WORKBOOK_DATA_DEMO } from '@univerjs/mockdata';
import { UniverSheetsPlugin } from '@univerjs/sheets';
Expand All @@ -29,8 +30,8 @@ import { UniverUIPlugin } from '@univerjs/ui';
import React, { useEffect } from 'react';
import { createRoot } from 'react-dom/client';
import { Mosaic, MosaicWindow } from 'react-mosaic-component';
import { enUS, ruRU, zhCN } from '../locales';

import { enUS, ruRU, zhCN } from '../locales';
import 'react-mosaic-component/react-mosaic-component.css';
import './index.css';

Expand All @@ -47,6 +48,7 @@ function factory(id: string) {
logLevel: LogLevel.VERBOSE,
});

univer.registerPlugin(UniverFormulaEnginePlugin);
univer.registerPlugin(UniverRenderEnginePlugin);
univer.registerPlugin(UniverUIPlugin, {
container: id,
Expand Down
2 changes: 1 addition & 1 deletion examples/src/sheets/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
import { FUniver } from '@univerjs/facade';
import { DEFAULT_WORKBOOK_DATA_DEMO } from '@univerjs/mockdata';

import { DEFAULT_WORKBOOK_DATA_DEMO } from '@univerjs/mockdata';
import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';
import { UniverSheetsPlugin } from '@univerjs/sheets';
import { UniverSheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting';
Expand Down
11 changes: 3 additions & 8 deletions examples/src/uni/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ import { UniSlidesUIController } from '@univerjs/uni-slides-ui';
import { UniverUniUIPlugin } from '@univerjs/uniui';
import { enUS } from '../locales';

/* eslint-disable-next-line node/prefer-global/process */
const IS_E2E: boolean = !!process.env.IS_E2E;

const LOAD_LAZY_PLUGINS_TIMEOUT = 4_000;

// univer
Expand Down Expand Up @@ -99,11 +96,9 @@ class CustomMentionDataService implements IThreadCommentMentionDataService {
}

// create univer instances
if (!IS_E2E) {
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
univer.createUnit(UniverInstanceType.UNIVER_DOC, DEFAULT_DOCUMENT_DATA_EN);
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO1);
}
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
univer.createUnit(UniverInstanceType.UNIVER_DOC, DEFAULT_DOCUMENT_DATA_EN);
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO1);

// debugger plugin
univer.registerPlugin(UniverDebuggerPlugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

import { Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { Disposable, ICommandService, Inject, Injector } from '@univerjs/core';
import { ComponentManager, IMenuManagerService } from '@univerjs/ui';

import { CreateFloatDomCommand } from '../commands/commands/float-dom.command';
import { CreateEmptySheetCommand, DisposeCurrentUnitCommand, DisposeUniverCommand, LoadSheetSnapshotCommand } from '../commands/commands/unit.command';
import { ShowCellContentOperation } from '../commands/operations/cell.operation';
Expand All @@ -28,19 +27,18 @@ import { MessageOperation } from '../commands/operations/message.operation';
import { NotificationOperation } from '../commands/operations/notification.operation';
import { SaveSnapshotOptions } from '../commands/operations/save-snapshot.operations';
import { SetEditable } from '../commands/operations/set.editable.operation';

import { SidebarOperation } from '../commands/operations/sidebar.operation';

import { ThemeOperation } from '../commands/operations/theme.operation';
import { ImageDemo } from '../components/Image';

// @ts-ignore
import VueI18nIcon from '../components/VueI18nIcon.vue';

import { TEST_EDITOR_CONTAINER_COMPONENT } from '../views/test-editor/component-name';
import { TestEditorContainer } from '../views/test-editor/TestTextEditor';
import { RecordController } from './local-save/record.controller';
import { menuSchema } from './menu.schema';

@OnLifecycle(LifecycleStages.Ready, DebuggerController)
export class DebuggerController extends Disposable {
constructor(
@Inject(Injector) private readonly _injector: Injector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* limitations under the License.
*/

import { Inject, IUniverInstanceService, LifecycleService, LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { distinctUntilChanged, filter, take, takeUntil } from 'rxjs';
import type { Nullable } from '@univerjs/core';
import type { Subscription } from 'rxjs';
import { Inject, IUniverInstanceService, LifecycleService, LifecycleStages, RxDisposable } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { distinctUntilChanged, filter, take, takeUntil } from 'rxjs';

@OnLifecycle(LifecycleStages.Rendered, PerformanceMonitorController)
export class PerformanceMonitorController extends RxDisposable {
private _initListener = false;
private _containerElement!: HTMLDivElement;
Expand Down
8 changes: 8 additions & 0 deletions packages-experimental/debugger/src/debugger-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ export class UniverDebuggerPlugin extends Plugin {
this._injector.get(E2EController);
}

override onReady(): void {
this._injector.get(DebuggerController);
}

override onRendered(): void {
this._injector.get(PerformanceMonitorController);
}

getDebuggerController() {
this._debuggerController = this._injector.get(DebuggerController);
return this._debuggerController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
* limitations under the License.
*/

import { ICommandService, IConfigService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { ICommandService, IConfigService, Inject, Injector, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { IMAGE_MENU_ID as DocsImageMenuId } from '@univerjs/docs-drawing-ui';
import { BulletListCommand, DocCreateTableOperation, DocUIController, OrderListCommand, SetInlineFormatBoldCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand } from '@univerjs/docs-ui';
import { ComponentManager, ILayoutService, IMenuManagerService, IShortcutService, IUIPartsService } from '@univerjs/ui';
import { BuiltinUniToolbarItemId, generateCloneMutation, UniToolbarService } from '@univerjs/uniui';
import { DOC_BOLD_MUTATION_ID, DOC_ITALIC_MUTATION_ID, DOC_STRIKE_MUTATION_ID, DOC_TABLE_MUTATION_ID, DOC_UNDERLINE_MUTATION_ID } from './menu';
import { menuSchema } from './menu.schema';

@OnLifecycle(LifecycleStages.Ready, UniDocsUIController)
export class UniDocsUIController extends DocUIController {
constructor(
@Inject(Injector) injector: Injector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,22 @@
* limitations under the License.
*/

import { CustomRangeType, Disposable, ICommandService, ILogService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { DocumentDataModel } from '@univerjs/core';
import type { IInsertCommandParams } from '@univerjs/docs-ui';
import type { IShowFormulaPopupOperationParams } from '../commands/operations/operation';
import { CustomRangeType, Disposable, ICommandService, ILogService, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';

import { DeleteLeftCommand, DocEventManagerService, IEditorService, InsertCommand, MoveCursorOperation } from '@univerjs/docs-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { filter, map, mergeMap } from 'rxjs';

import type { DocumentDataModel } from '@univerjs/core';
import type { IInsertCommandParams } from '@univerjs/docs-ui';
import { AddDocUniFormulaCommand, RemoveDocUniFormulaCommand, UpdateDocUniFormulaCommand } from '../commands/commands/doc.command';
import { CloseFormulaPopupOperation, ShowFormulaPopupOperation } from '../commands/operations/operation';
import { UniFormulaPopupService } from '../services/formula-popup.service';
import { UNI_FORMULA_EDITOR_ID } from '../views/components/DocFormulaPopup';
import type { IShowFormulaPopupOperationParams } from '../commands/operations/operation';

const FORMULA_INPUT_TRIGGER_CHAR = '=';

@OnLifecycle(LifecycleStages.Steady, DocUniFormulaInputController)
export class DocUniFormulaInputController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
Expand Down
Loading

0 comments on commit f5e97b1

Please sign in to comment.