ソースを参照

add button spec

杨磊 7 年 前
コミット
ec4e2285ea

+ 105 - 0
src/packages/button/__test__/button.spec.js

@@ -0,0 +1,105 @@
+import { shallowMount, mount } from '@vue/test-utils'
+import Button from '../button.vue';
+import Vue from 'vue';
+
+describe('Button.vue', () => {
+    it('设置type', () => {
+        let wrapper = shallowMount(Button, {
+            slots: {
+                default: '去结算'
+            },
+            propsData:{
+                type: 'light'
+            }
+        });
+        return Vue.nextTick().then(function () {
+            expect(wrapper.attributes('class')).toContain('light');
+        })
+    });
+    it('设置slot', () => {
+        let wrapper = shallowMount(Button, {
+            slots: {
+                default: '去结算'
+            }
+        });
+        return Vue.nextTick().then(function () {
+            expect(wrapper.text()).toBe('去结算');
+        })
+    });
+    it('设置disabled', () => {
+        let wrapper = shallowMount(Button, {
+            slots: {
+                default: '去结算'
+            },
+            propsData:{
+                disabled: true
+            }
+        });
+        return Vue.nextTick().then(function () {
+            expect(wrapper.text()).toBe('去结算');
+            expect(wrapper.attributes('disabled')).toContain('disabled');
+        })
+    });
+    it('设置shape', () => {
+        let wrapper = shallowMount(Button, {
+            slots: {
+                default: '去结算'
+            },
+            propsData:{
+                shape: 'circle'
+            }
+        });
+        return Vue.nextTick().then(function () {
+            expect(wrapper.text()).toBe('去结算');
+            expect(wrapper.attributes('class')).toContain('circle');
+        })
+    });
+    it('设置small', () => {
+        let wrapper = shallowMount(Button, {
+            slots: {
+                default: '去结算'
+            },
+            propsData:{
+                small: true
+            }
+        });
+        return Vue.nextTick().then(function () {
+            expect(wrapper.text()).toBe('去结算');
+            expect(wrapper.attributes('class')).toContain('small');
+        })
+    });
+    it('设置icon', () => {
+        let wrapper = shallowMount(Button, {
+            slots: {
+                default: '全部100万'
+            },
+            propsData:{
+                type: 'actived',
+                icon: 'tick'
+            }
+        });
+        return Vue.nextTick().then(function () {
+            expect(wrapper.text()).toBe('全部100万');
+            expect(wrapper.contains('.txt-icon')).toBe(true);
+            expect(wrapper.find('.txt-icon').attributes('type')).toBe('tick');            
+            expect(wrapper.find('span').text()).toBe('全部100万');
+        })
+    });
+    it('设置color', () => {
+        let wrapper = shallowMount(Button, {
+            slots: {
+                default: '去结算'
+            },
+            propsData:{
+                icon: 'tick',
+                color: '#fff'
+            }
+        });
+        return Vue.nextTick().then(function () {
+            expect(wrapper.text()).toBe('去结算');
+            expect(wrapper.find('span').attributes('style')).toBe('color: rgb(255, 255, 255);');
+            expect(wrapper.find('.txt-icon').attributes('color')).toBe('#fff');
+        })
+    });
+
+});

+ 6 - 6
src/packages/buttongroup/demo.vue

@@ -1,23 +1,23 @@
 <template>
 <template>
     <div>
     <div>
       <h4>常规按钮组</h4>
       <h4>常规按钮组</h4>
-      <nut-button-group>
+      <nut-buttongroup>
         <nut-button type="light">重置</nut-button>
         <nut-button type="light">重置</nut-button>
         <nut-button>确定</nut-button>
         <nut-button>确定</nut-button>
-      </nut-button-group>
+      </nut-buttongroup>
     <h4>圆角按钮组</h4>
     <h4>圆角按钮组</h4>
-    <nut-button-group shape="circle">
+    <nut-buttongroup shape="circle">
       <nut-button type="light">重置</nut-button>
       <nut-button type="light">重置</nut-button>
       <nut-button>确定</nut-button>
       <nut-button>确定</nut-button>
-    </nut-button-group>
+    </nut-buttongroup>
     <h4>页面底部功能,配合Badge使用</h4>
     <h4>页面底部功能,配合Badge使用</h4>
-      <nut-button-group type="menu">
+      <nut-buttongroup type="menu">
         <nut-button type="light" icon="action" color="#000">关于</nut-button>
         <nut-button type="light" icon="action" color="#000">关于</nut-button>
         <nut-button type="light" icon="more" color="#000">更多</nut-button>
         <nut-button type="light" icon="more" color="#000">更多</nut-button>
         <nut-button type="light" icon="search" color="#000">关闭</nut-button>
         <nut-button type="light" icon="search" color="#000">关闭</nut-button>
         <nut-badge value="2" top="0.5rem" right="2rem"><nut-button type="light" icon="trolley" color="#f00">购物车</nut-button></nut-badge>      
         <nut-badge value="2" top="0.5rem" right="2rem"><nut-button type="light" icon="trolley" color="#f00">购物车</nut-button></nut-badge>      
         <nut-button type="light" icon="tick" color="#000">成功</nut-button>
         <nut-button type="light" icon="tick" color="#000">成功</nut-button>
-      </nut-button-group>
+      </nut-buttongroup>
     </div>
     </div>
 </template>
 </template>