Browse Source

fix: 优化drag组件demo实例,增加单元测试

jerry 5 years ago
parent
commit
348f707ebd
2 changed files with 52 additions and 1 deletions
  1. 51 0
      src/packages/drag/__test__/drag.spec.js
  2. 1 1
      src/packages/drag/demo.vue

+ 51 - 0
src/packages/drag/__test__/drag.spec.js

@@ -0,0 +1,51 @@
+import { shallowMount } from "@vue/test-utils";
+import Drag from "../Drag.vue";
+import Vue from "vue";
+
+describe("Drag.vue", () => {
+  const wrapper = shallowMount(Drag, {});
+  it("设置x轴拖拽方向", () => {
+    wrapper.setProps({
+      direction: "x",
+    });
+
+    return Vue.nextTick().then(function() {
+      expect(wrapper.find(".nut-drag").isVisible()).toBe(true);
+    });
+  });
+
+  it("设置y轴拖拽方向", () => {
+    wrapper.setProps({
+      direction: "y",
+    });
+
+    return Vue.nextTick().then(function() {
+      expect(wrapper.find(".nut-drag").isVisible()).toBe(true);
+    });
+  });
+
+  it("设置自动吸边", () => {
+    wrapper.setProps({
+      attract: true,
+    });
+
+    return Vue.nextTick().then(function() {
+      expect(wrapper.find(".nut-drag").isVisible()).toBe(true);
+    });
+  });
+
+  it("设置拖拽边界", () => {
+    wrapper.setProps({
+      boundary: {
+        top: 401,
+        left: 9,
+        bottom: document.documentElement.clientHeight - 601,
+        right: document.documentElement.clientWidth - 300 - 9,
+      },
+    });
+
+    return Vue.nextTick().then(function() {
+      expect(wrapper.find(".nut-drag").isVisible()).toBe(true);
+    });
+  });
+});

+ 1 - 1
src/packages/drag/demo.vue

@@ -59,7 +59,7 @@ export default {
 }
 .touch-dom {
   height: 30px;
-  padding: 10px;
+  padding: 0 10px;
   line-height: 30px;
   text-align: center;
   color: #fff;