methodology-config-mock.test.ts
2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { describe, expect, it } from 'vitest';
import {
getMethodologyConfigFixture,
methodologyConfigMockFixtures,
validateMethodologyContentImageFile,
} from './methodology-config-mock';
describe('methodology config mock contract', () => {
it('provides the minimal page-facing config fields and step resources', () => {
const fixture = methodologyConfigMockFixtures.normal;
expect(fixture.data).toMatchObject({
config_id: expect.any(String),
display_status: expect.stringMatching(/enable|disable/),
main_title: expect.any(String),
sub_title: expect.any(String),
steps: expect.any(Array),
});
expect(fixture.data.steps[0]).toMatchObject({
step_id: expect.any(String),
step_icon: {
id: expect.any(String),
name: expect.any(String),
url: expect.any(String),
},
step_name: expect.any(String),
step_order: expect.any(Number),
step_image: {
id: expect.any(String),
name: expect.any(String),
url: expect.any(String),
mime_type: expect.stringMatching(/image\/(png|jpeg|gif)/),
size_bytes: expect.any(Number),
},
});
});
it('covers required load, save, and upload fixtures without locking a backend', () => {
expect(Object.keys(methodologyConfigMockFixtures).sort()).toEqual([
'disabled',
'emptySteps',
'invalidFileType',
'largeFile',
'loadError',
'normal',
'saveError',
'uploadError',
]);
});
it('exposes scenario lookup for page state selection', () => {
expect(getMethodologyConfigFixture('disabled').data.display_status).toBe('disable');
expect(getMethodologyConfigFixture('missing-scenario')).toBe(methodologyConfigMockFixtures.normal);
});
it('validates content image format and size with page-facing error messages', () => {
// GIF is now supported
expect(validateMethodologyContentImageFile(new File(['demo'], 'cover.gif', { type: 'image/gif' }))).toBeUndefined();
// BMP is not supported
expect(validateMethodologyContentImageFile(new File(['demo'], 'cover.bmp', { type: 'image/bmp' }))).toEqual({
code: 'invalid-file-type',
message: '内容图仅支持 PNG/JPG/JPEG/GIF',
});
const oversized = new File(['demo'], 'cover.png', { type: 'image/png' });
Object.defineProperty(oversized, 'size', { value: 10 * 1024 * 1024 + 1 });
expect(validateMethodologyContentImageFile(oversized)).toEqual({
code: 'file-too-large',
message: '内容图大小不能超过 10MB',
});
expect(validateMethodologyContentImageFile(new File(['demo'], 'cover.jpg', { type: 'image/jpeg' }))).toBeUndefined();
});
});