ebaa7f3c50
ci/woodpecker/manual/woodpecker Pipeline was successful
- 移除未使用的YAML锚点定义 - 替换commands字段中的锚点引用为实际值 - 移除有问题的通知步骤 - 修复测试文件中的问题 - 添加新的测试用例和配置文件
379 lines
14 KiB
TypeScript
379 lines
14 KiB
TypeScript
import { describe, it, expect, beforeEach } from '@jest/globals';
|
|
|
|
jest.mock('./constants', () => ({
|
|
COMPANY_INFO: {
|
|
name: '诺瓦隆科技',
|
|
email: 'contact@novalon.cn',
|
|
phone: '400-123-4567',
|
|
address: '北京市朝阳区科技园区',
|
|
},
|
|
}));
|
|
|
|
describe('Email Templates', () => {
|
|
const mockContactData = {
|
|
name: '张三',
|
|
phone: '13800138000',
|
|
email: 'zhangsan@example.com',
|
|
message: '这是一条测试留言',
|
|
};
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
describe('generateNotificationEmail', () => {
|
|
it('should generate valid HTML email', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('<!DOCTYPE html>');
|
|
expect(email).toContain('<html>');
|
|
expect(email).toContain('</html>');
|
|
});
|
|
|
|
it('should include customer name', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('张三');
|
|
expect(email).toContain('客户姓名');
|
|
});
|
|
|
|
it('should include customer phone', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('13800138000');
|
|
expect(email).toContain('联系电话');
|
|
});
|
|
|
|
it('should include customer email', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('zhangsan@example.com');
|
|
expect(email).toContain('电子邮箱');
|
|
});
|
|
|
|
it('should include message content', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('这是一条测试留言');
|
|
expect(email).toContain('留言内容');
|
|
});
|
|
|
|
it('should include company name', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('诺瓦隆科技');
|
|
});
|
|
|
|
it('should include submit time', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('提交时间');
|
|
});
|
|
|
|
it('should include mailto link', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('mailto:zhangsan@example.com');
|
|
expect(email).toContain('快速回复');
|
|
});
|
|
|
|
it('should include company address in footer', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('北京市朝阳区科技园区');
|
|
});
|
|
|
|
it('should have proper email title', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('官网留言通知');
|
|
});
|
|
|
|
it('should include responsive meta tag', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('viewport');
|
|
expect(email).toContain('width=device-width');
|
|
});
|
|
|
|
it('should include UTF-8 charset', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('charset="utf-8"');
|
|
});
|
|
|
|
it('should handle long messages', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const longMessage = '这是一条很长的留言'.repeat(100);
|
|
const data = { ...mockContactData, message: longMessage };
|
|
const email = generateNotificationEmail(data);
|
|
|
|
expect(email).toContain(longMessage);
|
|
});
|
|
|
|
it('should handle special characters in name', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const data = { ...mockContactData, name: '张三 <script>alert("xss")</script>' };
|
|
const email = generateNotificationEmail(data);
|
|
|
|
expect(email).toContain('张三 <script>alert("xss")</script>');
|
|
});
|
|
|
|
it('should handle special characters in message', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const data = { ...mockContactData, message: '测试 & < > " \'' };
|
|
const email = generateNotificationEmail(data);
|
|
|
|
expect(email).toContain('测试 & < > " \'');
|
|
});
|
|
});
|
|
|
|
describe('generateConfirmationEmail', () => {
|
|
it('should generate valid HTML email', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('<!DOCTYPE html>');
|
|
expect(email).toContain('<html>');
|
|
expect(email).toContain('</html>');
|
|
});
|
|
|
|
it('should include customer name', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('张三');
|
|
expect(email).toContain('尊敬的');
|
|
});
|
|
|
|
it('should include message content', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('这是一条测试留言');
|
|
expect(email).toContain('您的留言内容');
|
|
});
|
|
|
|
it('should include company name', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('诺瓦隆科技');
|
|
});
|
|
|
|
it('should include company contact information', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('contact@novalon.cn');
|
|
expect(email).toContain('北京市朝阳区科技园区');
|
|
});
|
|
|
|
it('should include expected response time', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('预计回复时间');
|
|
expect(email).toContain('2小时内');
|
|
});
|
|
|
|
it('should include working hours', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('工作日');
|
|
expect(email).toContain('9:00 - 18:00');
|
|
});
|
|
|
|
it('should have proper email title', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('感谢您的留言');
|
|
});
|
|
|
|
it('should include success icon', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('🎉');
|
|
});
|
|
|
|
it('should include current year in footer', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
const currentYear = new Date().getFullYear().toString();
|
|
|
|
expect(email).toContain(`© ${currentYear}`);
|
|
});
|
|
|
|
it('should include responsive meta tag', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('viewport');
|
|
expect(email).toContain('width=device-width');
|
|
});
|
|
|
|
it('should include UTF-8 charset', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('charset="utf-8"');
|
|
});
|
|
|
|
it('should handle long messages', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const longMessage = '这是一条很长的留言'.repeat(100);
|
|
const data = { ...mockContactData, message: longMessage };
|
|
const email = generateConfirmationEmail(data);
|
|
|
|
expect(email).toContain(longMessage);
|
|
});
|
|
|
|
it('should handle special characters in name', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const data = { ...mockContactData, name: '张三 <script>alert("xss")</script>' };
|
|
const email = generateConfirmationEmail(data);
|
|
|
|
expect(email).toContain('张三 <script>alert("xss")</script>');
|
|
});
|
|
});
|
|
|
|
describe('Email Template Structure', () => {
|
|
it('should have consistent styling in notification email', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('style');
|
|
expect(email).toContain('font-family');
|
|
expect(email).toContain('max-width: 600px');
|
|
});
|
|
|
|
it('should have consistent styling in confirmation email', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('style');
|
|
expect(email).toContain('font-family');
|
|
expect(email).toContain('max-width: 600px');
|
|
});
|
|
|
|
it('should use brand colors in notification email', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('#C41E3A');
|
|
expect(email).toContain('#1C1C1C');
|
|
});
|
|
|
|
it('should use brand colors in confirmation email', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('#C41E3A');
|
|
expect(email).toContain('#1C1C1C');
|
|
});
|
|
|
|
it('should have proper container structure in notification email', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const email = generateNotificationEmail(mockContactData);
|
|
|
|
expect(email).toContain('class="container"');
|
|
expect(email).toContain('class="header"');
|
|
expect(email).toContain('class="content"');
|
|
expect(email).toContain('class="footer"');
|
|
});
|
|
|
|
it('should have proper container structure in confirmation email', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const email = generateConfirmationEmail(mockContactData);
|
|
|
|
expect(email).toContain('class="container"');
|
|
expect(email).toContain('class="header"');
|
|
expect(email).toContain('class="content"');
|
|
expect(email).toContain('class="footer"');
|
|
});
|
|
});
|
|
|
|
describe('Edge Cases', () => {
|
|
it('should handle empty message', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const data = { ...mockContactData, message: '' };
|
|
const email = generateNotificationEmail(data);
|
|
|
|
expect(email).toContain('留言内容');
|
|
});
|
|
|
|
it('should handle empty name', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
const data = { ...mockContactData, name: '' };
|
|
const email = generateConfirmationEmail(data);
|
|
|
|
expect(email).toContain('尊敬的');
|
|
});
|
|
|
|
it('should handle email with special characters', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const data = { ...mockContactData, email: 'test+special@example.com' };
|
|
const email = generateNotificationEmail(data);
|
|
|
|
expect(email).toContain('test+special@example.com');
|
|
});
|
|
|
|
it('should handle phone number with spaces', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const data = { ...mockContactData, phone: '138 0013 8000' };
|
|
const email = generateNotificationEmail(data);
|
|
|
|
expect(email).toContain('138 0013 8000');
|
|
});
|
|
|
|
it('should handle unicode characters in message', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
const data = { ...mockContactData, message: '测试 emoji: 😀 🎉 📧' };
|
|
const email = generateNotificationEmail(data);
|
|
|
|
expect(email).toContain('测试 emoji: 😀 🎉 📧');
|
|
});
|
|
});
|
|
|
|
describe('Performance Tests', () => {
|
|
it('should generate notification email quickly', async () => {
|
|
const { generateNotificationEmail } = await import('./email-templates');
|
|
|
|
const start = performance.now();
|
|
for (let i = 0; i < 100; i++) {
|
|
generateNotificationEmail(mockContactData);
|
|
}
|
|
const end = performance.now();
|
|
|
|
expect(end - start).toBeLessThan(1000);
|
|
});
|
|
|
|
it('should generate confirmation email quickly', async () => {
|
|
const { generateConfirmationEmail } = await import('./email-templates');
|
|
|
|
const start = performance.now();
|
|
for (let i = 0; i < 100; i++) {
|
|
generateConfirmationEmail(mockContactData);
|
|
}
|
|
const end = performance.now();
|
|
|
|
expect(end - start).toBeLessThan(1000);
|
|
});
|
|
});
|
|
});
|