Initial commit: 积分兑换电商平台多商户版 MER-2.2

Made-with: Cursor
This commit is contained in:
apple
2026-03-08 20:07:52 +08:00
commit de02c8a3e1
4954 changed files with 703009 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
module.exports = {
env: {
jest: true,
},
};

View File

@@ -0,0 +1,18 @@
import { shallowMount } from '@vue/test-utils';
import Hamburger from '@/components/Hamburger/index.vue';
describe('Hamburger.vue', () => {
it('toggle click', () => {
const wrapper = shallowMount(Hamburger);
const mockFn = jest.fn();
wrapper.vm.$on('toggleClick', mockFn);
wrapper.find('.hamburger').trigger('click');
expect(mockFn).toBeCalled();
});
it('prop isActive', () => {
const wrapper = shallowMount(Hamburger);
wrapper.setProps({ isActive: true });
expect(wrapper.contains('.is-active')).toBe(true);
wrapper.setProps({ isActive: false });
expect(wrapper.contains('.is-active')).toBe(false);
});
});

View File

@@ -0,0 +1,22 @@
import { shallowMount } from '@vue/test-utils';
import SvgIcon from '@/components/SvgIcon/index.vue';
describe('SvgIcon.vue', () => {
it('iconClass', () => {
const wrapper = shallowMount(SvgIcon, {
propsData: {
iconClass: 'test',
},
});
expect(wrapper.find('use').attributes().href).toBe('#icon-test');
});
it('className', () => {
const wrapper = shallowMount(SvgIcon, {
propsData: {
iconClass: 'test',
},
});
expect(wrapper.classes().length).toBe(1);
wrapper.setProps({ className: 'test' });
expect(wrapper.classes().includes('test')).toBe(true);
});
});

View File

@@ -0,0 +1,29 @@
import { formatTime } from '@/utils/index.js';
describe('Utils:formatTime', () => {
const d = new Date('2018-07-13 17:54:01'); // "2018-07-13 17:54:01"
const retrofit = 5 * 1000;
it('ten digits timestamp', () => {
expect(formatTime((d / 1000).toFixed(0))).toBe('7月13日17时54分');
});
it('test now', () => {
expect(formatTime(+new Date() - 1)).toBe('刚刚');
});
it('less two minute', () => {
expect(formatTime(+new Date() - 60 * 2 * 1000 + retrofit)).toBe('2分钟前');
});
it('less two hour', () => {
expect(formatTime(+new Date() - 60 * 60 * 2 * 1000 + retrofit)).toBe('2小时前');
});
it('less one day', () => {
expect(formatTime(+new Date() - 60 * 60 * 24 * 1 * 1000)).toBe('1天前');
});
it('more than one day', () => {
expect(formatTime(d)).toBe('7月13日17时54分');
});
it('format', () => {
expect(formatTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54');
expect(formatTime(d, '{y}-{m}-{d}')).toBe('2018-07-13');
expect(formatTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54');
});
});

View File

@@ -0,0 +1,32 @@
import { parseTime } from '@/utils/index.js';
describe('Utils:parseTime', () => {
const d = new Date('2018-07-13 17:54:01'); // "2018-07-13 17:54:01"
it('timestamp', () => {
expect(parseTime(d)).toBe('2018-07-13 17:54:01');
});
it('timestamp string', () => {
expect(parseTime(d + '')).toBe('2018-07-13 17:54:01');
});
it('ten digits timestamp', () => {
expect(parseTime((d / 1000).toFixed(0))).toBe('2018-07-13 17:54:01');
});
it('new Date', () => {
expect(parseTime(new Date(d))).toBe('2018-07-13 17:54:01');
});
it('format', () => {
expect(parseTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54');
expect(parseTime(d, '{y}-{m}-{d}')).toBe('2018-07-13');
expect(parseTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54');
});
it('get the day of the week', () => {
expect(parseTime(d, '{a}')).toBe('五'); // 星期五
});
it('get the day of the week', () => {
expect(parseTime(+d + 1000 * 60 * 60 * 24 * 2, '{a}')).toBe('日'); // 星期日
});
it('empty argument', () => {
expect(parseTime()).toBeNull();
});
});

View File

@@ -0,0 +1,28 @@
import { validUsername, validURL, validLowerCase, validUpperCase, validAlphabets } from '@/utils/validate.js';
describe('Utils:validate', () => {
it('validUsername', () => {
expect(validUsername('admin')).toBe(true);
expect(validUsername('editor')).toBe(true);
expect(validUsername('xxxx')).toBe(false);
});
it('validURL', () => {
expect(validURL('https://github.com/PanJiaChen/vue-element-admin')).toBe(true);
expect(validURL('http://github.com/PanJiaChen/vue-element-admin')).toBe(true);
expect(validURL('github.com/PanJiaChen/vue-element-admin')).toBe(false);
});
it('validLowerCase', () => {
expect(validLowerCase('abc')).toBe(true);
expect(validLowerCase('Abc')).toBe(false);
expect(validLowerCase('123abc')).toBe(false);
});
it('validUpperCase', () => {
expect(validUpperCase('ABC')).toBe(true);
expect(validUpperCase('Abc')).toBe(false);
expect(validUpperCase('123ABC')).toBe(false);
});
it('validAlphabets', () => {
expect(validAlphabets('ABC')).toBe(true);
expect(validAlphabets('Abc')).toBe(true);
expect(validAlphabets('123aBC')).toBe(false);
});
});