Skip to content

Commit

Permalink
test(ruler): add ruler jest test (didi#395)
Browse files Browse the repository at this point in the history
* fix(ActivityIndicator): fix wrong roller-success background-color

* feat(ruler): add new component Ruler

* feat(ruler): update for ruler

* feat(ruler): finish ruler

* code-style(activity-indicator): change color

* feat(ruler): remove mouse event and add throttle

* test(jest): add jest-canvas-mock
  • Loading branch information
supergaojian authored and xxyan0205 committed Apr 9, 2019
1 parent 5687d4f commit 86cd506
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 10 deletions.
7 changes: 5 additions & 2 deletions components/ruler/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,18 @@ export default {
realMin() {
const {scope, min} = this
const [left] = scope
const [left, right] = scope
if (min > right) {
return left
}
return min > left ? min : left
},
realMax() {
let {scope, max} = this
const [left, right] = scope
if (left > max) {
max = right
return right
}
return max > right ? right : max
},
Expand Down
37 changes: 37 additions & 0 deletions components/ruler/test/__snapshots__/demo.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Radio Basic 1`] = `
<div class="md-example-child md-example-child-single-component">
<p>当前值:1000</p>
<div class="container">
<div class="md-ruler"><canvas class="md-ruler-canvas"></canvas>
<div class="md-ruler-cursor"></div>
<div class="md-ruler-arrow"></div>
</div>
</div>
</div>
`;

exports[`Radio List 1`] = `
<div class="md-example-child md-example-child-single-component">
<p>当前值:1300</p>
<div class="container">
<div class="md-ruler"><canvas class="md-ruler-canvas"></canvas>
<div class="md-ruler-cursor"></div>
<div class="md-ruler-arrow"></div>
</div>
</div>
</div>
`;

exports[`Radio With Field 1`] = `
<div class="md-example-child md-example-child-single-component">
<p>当前值:1305</p>
<div class="container">
<div class="md-ruler"><canvas class="md-ruler-canvas"></canvas>
<div class="md-ruler-cursor"></div>
<div class="md-ruler-arrow"></div>
</div>
</div>
</div>
`;
36 changes: 36 additions & 0 deletions components/ruler/test/cases/demo0.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<div class="md-example-child md-example-child-single-component">
<p>当前值:{{ value }}</p>
<div class="container">
<md-ruler
:scope="scope"
:step="100"
:unit="10"
v-model="value"
></md-ruler>
</div>
</div>
</template>

<script>import {Ruler} from 'mand-mobile'
export default {
name: 'ruler-demo',
components: {
[Ruler.name]: Ruler,
},
data() {
return {
value: 1000,
scope: [1000, 2000],
}
},
}
</script>

<style lang="stylus" scoped>
.md-example-child-single-component
.container
margin 0 auto
width 640px
</style>
Expand Down
38 changes: 38 additions & 0 deletions components/ruler/test/cases/demo1.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<div class="md-example-child md-example-child-single-component">
<p>当前值:{{ value }}</p>
<div class="container">
<md-ruler
:scope="scope"
:step="100"
:unit="10"
:max="1800"
:min="1200"
v-model="value"
></md-ruler>
</div>
</div>
</template>

<script>import {Ruler} from 'mand-mobile'
export default {
name: 'ruler-demo',
components: {
[Ruler.name]: Ruler,
},
data() {
return {
value: 1305,
scope: [1000, 2000],
}
},
}
</script>

<style lang="stylus" scoped>
.md-example-child-single-component
.container
margin 0 auto
width 640px
</style>
Expand Down
43 changes: 43 additions & 0 deletions components/ruler/test/cases/demo2.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<div class="md-example-child md-example-child-single-component">
<p>当前值:{{ value }}</p>
<div class="container">
<md-ruler
:scope="scope"
:step="100"
:unit="10"
:max="2000"
:min="1000"
v-model="value"
></md-ruler>
</div>
</div>
</template>

<script>import {Ruler} from 'mand-mobile'
export default {
name: 'ruler-demo',
components: {
[Ruler.name]: Ruler,
},
data() {
return {
value: 1300,
scope: [1000, 2000],
}
},
mounted() {
window.triggerRuler2 = () => {
this.value = 1500
}
},
}
</script>

<style lang="stylus" scoped>
.md-example-child-single-component
.container
margin 0 auto
width 640px
</style>
Expand Down
16 changes: 16 additions & 0 deletions components/ruler/test/demo.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Demo0 from './cases/demo0'
import Demo1 from './cases/demo1'
import Demo2 from './cases/demo2'
import {renderToString} from '@vue/server-test-utils'

describe('Radio', () => {
test(`Basic`, () => {
expect(renderToString(Demo0)).toMatchSnapshot()
})
test(`With Field`, () => {
expect(renderToString(Demo1)).toMatchSnapshot()
})
test(`List`, () => {
expect(renderToString(Demo2)).toMatchSnapshot()
})
})
Loading

0 comments on commit 86cd506

Please sign in to comment.