import { defineComponent } from 'vue' import { mount } from '@vue/test-utils' import TimeLine from '../src/index.vue' import TimeLineItem from '../src/item.vue' const Component = defineComponent({ components: { 'el-timeline': TimeLine, 'el-timeline-item': TimeLineItem, }, props: [], data() { return { activities: [{ content: 'Step 1: xxxxxx', timestamp: '2018-04-11', }, { content: 'Step 2: xxxxxx', timestamp: '2018-04-13', }, { content: 'Step 3: xxxxxx', timestamp: '2018-04-15', }], } }, template: ` {{activity.content}} `, }) describe('TimeLine.vue', () => { test('create', () => { const wrapper = mount(Component) const vm = wrapper.vm const contentWrappers = wrapper.findAll('.el-timeline-item__content') contentWrappers.forEach((content, index) => { expect(content.text()).toEqual(vm.activities[index].content) }) const timestampWrappers = wrapper.findAll('.el-timeline-item__timestamp') timestampWrappers.forEach((timestamp, index) => { expect(timestamp.text()).toEqual(vm.activities[index].timestamp) }) }) test('placement', () => { const wrapper = mount({ ...Component, template: ` {{activity.content}} `, data() { return { activities: [{ content: 'Step 1: xxxxxx', timestamp: '2018-04-11', placement: 'top', }, { content: 'Step 2: xxxxxx', timestamp: '2018-04-13', }, { content: 'Step 3: xxxxxx', timestamp: '2018-04-15', }], } }, }) const timestampWrapper = wrapper.findAll('.el-timeline-item__timestamp')[0] expect(timestampWrapper.classes('is-top')).toBe(true) }) test('hide-timestamp', () => { const wrapper = mount({ ...Component, template: ` {{activity.content}} `, data() { return { activities: [{ content: 'Step 1: xxxxxx', timestamp: '2018-04-11', hideTimestamp: true, }, { content: 'Step 2: xxxxxx', timestamp: '2018-04-13', }, { content: 'Step 3: xxxxxx', timestamp: '2018-04-15', }], } }, }) const timestampWrappers = wrapper.findAll('.el-timeline-item__timestamp') expect(timestampWrappers.length).toEqual(2) }) test('color', () => { const wrapper = mount({ ...Component, template: ` Step 1: xxxxxx `, }) const vm = wrapper.vm const nodeElm = vm.$el.querySelector('.el-timeline-item__node') expect(nodeElm.style.backgroundColor).toEqual('rgb(255, 0, 0)') }) test('type', () => { const wrapper = mount({ ...Component, template: ` Step 1: xxxxxx `, }) const nodeWrapper = wrapper.find('.el-timeline-item__node') expect(nodeWrapper.classes('el-timeline-item__node--primary')).toBe(true) }) test('size', () => { const wrapper = mount({ ...Component, template: ` Step 1: xxxxxx `, }) const nodeWrapper = wrapper.find('.el-timeline-item__node') expect(nodeWrapper.classes('el-timeline-item__node--large')).toBe(true) }) test('icon', () => { const wrapper = mount({ ...Component, template: ` Step 1: xxxxxx `, }) const nodeWrapper = wrapper.find('.el-timeline-item__icon') expect(nodeWrapper.classes('el-icon-more')).toBe(true) }) test('dot', () => { const wrapper = mount({ ...Component, template: ` `, }) const dotWrapper = wrapper.find('.el-timeline-item__dot') expect(dotWrapper.text()).toEqual('dot') expect(wrapper.find('.el-timeline-item__node').exists()).toBe(false) }) })