|
| 1 | +import { nextTick, ref } from 'vue' |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | +import { mount } from '@vue/test-utils' |
| 4 | +import { UedRow, UedCol } from '@ued-plus/components' |
| 5 | + |
| 6 | +describe('Row.vue', () => { |
| 7 | + it('create', () => { |
| 8 | + const wrapper = mount(UedRow) |
| 9 | + expect(wrapper.classes()).toContain('ued-row') |
| 10 | + }) |
| 11 | + |
| 12 | + it('gutter', () => { |
| 13 | + const wrapper = mount(UedRow, { |
| 14 | + props: { |
| 15 | + gutter: 20, |
| 16 | + }, |
| 17 | + }) |
| 18 | + const rowElm = wrapper.element as HTMLElement |
| 19 | + expect(rowElm.style.marginLeft).toEqual('-10px') |
| 20 | + expect(rowElm.style.marginRight).toEqual('-10px') |
| 21 | + }) |
| 22 | + |
| 23 | + it('justify', () => { |
| 24 | + const wrapper = mount(UedRow, { |
| 25 | + props: { |
| 26 | + justify: 'end', |
| 27 | + }, |
| 28 | + }) |
| 29 | + expect(wrapper.classes()).toContain('is-justify-end') |
| 30 | + }) |
| 31 | + |
| 32 | + it('align', () => { |
| 33 | + const wrapper = mount(UedRow, { |
| 34 | + props: { |
| 35 | + align: 'bottom', |
| 36 | + }, |
| 37 | + }) |
| 38 | + expect(wrapper.classes()).toContain('is-align-bottom') |
| 39 | + }) |
| 40 | +}) |
| 41 | + |
| 42 | +describe('Col.vue', () => { |
| 43 | + it('create', () => { |
| 44 | + const wrapper = mount(UedCol) |
| 45 | + expect(wrapper.classes()).toContain('ued-col') |
| 46 | + }) |
| 47 | + |
| 48 | + it('span', () => { |
| 49 | + const wrapper = mount(UedCol, { |
| 50 | + props: { |
| 51 | + span: 12, |
| 52 | + }, |
| 53 | + }) |
| 54 | + expect(wrapper.classes()).toContain('ued-col-12') |
| 55 | + }) |
| 56 | + |
| 57 | + it('pull', () => { |
| 58 | + const wrapper = mount(UedCol, { |
| 59 | + props: { |
| 60 | + pull: 3, |
| 61 | + }, |
| 62 | + }) |
| 63 | + expect(wrapper.classes()).toContain('ued-col-pull-3') |
| 64 | + }) |
| 65 | + |
| 66 | + it('push', () => { |
| 67 | + const wrapper = mount(UedCol, { |
| 68 | + props: { |
| 69 | + push: 3, |
| 70 | + }, |
| 71 | + }) |
| 72 | + expect(wrapper.classes()).toContain('ued-col-push-3') |
| 73 | + }) |
| 74 | + |
| 75 | + it('gutter', () => { |
| 76 | + const wrapper = mount({ |
| 77 | + setup: () => () => ( |
| 78 | + <UedRow gutter={20}> |
| 79 | + <UedCol span={12} ref="col"></UedCol> |
| 80 | + </UedRow> |
| 81 | + ), |
| 82 | + }) |
| 83 | + |
| 84 | + const colElm = wrapper.findComponent({ ref: 'col' }).element as HTMLElement |
| 85 | + expect(colElm.style.paddingLeft === '10px').toBe(true) |
| 86 | + expect(colElm.style.paddingRight === '10px').toBe(true) |
| 87 | + }) |
| 88 | + |
| 89 | + it('change gutter value', async () => { |
| 90 | + const outer = ref(20) |
| 91 | + |
| 92 | + const wrapper = mount({ |
| 93 | + setup: () => () => ( |
| 94 | + <UedRow gutter={outer.value} ref="row"> |
| 95 | + <UedCol span={12} ref="col" /> |
| 96 | + </UedRow> |
| 97 | + ), |
| 98 | + }) |
| 99 | + |
| 100 | + const rowElm = wrapper.findComponent({ ref: 'row' }).element as HTMLElement |
| 101 | + const colElm = wrapper.findComponent({ ref: 'col' }).element as HTMLElement |
| 102 | + |
| 103 | + expect(rowElm.style.marginLeft === '-10px').toBe(true) |
| 104 | + expect(rowElm.style.marginRight === '-10px').toBe(true) |
| 105 | + expect(colElm.style.paddingLeft === '10px').toBe(true) |
| 106 | + expect(colElm.style.paddingRight === '10px').toBe(true) |
| 107 | + |
| 108 | + outer.value = 40 |
| 109 | + await nextTick() |
| 110 | + |
| 111 | + expect(rowElm.style.marginLeft === '-20px').toBe(true) |
| 112 | + expect(rowElm.style.marginRight === '-20px').toBe(true) |
| 113 | + expect(colElm.style.paddingLeft === '20px').toBe(true) |
| 114 | + expect(colElm.style.paddingRight === '20px').toBe(true) |
| 115 | + }) |
| 116 | + |
| 117 | + it('responsive', () => { |
| 118 | + const wrapper = mount({ |
| 119 | + setup: () => () => ( |
| 120 | + <UedRow gutter={20}> |
| 121 | + <UedCol |
| 122 | + ref="col" |
| 123 | + sm={{ span: 4, offset: 2 }} |
| 124 | + md={8} |
| 125 | + lg={{ span: 6, offset: 3 }} |
| 126 | + /> |
| 127 | + </UedRow> |
| 128 | + ), |
| 129 | + }) |
| 130 | + |
| 131 | + const colElmClass = wrapper.findComponent({ ref: 'col' }).classes() |
| 132 | + |
| 133 | + expect(colElmClass.includes('ued-col-sm-4')).toBe(true) |
| 134 | + expect(colElmClass.includes('ued-col-sm-4')).toBe(true) |
| 135 | + expect(colElmClass.includes('ued-col-offset-sm-2')).toBe(true) |
| 136 | + expect(colElmClass.includes('ued-col-lg-6')).toBe(true) |
| 137 | + expect(colElmClass.includes('ued-col-offset-lg-3')).toBe(true) |
| 138 | + expect(colElmClass.includes('ued-col-md-8')).toBe(true) |
| 139 | + }) |
| 140 | +}) |
0 commit comments