Skip to content

Commit 043abf3

Browse files
committed
test: 修正前端测试错误
1 parent 2fe612c commit 043abf3

6 files changed

Lines changed: 47 additions & 34 deletions

File tree

apps/docs/src/components/demo/dialog/api.zh-Hans.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@
8484
},
8585
{
8686
"kind": "function",
87-
"name": "xalert",
87+
"name": "Dialog.alert",
8888
"summary": "提供了与\n`alert`\n相同的功能,但是在行为上有些不同。\n`alert`\n是阻塞模式的,而当前函数则是异步函数。\n\n",
89-
"type": "function xalert(msg: string): Promise<void>",
89+
"type": "declare function alert_2(msg: string): Promise<void>",
9090
"params": [
9191
{
9292
"name": "msg",
@@ -101,9 +101,9 @@
101101
},
102102
{
103103
"kind": "function",
104-
"name": "xconfirm",
104+
"name": "Dialog.confirm",
105105
"summary": "提供了与\n`confirm`\n相同的功能,但是在行为上有些不同。\n`confirm`\n是阻塞模式的,而当前函数则是异步函数。\n\n",
106-
"type": "function xconfirm(msg?: string): Promise<boolean>",
106+
"type": "declare function confirm_2(msg?: string): Promise<boolean>",
107107
"params": [
108108
{
109109
"name": "msg",
@@ -118,9 +118,9 @@
118118
},
119119
{
120120
"kind": "function",
121-
"name": "xprompt",
121+
"name": "Dialog.prompt",
122122
"summary": "提供了与\n`prompt`\n相同的功能,但是在行为上有些不同。\n`prompt`\n是阻塞模式的,而当前函数则是异步函数。\n\n",
123-
"type": "function xprompt(msg?: string, val?: string): Promise<string | null>",
123+
"type": "declare function prompt_2(msg?: string, val?: string): Promise<string | null>",
124124
"params": [
125125
{
126126
"name": "msg",

packages/components/src/badge/root.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ describe('Badge', async () => {
5151
const span = c.lastChild;
5252
expect(span).toHaveTextContent('text');
5353
expect(span).toHaveClass(styles.point);
54-
expect(span).toHaveClass(styles.bottomleft);
54+
expect(span).toHaveClass(styles['bottom-left']);
5555
});
5656
});

packages/components/src/formatter/bits.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('createBits', async () => {
2020
expect(f(10261111)).equal('9.786 megabits');
2121
expect(f(9999261111)).equal('9.313 gigabits');
2222

23-
expect(createBits(l, 'bit')(99998888261111)).equal('99998888261111 bits');
23+
expect(createBits(l, 'bit')(99998888261111)).equal('99,998,888,261,111 bits');
2424

25-
expect(createBits(l, 'bit', 'minute')(99998888261111)).equal('99998888261111 bits per minute');
25+
expect(createBits(l, 'bit', 'minute')(99998888261111)).equal('99,998,888,261,111 bits per minute');
2626
});

packages/components/src/formatter/bytes.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ test('createBytes', async () => {
2121
expect(f(9999261111)).equal('9.313 gigabytes');
2222
expect(f(99998888261111)).equal('90.948 terabytes');
2323

24-
expect(createBytes(l, 'byte')(99998888261111)).equal('99998888261111 bytes');
24+
expect(createBytes(l, 'byte')(99998888261111)).equal('99,998,888,261,111 bytes');
2525

2626
expect(createBytes(l, undefined, 'second')(10261111)).equal('9.786 megabytes per second');
2727

28-
expect(createBytes(l, 'byte', 'second')(99998888261111)).equal('99998888261111 bytes per second');
28+
expect(createBytes(l, 'byte', 'second')(99998888261111)).equal('99,998,888,261,111 bytes per second');
2929
});

packages/components/src/page/root.spec.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,43 @@ import { type Ref, Root } from './root';
1010
describe('Page backtop=undefined', async () => {
1111
let ref: Ref;
1212
const ct = await ComponentTester.build('Page', props => (
13-
<Root
14-
{...props}
15-
title="title"
16-
ref={el => {
17-
ref = el;
18-
}}
19-
>
13+
<Root {...props} title="title" ref={el => (ref = el)}>
2014
abc
2115
</Root>
2216
));
2317

2418
test('props', () => ct.testProps());
2519

26-
test('backtop=undefined', () => {
27-
expect(ref!.root()).not.toBeUndefined();
28-
expect(ref!.backTop()).not.toBeUndefined();
20+
test('ref', () => {
21+
expect(ref!.root()).toBeDefined();
22+
expect(ref!.backTop()).toBeDefined();
2923
});
3024
});
3125

32-
describe('Page', async () => {
26+
describe('Page backtop=false', async () => {
3327
let ref: Ref;
3428
await ComponentTester.build('Page', props => (
35-
<Root
36-
backTop={false}
37-
{...props}
38-
title="title"
39-
ref={el => {
40-
ref = el;
41-
}}
42-
>
29+
<Root backTop={false} {...props} title="title" ref={el => (ref = el)}>
4330
abc
4431
</Root>
4532
));
4633

47-
test('backtop=false', async () => {
48-
expect(ref!.root()).not.toBeUndefined();
34+
test('ref', async () => {
35+
expect(ref!.root()).toBeDefined();
4936
expect(ref!.backTop()).toBeUndefined();
5037
});
5138
});
39+
40+
describe('Page backtop=custom', async () => {
41+
let ref: Ref;
42+
await ComponentTester.build('Page', props => (
43+
<Root backTop={{ rounded: true }} {...props} title="title" ref={el => (ref = el)}>
44+
abc
45+
</Root>
46+
));
47+
48+
test('ref', async () => {
49+
expect(ref!.root()).toBeDefined();
50+
expect(ref!.backTop()).toBeDefined();
51+
});
52+
});

packages/components/src/page/root.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface Ref extends BaseRef<HTMLDivElement> {
1313
/**
1414
* 返回顶部按钮的接口
1515
*/
16-
backTop(): BackTop.RootRef;
16+
backTop(): BackTop.RootRef | undefined;
1717
}
1818

1919
export interface Props extends BaseProps, ParentProps, RefProps<Ref> {
@@ -52,7 +52,19 @@ export function Root(props: Props): JSX.Element {
5252
});
5353

5454
return (
55-
<div ref={el => (rootRef = el)} class={joinClass(props.palette, styles.page, props.class)} style={props.style}>
55+
<div
56+
ref={el => {
57+
rootRef = el;
58+
if (props.backTop === false && props.ref) {
59+
props.ref({
60+
root: () => rootRef,
61+
backTop: () => undefined,
62+
});
63+
}
64+
}}
65+
class={joinClass(props.palette, styles.page, props.class)}
66+
style={props.style}
67+
>
5668
{props.children}
5769
<Switch>
5870
<Match when={props.backTop === undefined}>

0 commit comments

Comments
 (0)