-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathrender-createsite-plan.test.js
More file actions
170 lines (146 loc) · 6.08 KB
/
Copy pathrender-createsite-plan.test.js
File metadata and controls
170 lines (146 loc) · 6.08 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const scriptPath = path.join(__dirname, '..', 'render-createsite-plan.js');
const SAMPLE_DATA = {
SITE_NAME: 'Contoso Portal',
PLAN_TITLE: 'Implementation Plan',
FRAMEWORK: 'React',
AESTHETIC: 'Minimal & Clean',
MOOD: 'Professional & Trustworthy',
SUMMARY: 'An internal portal for Contoso consultants with directory, announcements, and docs.',
TYPOGRAPHY_DATA: {
primary: { name: 'DM Sans', sample: 'Aa Bb Cc', reason: 'Neutral sans for body and UI' },
secondary: { name: 'Space Grotesk', sample: 'Headings', reason: 'Geometric display for headings' },
},
PALETTE_DATA: [
{ var: '--color-primary', hex: '#1E3A5F', description: 'Primary brand' },
{ var: '--color-secondary', hex: '#4A90A4', description: 'Accent' },
{ var: '--color-bg', hex: '#F7F8FA', description: 'Background' },
],
MOTION_DATA: [
{ label: 'Page transitions', description: 'Fade-in 300ms on route change' },
],
BACKGROUNDS_DATA: [
{ label: 'Hero section', description: 'Gradient overlay on Unsplash photo' },
],
PAGES_DATA: [
{
name: 'Home',
route: '/',
description: 'Landing page for the portal',
content: ['Hero section', 'Quick links', 'Recent announcements'],
components: ['Navbar', 'Hero', 'QuickLinks'],
},
{
name: 'Directory',
route: '/directory',
description: 'Searchable consultant directory',
content: ['Search bar', 'Consultant cards'],
components: ['Navbar', 'ConsultantCard'],
},
],
COMPONENTS_DATA: [
{ name: 'Navbar', purpose: 'Top navigation', usedBy: ['Home', 'Directory'] },
{ name: 'Hero', purpose: 'Landing hero section', usedBy: ['Home'] },
],
ROUTES_DATA: [
{ path: '/', page: 'Home' },
{ path: '/directory', page: 'Directory' },
],
REVIEW_DATA: [
'All pages load without console errors',
'Navigation links work and highlight the active page',
],
DEPLOYMENT_DATA: [
{ title: 'Deploy now to Power Pages', description: 'Runs /deploy-site to publish.', recommended: true },
{ title: 'Skip for now', description: 'Continue locally, deploy later.' },
],
};
test('render-createsite-plan renders HTML from --data file', () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'createsite-plan-'));
const dataPath = path.join(tempDir, 'data.json');
const outputPath = path.join(tempDir, 'plan.html');
fs.writeFileSync(dataPath, JSON.stringify(SAMPLE_DATA, null, 2), 'utf8');
const result = spawnSync(process.execPath, [scriptPath, '--output', outputPath, '--data', dataPath], {
encoding: 'utf8',
});
assert.equal(result.status, 0, result.stderr || result.stdout);
assert.ok(fs.existsSync(outputPath));
const html = fs.readFileSync(outputPath, 'utf8');
assert.match(html, /Contoso Portal/);
assert.match(html, /Implementation Plan/);
assert.match(html, /React/);
assert.match(html, /Minimal & Clean|Minimal & Clean/);
assert.match(html, /DM Sans/);
assert.match(html, /#1E3A5F/);
assert.match(html, /Directory/);
assert.match(html, /Navbar/);
assert.match(html, /Deploy now to Power Pages/);
});
test('render-createsite-plan renders HTML from --data-inline JSON', () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'createsite-plan-'));
const outputPath = path.join(tempDir, 'plan-inline.html');
const result = spawnSync(
process.execPath,
[scriptPath, '--output', outputPath, '--data-inline', JSON.stringify(SAMPLE_DATA)],
{ encoding: 'utf8' }
);
assert.equal(result.status, 0, result.stderr || result.stdout);
assert.ok(fs.existsSync(outputPath));
const html = fs.readFileSync(outputPath, 'utf8');
assert.match(html, /Contoso Portal/);
assert.match(html, /Space Grotesk/);
});
test('render-createsite-plan fails with no arguments', () => {
const result = spawnSync(process.execPath, [scriptPath], { encoding: 'utf8' });
assert.notEqual(result.status, 0);
assert.match(result.stderr, /Usage:/);
});
test('render-createsite-plan fails with invalid --data-inline JSON', () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'createsite-plan-'));
const outputPath = path.join(tempDir, 'plan.html');
const result = spawnSync(
process.execPath,
[scriptPath, '--output', outputPath, '--data-inline', '{bad json}'],
{ encoding: 'utf8' }
);
assert.equal(result.status, 1);
assert.match(result.stderr, /not valid JSON/);
});
test('render-createsite-plan fails when required keys are missing', () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'createsite-plan-'));
const outputPath = path.join(tempDir, 'plan.html');
const incomplete = { ...SAMPLE_DATA };
delete incomplete.PAGES_DATA;
delete incomplete.ROUTES_DATA;
const result = spawnSync(
process.execPath,
[scriptPath, '--output', outputPath, '--data-inline', JSON.stringify(incomplete)],
{ encoding: 'utf8' }
);
assert.equal(result.status, 1);
assert.match(result.stderr, /Missing required keys/);
assert.match(result.stderr, /PAGES_DATA/);
assert.match(result.stderr, /ROUTES_DATA/);
});
test('render-createsite-plan refuses to overwrite existing file', () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'createsite-plan-'));
const dataPath = path.join(tempDir, 'data.json');
const outputPath = path.join(tempDir, 'plan.html');
fs.writeFileSync(dataPath, JSON.stringify(SAMPLE_DATA, null, 2), 'utf8');
const result1 = spawnSync(process.execPath, [scriptPath, '--output', outputPath, '--data', dataPath], {
encoding: 'utf8',
});
assert.equal(result1.status, 0, result1.stderr || result1.stdout);
const original = fs.readFileSync(outputPath, 'utf8');
const result2 = spawnSync(process.execPath, [scriptPath, '--output', outputPath, '--data', dataPath], {
encoding: 'utf8',
});
assert.equal(result2.status, 1);
assert.match(result2.stderr, /Output file already exists/);
assert.equal(fs.readFileSync(outputPath, 'utf8'), original);
});