tangjinzhou
7 years ago
11 changed files with 234 additions and 28 deletions
@ -0,0 +1,82 @@
|
||||
import { mount } from '@vue/test-utils' |
||||
import Vue from 'vue' |
||||
import Anchor from '..' |
||||
|
||||
const { Link } = Anchor |
||||
|
||||
describe('Anchor Render', () => { |
||||
it('Anchor render perfectly', (done) => { |
||||
const wrapper = mount({ |
||||
render () { |
||||
return ( |
||||
<Anchor ref='anchor'> |
||||
<Link href='#API' title='API' /> |
||||
</Anchor> |
||||
) |
||||
}, |
||||
}, { sync: false }) |
||||
Vue.nextTick(() => { |
||||
wrapper.find('a[href="#API"]').trigger('click') |
||||
wrapper.vm.$refs.anchor.handleScroll() |
||||
expect(wrapper.vm.$refs.anchor.$data.activeLink).not.toBe(null) |
||||
done() |
||||
}) |
||||
}) |
||||
|
||||
it('Anchor render perfectly for complete href - click', (done) => { |
||||
const wrapper = mount({ |
||||
render () { |
||||
return ( |
||||
<Anchor ref='anchor'> |
||||
<Link href='http://www.example.com/#API' title='API' /> |
||||
</Anchor> |
||||
) |
||||
}, |
||||
}, { sync: false }) |
||||
Vue.nextTick(() => { |
||||
wrapper.find('a[href="http://www.example.com/#API"]').trigger('click') |
||||
expect(wrapper.vm.$refs.anchor.$data.activeLink).toBe('http://www.example.com/#API') |
||||
done() |
||||
}) |
||||
}) |
||||
|
||||
it('Anchor render perfectly for complete href - scoll', (done) => { |
||||
const wrapper = mount({ |
||||
render () { |
||||
return ( |
||||
<div> |
||||
<div id='API'>Hello</div> |
||||
<Anchor ref='anchor'> |
||||
<Link href='http://www.example.com/#API' title='API' /> |
||||
</Anchor> |
||||
</div> |
||||
) |
||||
}, |
||||
}, { sync: false, attachToDocument: true }) |
||||
Vue.nextTick(() => { |
||||
wrapper.vm.$refs.anchor.handleScroll() |
||||
expect(wrapper.vm.$refs.anchor.$data.activeLink).toBe('http://www.example.com/#API') |
||||
done() |
||||
}) |
||||
}) |
||||
|
||||
it('Anchor render perfectly for complete href - scollTo', (done) => { |
||||
const wrapper = mount({ |
||||
render () { |
||||
return ( |
||||
<div> |
||||
<div id='API'>Hello</div> |
||||
<Anchor ref='anchor'> |
||||
<Link href='##API' title='API' /> |
||||
</Anchor> |
||||
</div> |
||||
) |
||||
}, |
||||
}, { sync: false, attachToDocument: true }) |
||||
Vue.nextTick(() => { |
||||
wrapper.vm.$refs.anchor.handleScrollTo('##API') |
||||
expect(wrapper.vm.$refs.anchor.$data.activeLink).toBe('##API') |
||||
done() |
||||
}) |
||||
}) |
||||
}) |
@ -0,0 +1,51 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP |
||||
|
||||
exports[`renders ./components/anchor/demo/basic.md correctly 1`] = ` |
||||
<div> |
||||
<div class=""> |
||||
<div class="ant-anchor-wrapper" style="max-height: 100vh;"> |
||||
<div class="ant-anchor"> |
||||
<div class="ant-anchor-ink"><span class="ant-anchor-ink-ball"></span></div> |
||||
<div class="ant-anchor-link"> |
||||
<a href="#components-anchor-demo-basic" title="Basic demo" class="ant-anchor-link-title">Basic demo</a> |
||||
</div> |
||||
<div class="ant-anchor-link"> |
||||
<a href="#components-anchor-demo-static-anchor" title="Fixed demo" class="ant-anchor-link-title">Fixed demo</a> |
||||
</div> |
||||
<div class="ant-anchor-link"> |
||||
<a href="#API" title="API" class="ant-anchor-link-title">API</a> |
||||
<div class="ant-anchor-link"> |
||||
<a href="#Anchor-Props" title="Anchor Props" class="ant-anchor-link-title">Anchor Props</a> |
||||
</div> |
||||
<div class="ant-anchor-link"> |
||||
<a href="#Link-Props" title="Link Props" class="ant-anchor-link-title">Link Props</a> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
`; |
||||
|
||||
exports[`renders ./components/anchor/demo/static.md correctly 1`] = ` |
||||
<div class="ant-anchor-wrapper" style="max-height: 100vh;"> |
||||
<div class="ant-anchor fixed"> |
||||
<div class="ant-anchor-ink"><span class="ant-anchor-ink-ball"></span></div> |
||||
<div class="ant-anchor-link"> |
||||
<a href="#components-anchor-demo-basic" title="Basic demo" class="ant-anchor-link-title">Basic demo</a> |
||||
</div> |
||||
<div class="ant-anchor-link"> |
||||
<a href="#components-anchor-demo-static-anchor" title="Fixed demo" class="ant-anchor-link-title">Fixed demo</a> |
||||
</div> |
||||
<div class="ant-anchor-link"> |
||||
<a href="#API" title="API" class="ant-anchor-link-title">API</a> |
||||
<div class="ant-anchor-link"> |
||||
<a href="#Anchor-Props" title="Anchor Props" class="ant-anchor-link-title">Anchor Props</a> |
||||
</div> |
||||
<div class="ant-anchor-link"> |
||||
<a href="#Link-Props" title="Link Props" class="ant-anchor-link-title">Link Props</a> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
`; |
@ -0,0 +1,22 @@
|
||||
<cn> |
||||
#### 基本 |
||||
最简单的用法。 |
||||
</cn> |
||||
|
||||
<us> |
||||
#### basic |
||||
The simplest usage. |
||||
</us> |
||||
|
||||
```html |
||||
<template> |
||||
<a-anchor> |
||||
<a-anchor-link href="#components-anchor-demo-basic" title="Basic demo" /> |
||||
<a-anchor-link href="#components-anchor-demo-static-anchor" title="Fixed demo" /> |
||||
<a-anchor-link href="#API" title="API"> |
||||
<a-anchor-link href="#Anchor-Props" title="Anchor Props" /> |
||||
<a-anchor-link href="#Link-Props" title="Link Props" /> |
||||
</a-anchor-link> |
||||
</a-anchor> |
||||
</template> |
||||
``` |
@ -0,0 +1,50 @@
|
||||
<script> |
||||
import Basic from './basic' |
||||
import Static from './static' |
||||
|
||||
import CN from '../index.zh-CN.md' |
||||
import US from '../index.en-US.md' |
||||
const md = { |
||||
cn: `# Anchor 锚点 |
||||
用于跳转到页面指定位置。 |
||||
|
||||
## 何时使用 |
||||
|
||||
需要展现当前页面上可供跳转的锚点链接,以及快速在锚点之间跳转。 |
||||
## 代码演示`, |
||||
us: `# Anchor |
||||
|
||||
Hyperlinks to scroll on one page. |
||||
|
||||
## When To Use |
||||
|
||||
For displaying anchor hyperlinks on page and jumping between them. |
||||
## Examples |
||||
`, |
||||
} |
||||
export default { |
||||
category: 'Components', |
||||
subtitle: '锚点', |
||||
cols: 2, |
||||
type: 'Other', |
||||
title: 'Anchor', |
||||
render () { |
||||
return ( |
||||
<div id='components-anchor-demo'> |
||||
<md cn={md.cn} us={md.us}/> |
||||
<Basic/> |
||||
<Static/> |
||||
<api> |
||||
<CN slot='cn' /> |
||||
<US/> |
||||
</api> |
||||
</div> |
||||
) |
||||
}, |
||||
} |
||||
</script> |
||||
<style> |
||||
#components-anchor-demo .ant-affix { |
||||
z-index: 11; |
||||
} |
||||
</style> |
@ -0,0 +1,22 @@
|
||||
<cn> |
||||
#### 静态位置 |
||||
不浮动,状态不随页面滚动变化。 |
||||
</cn> |
||||
|
||||
<us> |
||||
#### Static Anchor |
||||
Do not change state when page is scrolling. |
||||
</us> |
||||
|
||||
```html |
||||
<template> |
||||
<a-anchor :affix="false"> |
||||
<a-anchor-link href="#components-anchor-demo-basic" title="Basic demo" /> |
||||
<a-anchor-link href="#components-anchor-demo-static-anchor" title="Fixed demo" /> |
||||
<a-anchor-link href="#API" title="API"> |
||||
<a-anchor-link href="#Anchor-Props" title="Anchor Props" /> |
||||
<a-anchor-link href="#Link-Props" title="Link Props" /> |
||||
</a-anchor-link> |
||||
</a-anchor> |
||||
</template> |
||||
``` |
Loading…
Reference in new issue