Files
SlabUploader/frontend/src/create/publish/publishPreview.contract.test.ts
T
grokbot_ty 73e28180c8 feat(publish): Publish preview before Woo draft POST
After Review → Continue to Publish, show a glanceable confirmation:
ordered photo thumbs, SKU/title/price, taxonomy + dims, short and long
descriptions (plain text). Back to Review edits; Publish posts the draft.
Reuses slab/taxonomy/photos only — no invented fields.
2026-09-26 11:47:18 -07:00

51 lines
2.3 KiB
TypeScript

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { test } from 'node:test';
const dir = dirname(fileURLToPath(import.meta.url));
const publishSrc = readFileSync(join(dir, 'Publish.svelte'), 'utf8');
const previewSrc = readFileSync(join(dir, 'PublishPreview.svelte'), 'utf8');
const modelSrc = readFileSync(join(dir, 'publishPreviewModel.ts'), 'utf8');
test('Publish uses dedicated PublishPreview before Woo POST', () => {
assert.match(publishSrc, /import PublishPreview from '\.\/PublishPreview\.svelte'/);
assert.match(publishSrc, /buildPublishPreviewModel/);
assert.match(publishSrc, /data-testid="publish-preview"|PublishPreview/);
// Idle confirm still posts only via doPublish / publish-btn
assert.match(publishSrc, /data-testid="publish-btn"/);
assert.match(publishSrc, /data-testid="back-review"/);
assert.match(publishSrc, /publishSlab\(slabId\)/);
});
test('PublishPreview layout: thumbs → head → facts → short → long', () => {
assert.match(previewSrc, /data-testid="publish-preview"/);
assert.match(previewSrc, /data-testid="preview-thumbs"/);
assert.match(previewSrc, /data-testid="preview-head"/);
assert.match(previewSrc, /data-testid="preview-sku"/);
assert.match(previewSrc, /data-testid="preview-title"/);
assert.match(previewSrc, /data-testid="preview-price"/);
assert.match(previewSrc, /data-testid="preview-facts"/);
assert.match(previewSrc, /data-testid="preview-short"/);
assert.match(previewSrc, /data-testid="preview-long"/);
// Plain-text long description (pre-wrap), not HTML render
assert.match(previewSrc, /white-space:\s*pre-wrap/);
assert.match(previewSrc, /<pre class="body long"/);
});
test('Preview model resolves taxonomy names; does not invent fields', () => {
assert.match(modelSrc, /species_id/);
assert.match(modelSrc, /wood_category_ids/);
assert.match(modelSrc, /edge_type_term_id/);
assert.match(modelSrc, /figure_term_ids/);
assert.match(modelSrc, /grade_term_id/);
assert.match(modelSrc, /moisture_term_id/);
assert.match(modelSrc, /feat_tag_ids/);
assert.match(modelSrc, /width_min_in/);
assert.match(modelSrc, /bdft/);
assert.match(modelSrc, /decodeName/);
// No invented brand/voice fields
assert.equal(modelSrc.includes('brand_voice'), false);
});