|
| 1 | +/* |
| 2 | +表格通用单元测试 |
| 3 | +*/ |
| 4 | + |
| 5 | +import { mount } from "@vue/test-utils"; |
| 6 | +import veTable from "@/ve-table"; |
| 7 | +import { |
| 8 | + later, |
| 9 | + mockElementMeasurement, |
| 10 | + clearMockElementMeasurement, |
| 11 | +} from "../util"; |
| 12 | + |
| 13 | +describe("veTable common", () => { |
| 14 | + afterEach(() => { |
| 15 | + clearMockElementMeasurement("scrollWidth"); |
| 16 | + clearMockElementMeasurement("clientWidth"); |
| 17 | + }); |
| 18 | + |
| 19 | + it("horizontal scroll effect", async () => { |
| 20 | + mockElementMeasurement("scrollWidth", 1200); |
| 21 | + mockElementMeasurement("clientWidth", 900); |
| 22 | + |
| 23 | + const COLUMNS = [ |
| 24 | + { field: "col1", key: "a", title: "Title1" }, |
| 25 | + { field: "col2", key: "b", title: "Title2" }, |
| 26 | + { field: "col3", key: "c", title: "Title3" }, |
| 27 | + { field: "col4", key: "d", title: "Title4" }, |
| 28 | + { field: "col5", key: "e", title: "Title5" }, |
| 29 | + { field: "col6", key: "f", title: "Title6" }, |
| 30 | + { field: "col7", key: "g", title: "Title7" }, |
| 31 | + { field: "col8", key: "h", title: "Title8" }, |
| 32 | + { field: "col9", key: "i", title: "Title9" }, |
| 33 | + { field: "col10", key: "j", title: "Title10" }, |
| 34 | + ]; |
| 35 | + |
| 36 | + const COLUMNS2 = [ |
| 37 | + { field: "col1", key: "a", title: "Title1", fixed: "left" }, |
| 38 | + { field: "col2", key: "b", title: "Title2", fixed: "left" }, |
| 39 | + { field: "col3", key: "c", title: "Title3" }, |
| 40 | + { field: "col4", key: "d", title: "Title4" }, |
| 41 | + { field: "col5", key: "e", title: "Title5" }, |
| 42 | + { field: "col6", key: "f", title: "Title6" }, |
| 43 | + { field: "col7", key: "g", title: "Title7" }, |
| 44 | + { field: "col8", key: "h", title: "Title8" }, |
| 45 | + { field: "col9", key: "i", title: "Title9" }, |
| 46 | + { field: "col10", key: "j", title: "Title10", fixed: "right" }, |
| 47 | + ]; |
| 48 | + |
| 49 | + const TABLE_DATA = [ |
| 50 | + { |
| 51 | + col1: "1", |
| 52 | + col2: "2", |
| 53 | + col3: "3", |
| 54 | + col4: "4", |
| 55 | + col5: "5", |
| 56 | + col6: "6", |
| 57 | + col7: "7", |
| 58 | + col8: "8", |
| 59 | + col9: "9", |
| 60 | + col10: "10", |
| 61 | + }, |
| 62 | + ]; |
| 63 | + |
| 64 | + const ParentComp = { |
| 65 | + template: ` |
| 66 | + <veTable |
| 67 | + style="width:900px" |
| 68 | + :scrollWidth="1200" |
| 69 | + :columns="columns" |
| 70 | + :tableData="tableData" |
| 71 | + /> |
| 72 | + `, |
| 73 | + props: { |
| 74 | + columns: { |
| 75 | + type: Array, |
| 76 | + required: true, |
| 77 | + }, |
| 78 | + }, |
| 79 | + data() { |
| 80 | + return { |
| 81 | + tableData: TABLE_DATA, |
| 82 | + }; |
| 83 | + }, |
| 84 | + components: { |
| 85 | + veTable, |
| 86 | + }, |
| 87 | + }; |
| 88 | + |
| 89 | + await later(); |
| 90 | + |
| 91 | + const parentWrapper = mount(ParentComp, { |
| 92 | + propsData: { |
| 93 | + columns: COLUMNS, |
| 94 | + }, |
| 95 | + }); |
| 96 | + |
| 97 | + const wrapper = parentWrapper.findComponent(veTable); |
| 98 | + |
| 99 | + expect(wrapper.vm.isRightScrolling).toBe(false); |
| 100 | + |
| 101 | + // 只能通过父组件设置 |
| 102 | + await parentWrapper.setProps({ columns: COLUMNS2 }); |
| 103 | + expect(wrapper.vm.isRightScrolling).toBe(true); |
| 104 | + }); |
| 105 | +}); |
0 commit comments