Skip to content

Commit

Permalink
test(utils): [grid,select] add vitest for utils package (#2813)
Browse files Browse the repository at this point in the history
* test(utils): add vitest for utils package

* fix(log): fix

* fix(xss): fix

* fix(grid): add dependence

* fix(grid): fix e2e test

* fix(test): fix
  • Loading branch information
shenjunjian authored Jan 16, 2025
1 parent 9ed39c7 commit 312dbcf
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 788 deletions.
3 changes: 1 addition & 2 deletions examples/sites/demos/pc/app/grid/editor/custom-edit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ import { test, expect } from '@playwright/test'
test('多行编辑', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('grid-editor#editor-custom-edit')
await expect(page.getByRole('row', { name: '1 请选择 保存 取消' }).getByRole('textbox').first()).toBeVisible()
await expect(page.getByRole('row', { name: '2 请选择 保存 取消' }).getByRole('textbox').first()).toBeVisible()
await expect(page.getByRole('textbox', { name: 'GFD 科技有限公司', exact: true })).toBeVisible()
})
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type {
} from '../file-upload'

import { extend } from '@mobile-root/utils/object'
import { xss, log } from '@mobile-root/utils/xss'
import { xss, log } from '@mobile-root/utils'
import uploadAjax from '@mobile-root/utils/deps/upload-ajax'
import { isObject } from '@mobile-root/utils/type'
import { isEmptyObject } from '@mobile-root/utils/type'
Expand Down Expand Up @@ -577,7 +577,7 @@ export const handleStart =
state,
vm
}: Pick<IFileUploadRenderlessParams, 'api' | 'constants' | 'props' | 'state' | 'vm'>) =>
(rawFiles: IFileUploadFile[], updateId: string, reUpload: boolean = false) => {
(rawFiles: IFileUploadFile[], updateId: string, reUpload = false) => {
if (state.isHwh5) {
rawFiles = handleHwh5Files(rawFiles, props.hwh5)
}
Expand Down Expand Up @@ -921,7 +921,7 @@ export const abort =

export const abortDownload =
({ state }: Pick<IFileUploadRenderlessParams, 'state'>) =>
(file: IFileUploadFile, batch: boolean = false) => {
(file: IFileUploadFile, batch = false) => {
const cancel = (docId) => {
if (!docId) return
const cancels = state.downloadCancelToken[docId]
Expand Down Expand Up @@ -2246,7 +2246,7 @@ export const getToken =

export const previewFile =
({ api, props }: Pick<IFileUploadRenderlessParams, 'api' | 'props'>) =>
(file: IFileUploadFile, open: boolean = false) => {
(file: IFileUploadFile, open = false) => {
return new Promise((resolve, reject) => {
try {
const tokenParams = { isOnlinePreview: true, file, type: 'preview', token: props.edm.preview.token }
Expand Down
6 changes: 1 addition & 5 deletions packages/renderless/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
*/

import { log as uLog, xss } from '@opentiny/utils'
import { xss } from '@opentiny/utils'

export const KEY_CODE = {
Backspace: 8,
Expand Down Expand Up @@ -264,8 +264,4 @@ export const CASCADER = {

export const version = process.env.RUNTIME_VERSION

export const log = (data, type = 'log') => {
uLog.logger[type](data)
}

export { xss }
2 changes: 1 addition & 1 deletion packages/renderless/src/tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { on, off } from '../common/deps/dom'
import { getDataset } from '../common/dataset'
import { copyArray } from '../common/object'

import { log } from '../common'
import { log } from '@opentiny/utils'

export const setChildren = (props) => (data) => (props.data = data)

Expand Down
6 changes: 5 additions & 1 deletion packages/utils/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# @opentiny/utils
## 安装

```bash
npm install --save @opentiny/utils
```
8 changes: 5 additions & 3 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@opentiny/utils",
"type": "module",
"version": "1.0.0",
"description": "nanoid console xss",
"author": "",
"license": "ISC",
"type": "module",
"repository": {
"type": "git",
"url": "[email protected]:opentiny/tiny-vue.git"
Expand All @@ -16,14 +16,16 @@
],
"scripts": {
"build": "vite build",
"pub": "pnpm publish --no-git-checks --access=public"
"pub": "pnpm publish --no-git-checks --access=public",
"test": "vitest"
},
"dependencies": {
"xss": "1.0.14"
},
"devDependencies": {
"typescript": "catalog:",
"vite": "catalog:",
"vite-plugin-dts": "~4.3.0",
"vite": "catalog:"
"vitest": "catalog:"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`测试sha256 1`] = `"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"`;
7 changes: 7 additions & 0 deletions packages/utils/src/crypt/__test__/crypt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test, expect } from 'vitest'
import { sha256 } from '../index'

test('测试sha256', async () => {
// 简单记录加密的结果,测试用来保证sha256算法不变化
expect(await sha256('hello world')).toMatchSnapshot()
})
Loading

0 comments on commit 312dbcf

Please sign in to comment.