From 8479fd8c1d76428060e5c6b5ed5802cd20f58758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AA=86=E6=B2=9B?= Date: Tue, 27 Sep 2022 14:26:08 +0800 Subject: [PATCH] test(unit): card: add card test card: add card test --- src/card/__tests__/index.test.jsx | 153 ++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/src/card/__tests__/index.test.jsx b/src/card/__tests__/index.test.jsx index 83a8bc1da7..1513bf47d2 100644 --- a/src/card/__tests__/index.test.jsx +++ b/src/card/__tests__/index.test.jsx @@ -1,4 +1,5 @@ import { mount } from '@vue/test-utils'; +import { it, expect } from 'vitest'; import Card from '@/src/card'; // every component needs four parts: props/events/slots/functions. @@ -13,5 +14,157 @@ describe('Card', () => { }); expect(wrapper.exists()).toBe(true); }); + + it(':bordered', () => { + const wrapper = mount(() => ); + expect(wrapper.classes()).toContain('t-card--bordered'); + }); + + it(':shadow', () => { + const wrapper = mount(() => ); + expect(wrapper.classes()).toContain('t-card--shadow'); + }); + + it(':size:medium', () => { + const wrapper = mount(() => ); + expect(wrapper.classes()).toContain('t-card'); + }); + + it(':size:small', () => { + const wrapper = mount(() => ); + expect(wrapper.classes()).toContain('t-size-s'); + }); + + it(':hoverShadow', () => { + const wrapper = mount(() => 卡片内容); + expect(wrapper.classes()).toContain('t-card--shadow-hover'); + }); + + it(':default', () => { + const wrapper = mount(() => 卡片内容); + const body = wrapper.find('.t-card__body'); + expect(body.text()).toBe('卡片内容'); + }); + + it(':content', () => { + const wrapper = mount(() => ); + const body = wrapper.find('.t-card__body'); + expect(body.text()).toBe('卡片内容'); + }); + + it(':header', () => { + const wrapper = mount(() => 卡片内容); + const header = wrapper.find('.t-card__header'); + expect(header.exists()).toBeTruthy(); + expect(header.text()).toBe('header'); + }); + + it(':headerBordered', () => { + const wrapper = mount(() => ( + + 卡片内容 + + )); + const header = wrapper.find('.t-card__header'); + expect(header.exists()).toBeTruthy(); + expect(header.text()).toBe('header'); + expect(header.classes()).toContain('t-card__title--bordered'); + }); + + it(':footer', () => { + const wrapper = mount(() => 卡片内容); + const footer = wrapper.find('.t-card__footer'); + expect(footer.exists()).toBeTruthy(); + expect(footer.text()).toBe('footer'); + }); + + it(':title', () => { + const wrapper = mount(() => 卡片内容); + const title = wrapper.find('.t-card__title'); + expect(title.exists()).toBeTruthy(); + expect(title.text()).toBe('title'); + }); + + it(':subtitle', () => { + const wrapper = mount(() => 卡片内容); + const subtitle = wrapper.find('.t-card__subtitle'); + expect(subtitle.exists()).toBeTruthy(); + expect(subtitle.text()).toBe('subtitle'); + }); + + it(':description', () => { + const wrapper = mount(() => 卡片内容); + const description = wrapper.find('.t-card__description'); + expect(description.exists()).toBeTruthy(); + expect(description.text()).toBe('description'); + }); + + it(':avatar', () => { + const wrapper = mount(() => 卡片内容); + const avatar = wrapper.find('.t-card__avatar'); + expect(avatar.exists()).toBeTruthy(); + expect(avatar.text()).toBe('avatar'); + }); + + it(':cover', () => { + const src = 'https://tdesign.gtimg.com/site/source/card-demo.png'; + const wrapper = mount(() => 卡片内容); + const cover = wrapper.find('.t-card__cover img'); + expect(cover.exists()).toBeTruthy(); + expect(cover.element.getAttribute('src')).toBe(src); + }); + + it(':actions', () => { + const wrapper = mount(() => 卡片内容); + const actions = wrapper.find('.t-card__actions'); + expect(actions.exists()).toBeTruthy(); + expect(actions.text()).toBe('actions'); + }); + + it(':loading', () => { + const wrapper = mount(() => 卡片内容); + const loading = wrapper.find('.t-loading'); + const svg = loading.find('svg'); + expect(loading.exists()).toBeTruthy(); + expect(svg.exists()).toBeTruthy(); + expect(svg.classes()).toContain('t-icon-loading'); + }); + + it(':theme:poster1', () => { + const wrapper = mount(() => ( + + 卡片内容 + + )); + const header = wrapper.find('.t-card__header'); + const actions = header.find('.t-card__actions'); + expect(header.exists()).toBeTruthy(); + expect(actions.exists()).toBeTruthy(); + }); + + it(':theme:poster2', () => { + const wrapper = mount(() => ( + + 卡片内容 + + )); + const footer = wrapper.find('.t-card__footer'); + const actions = footer.find('.t-card__actions'); + expect(footer.exists()).toBeTruthy(); + expect(actions.exists()).toBeTruthy(); + }); + + it(':status', () => { + const wrapper = mount(() => ( + + 卡片内容 + + )); + const header = wrapper.find('.t-card__header'); + const actions = header.find('.t-card__actions'); + expect(header.exists()).toBeTruthy(); + expect(actions.exists()).toBeTruthy(); + expect(actions.text()).toBe('status'); + }); }); });