Skip to content

Commit

Permalink
fix: center component unit test fail
Browse files Browse the repository at this point in the history
  • Loading branch information
GaoNeng-wWw committed Oct 2, 2024
1 parent cd73cd3 commit 535d4a7
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 15 deletions.
7 changes: 7 additions & 0 deletions doc/docs/components/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@
"label": "Ripple",
"collapsible": true,
"collapsed": false
},
{
"type": "dir",
"name": "center",
"label": "Center",
"collapsible": true,
"collapsed": false
}
]
7 changes: 7 additions & 0 deletions doc/docs/components/center/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "file",
"name": "center",
"label": "Center"
}
]
24 changes: 24 additions & 0 deletions doc/docs/components/center/center.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Center

## 基本用法

```tsx
import React from 'react';
import { Center } from '@qwqui/core';

export default function Example() {
return (
<Center>
<span>Your content here</span>
</Center>
)
};
```


## Props

| 名称 | 类型 | 介绍 |
|---|---|---|
| children | `React.ReactNode` | 要居中的内容。 |
| inline | `boolen` | 如果为`true`,那么`display`属性则为`inline-flex`,否则`display`属性则为`false` |
19 changes: 12 additions & 7 deletions packages/components/center/__test__/center.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@ describe('Center', () => {

it('should render children correctly', () => {
const { getByText } = render(
<Center>Centered Content</Center>
<Center>Centered Content</Center>,
);
expect(getByText('Centered Content')).toBeInTheDocument();
expect(getByText('Centered Content')).toBeDefined();
});

it('should apply inline-flex when inline is true', () => {
const { container } = render(
<Center inline>Inline Centered Content</Center>
const { baseElement } = render(
<Center inline><div>Inline Centered Content</div></Center>,
);
expect(container.firstChild).toHaveStyle('display: inline-flex');
const comp = baseElement.firstElementChild;
expect(comp).toBeDefined();
expect(comp.getAttribute('data-inline')).toBeDefined()
expect(comp.getAttribute('data-inline')).not.toBe('')
});

it('should apply flex when inline is false', () => {
const { container } = render(
const { baseElement } = render(
<Center>Block Centered Content</Center>
);
expect(container.firstChild).toHaveStyle('display: flex');
const comp = baseElement.firstElementChild;
expect(comp).toBeDefined();
expect(comp.getAttribute('data-inline')).toBeNull()
});
});
2 changes: 1 addition & 1 deletion packages/components/center/src/center.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.root {
display: flex;
display: flex;
align-items: center;
justify-content: center;

Expand Down
8 changes: 2 additions & 6 deletions packages/components/center/src/center.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ import classes from './center.module.scss';

export const Center = (props: CenterProps) => {
const { children, inline } = props;

const getDisplayType = () => {
return inline ? 'inline-flex' : 'flex';
};

return (
<div
className={classes.root}
data-inline={inline}>
data-inline={inline}
>
{children}
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion packages/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import './drop-zone/src/style.scss'
import './ripple/src/ripple.module.scss'
import './center/src/center.module.scss'
export * from './button/index.ts'
export * from './drop-zone/index.ts'
export * from './ripple/index.ts'
export * from './ripple/index.ts'
export * from './center/index.ts'

0 comments on commit 535d4a7

Please sign in to comment.