Skip to content

Commit

Permalink
fix(ui/input select): 修复了input select的label居中问题 完成layout skeleton的单元测试
Browse files Browse the repository at this point in the history
affects: @varlet/cli, @varlet/ui
  • Loading branch information
haoziqaq committed Apr 29, 2021
1 parent 9a97c2b commit b9502f9
Show file tree
Hide file tree
Showing 14 changed files with 433 additions and 22 deletions.
15 changes: 11 additions & 4 deletions packages/varlet-cli/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,18 @@ export default ${bigCamelize(name)}

const testsTemplate = `\
import example from '../example'
import { render } from '@testing-library/vue'
import ${bigCamelize(name)} from '..'
import { mount } from '@vue/test-utils'
import { createApp } from 'vue'
test('test ${camelize(name)} example', () => {
const wrapper = mount(example)
expect(wrapper.html()).toMatchSnapshot()
})
test('test ${camelize(name)} example', async () => {
const wrapper = render(example)
console.log(wrapper)
test('test ${camelize(name)} plugin', () => {
const app = createApp({}).use(${bigCamelize(name)})
expect(app.component(${bigCamelize(name)}.name)).toBeTruthy()
})
`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ exports[`test button example 1`] = `
</button>"
`;
exports[`test button size & text & block & round 1`] = `
exports[`test button styles 1`] = `
"<button class=\\"var-button var--box var-button--large var--flex var-button--text-default var-button--text var-button--round\\" style=\\"width: 100%;\\">
<!--v-if-->
<div class=\\"var-button__content\\"></div>
<div class=\\"var-button__content\\">button text</div>
</button>"
`;
7 changes: 5 additions & 2 deletions packages/varlet-ui/src/button/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('test button plugin', () => {
expect(app.component(Button.name)).toBeTruthy()
})

test('test button click & touchstart', () => {
test('test button onClick & onTouchstart null callback', () => {
const wrapper = mount(VarButton)
wrapper.trigger('click')
wrapper.trigger('touchstart')
Expand Down Expand Up @@ -82,14 +82,17 @@ test('test button color & textColor', () => {
expect(wrapper.html()).toMatchSnapshot()
})

test('test button size & text & block & round', () => {
test('test button styles', () => {
const wrapper = mount(VarButton, {
props: {
size: 'large',
round: true,
text: true,
block: true,
},
slots: {
default: () => 'button text',
},
})

expect(wrapper.html()).toMatchSnapshot()
Expand Down
7 changes: 5 additions & 2 deletions packages/varlet-ui/src/input/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@
@change="handleChange"
/>
<label
class="var-input__placeholder"
:class="[computePlaceholderState(), !hint ? 'var-input--placeholder-non-hint' : null]"
:class="[
textarea ? 'var-input__textarea-placeholder' : 'var-input__placeholder',
computePlaceholderState(),
!hint ? 'var-input--placeholder-non-hint' : null,
]"
:for="id"
>
{{ placeholder }}
Expand Down
1 change: 0 additions & 1 deletion packages/varlet-ui/src/input/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ Other values are converted to text as a user prompt.
| `@input-blur-color` | `#888` |
| `@input-focus-color` | `@color-primary` |
| `@input-placeholder-size` | `6px` |
| `@input-placeholder-offset-top` | `4px` |
| `@input-textarea-height` | `auto` |
| `@input-textarea-padding-top` | `8px` |
| `@input-icon-padding` | `@input-placeholder-size 0 0` |
Expand Down
1 change: 0 additions & 1 deletion packages/varlet-ui/src/input/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ createApp().use(Icon)
| `@input-blur-color` | `#888` |
| `@input-focus-color` | `@color-primary` |
| `@input-placeholder-size` | `6px` |
| `@input-placeholder-offset-top` | `4px` |
| `@input-textarea-height` | `auto` |
| `@input-textarea-padding-top` | `8px` |
| `@input-icon-padding` | `@input-placeholder-size 0 0` |
Expand Down
17 changes: 14 additions & 3 deletions packages/varlet-ui/src/input/input.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@input-blur-color: #888;
@input-focus-color: @color-primary;
@input-placeholder-size: 16px;
@input-placeholder-offset-top: 4px;
@input-textarea-height: auto;
@input-textarea-padding-top: 8px;
@input-icon-padding: @input-placeholder-size 0 0;
Expand Down Expand Up @@ -54,12 +53,23 @@
}

&__placeholder {
position: absolute;
top: 50%;
left: 0;
transform-origin: left;
transition-property: top, transform;
transition-duration: 0.3s;
transform: translate(0, calc(-50% + @input-placeholder-size / 2)) scale(1);
font-size: @input-placeholder-size;
}

&__textarea-placeholder {
position: absolute;
top: 0;
left: 0;
transform-origin: left;
transition: transform 0.3s;
transform: translate(0, @input-placeholder-offset-top + @input-placeholder-size) scale(1);
transform: translate(0, @input-textarea-padding-top + @input-placeholder-size) scale(1);
font-size: @input-placeholder-size;
}

Expand Down Expand Up @@ -106,7 +116,8 @@
}

&--placeholder-non-hint {
transform: translate(0, @input-placeholder-offset-top) scale(1);
top: 50%;
transform: translate(0, -50%) scale(1);
}

&--non-hint {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test col in row 1`] = `
"<div class=\\"var-row var--box\\" style=\\"justify-content: flex-start; align-items: flex-start;\\">
<div class=\\"var-col var--box var-col--span-8 var-col--offset-4\\" style=\\"padding-left: 0px; padding-right: 0px;\\"></div>
<div class=\\"var-col var--box var-col--span-12\\" style=\\"padding-left: 0px; padding-right: 0px;\\"></div>
</div>"
`;
exports[`test col in row 2`] = `
"<div class=\\"var-row var--box\\" style=\\"justify-content: flex-start; align-items: flex-start;\\">
<div class=\\"var-col var--box var-col--span-12\\" style=\\"padding-left: 0px; padding-right: 5px;\\"></div>
<div class=\\"var-col var--box var-col--span-12\\" style=\\"padding-left: 5px; padding-right: 0px;\\"></div>
</div>"
`;
exports[`test row example 1`] = `
"<div class=\\"app-type\\">栅格系统</div>
<div class=\\"var-row var--box\\" style=\\"justify-content: flex-start; align-items: flex-start;\\">
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
</div>
<div class=\\"app-type\\">偏移</div>
<div class=\\"var-row var--box\\" style=\\"justify-content: flex-start; align-items: flex-start;\\">
<div class=\\"var-col var--box var-col--span-16 var-col--offset-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">offset: 8 span: 16</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
</div>
<div class=\\"app-type\\">对齐</div>
<div class=\\"var-row var--box\\" style=\\"justify-content: flex-start; align-items: flex-start;\\">
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
</div>
<div class=\\"var-row var--box\\" style=\\"justify-content: center; align-items: flex-start;\\">
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
</div>
<div class=\\"var-row var--box\\" style=\\"justify-content: flex-end; align-items: flex-start;\\">
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
</div>
<div class=\\"var-row var--box\\" style=\\"justify-content: space-around; align-items: flex-start;\\">
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
</div>
<div class=\\"var-row var--box\\" style=\\"justify-content: space-between; align-items: flex-start;\\">
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
</div>
<div class=\\"app-type\\">列间距</div>
<div class=\\"var-row var--box\\" style=\\"justify-content: flex-start; align-items: flex-start;\\">
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
<div class=\\"var-col var--box var-col--span-8 col\\" style=\\"padding-left: 0px; padding-right: 0px;\\">span: 8</div>
</div>"
`;
exports[`test row flex 1`] = `"<div class=\\"var-row var--box\\" style=\\"justify-content: flex-start; align-items: flex-start;\\"></div>"`;
exports[`test row flex 2`] = `"<div class=\\"var-row var--box\\" style=\\"justify-content: flex-end; align-items: flex-start;\\"></div>"`;
exports[`test row flex 3`] = `"<div class=\\"var-row var--box\\" style=\\"justify-content: center; align-items: flex-start;\\"></div>"`;
exports[`test row flex 4`] = `"<div class=\\"var-row var--box\\" style=\\"justify-content: space-between; align-items: flex-start;\\"></div>"`;
exports[`test row flex 5`] = `"<div class=\\"var-row var--box\\" style=\\"justify-content: space-around; align-items: flex-start;\\"></div>"`;
exports[`test row flex 6`] = `"<div class=\\"var-row var--box\\" style=\\"justify-content: space-around; align-items: flex-start;\\"></div>"`;
exports[`test row flex 7`] = `"<div class=\\"var-row var--box\\" style=\\"justify-content: space-around; align-items: center;\\"></div>"`;
exports[`test row flex 8`] = `"<div class=\\"var-row var--box\\" style=\\"justify-content: space-around; align-items: flex-end;\\"></div>"`;
92 changes: 92 additions & 0 deletions packages/varlet-ui/src/row/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import example from '../example'
import Row from '..'
import VarRow from '../Row'
import Col from '../../col'
import VarCol from '../../col/Col'
import { mount } from '@vue/test-utils'
import { createApp, h } from 'vue'

test('test row example', () => {
const wrapper = mount(example)
expect(wrapper.html()).toMatchSnapshot()
})

test('test row plugin', () => {
const app = createApp({}).use(Row)
expect(app.component(Row.name)).toBeTruthy()
})

test('test col plugin', () => {
const app = createApp({}).use(Col)
expect(app.component(Col.name)).toBeTruthy()
})

test('test row flex', async () => {
const wrapper = mount(VarRow)

await wrapper.setProps({ justify: 'flex-start' })
expect(wrapper.html()).toMatchSnapshot()

await wrapper.setProps({ justify: 'flex-end' })
expect(wrapper.html()).toMatchSnapshot()

await wrapper.setProps({ justify: 'center' })
expect(wrapper.html()).toMatchSnapshot()

await wrapper.setProps({ justify: 'space-between' })
expect(wrapper.html()).toMatchSnapshot()

await wrapper.setProps({ justify: 'space-around' })
expect(wrapper.html()).toMatchSnapshot()

await wrapper.setProps({ align: 'flex-start' })
expect(wrapper.html()).toMatchSnapshot()

await wrapper.setProps({ align: 'center' })
expect(wrapper.html()).toMatchSnapshot()

await wrapper.setProps({ align: 'flex-end' })
expect(wrapper.html()).toMatchSnapshot()
})

test('test row onClick null callback', () => {
const wrapper = mount(VarRow)
wrapper.trigger('click')
})

test('test row onClick', () => {
const onClick = jest.fn()

const wrapper = mount(VarRow, {
props: {
onClick,
},
})
wrapper.trigger('click')
expect(onClick).toHaveBeenCalledTimes(1)
})

test('test col in row', async () => {
const wrapper = mount({
data: () => ({
span: 8,
offset: 4,
}),
render() {
return h(
VarRow,
{
gutter: '10px',
},
() => [h(VarCol, { span: this.span, offset: this.offset }), h(VarCol, { span: 12 })]
)
},
})
expect(wrapper.html()).toMatchSnapshot()

await wrapper.setData({
span: 12,
offset: 0,
})
expect(wrapper.html()).toMatchSnapshot()
})
1 change: 0 additions & 1 deletion packages/varlet-ui/src/select/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ export default {
| `@select-scroller-padding` | `6px 0` |
| `@select-scroller-max-height` | `278px` |
| `@select-placeholder-size` | `16px` |
| `@select-placeholder-offset-top` | `4px` |
| `@select-icon-padding` | `@select-placeholder-size 0 0` |
| `@select-icon-size` | `20px` |
| `@select-select-text-color` | `#555` |
Expand Down
1 change: 0 additions & 1 deletion packages/varlet-ui/src/select/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ export default {
| `@select-scroller-padding` | `6px 0` |
| `@select-scroller-max-height` | `278px` |
| `@select-placeholder-size` | `16px` |
| `@select-placeholder-offset-top` | `4px` |
| `@select-icon-padding` | `@select-placeholder-size 0 0` |
| `@select-icon-size` | `20px` |
| `@select-select-text-color` | `#555` |
Expand Down
11 changes: 6 additions & 5 deletions packages/varlet-ui/src/select/select.less
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
@select-scroller-padding: 6px 0;
@select-scroller-max-height: 278px;
@select-placeholder-size: 16px;
@select-placeholder-offset-top: 4px;
@select-icon-padding: @select-placeholder-size 0 0;
@select-icon-size: 20px;
@select-select-text-color: #555;
Expand Down Expand Up @@ -74,11 +73,12 @@

&__placeholder {
position: absolute;
top: 0;
top: 50%;
left: 0;
transform-origin: left;
transition: transform 0.3s;
transform: translate(0, @select-placeholder-offset-top + @select-placeholder-size) scale(1);
transition-property: top, transform;
transition-duration: 0.3s;
transform: translate(0, calc(-50% + @select-placeholder-size / 2)) scale(1);
font-size: @select-placeholder-size;
}

Expand Down Expand Up @@ -122,7 +122,8 @@
}

&--placeholder-non-hint {
transform: translate(0, @select-placeholder-offset-top) scale(1);
top: 50%;
transform: translate(0, -50%) scale(1);
}

&--non-hint {
Expand Down
Loading

0 comments on commit b9502f9

Please sign in to comment.