openmaic-custom/tests/lib/edit/html-edit.test.ts
wyuc dcf8a63333
fix(generation): make outline type changes take effect (interactive/PBL no longer downgraded to slide) (#772)
* feat(generation): changeOutlineType total constructor for valid type switches

Switching a scene outline's type in the editor only flipped `type` and left
the new type without its required config, so applyOutlineFallbacks silently
downgraded interactive/pbl back to slide. changeOutlineType returns a new
outline that strips foreign per-type config and seeds the target type's
required config from the shared fields, valid by construction.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* i18n(generation): keys for interactive widget kind and PBL project config

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(editor): make outline type changes take effect with config forms

TypePill now builds a valid outline via changeOutlineType (replace, not
partial-merge) so a type switch drops stale config and seeds the new type's
required config — no longer silently downgraded to slide by applyOutlineFallbacks.
Adds InteractiveConfigDisclosure (widget kind + concept) and PblConfigDisclosure
(topic / description / target skills), mirroring QuizConfigDisclosure, so users
can configure interactive and PBL scenes that previously had no input UI.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(editor): move type-specific config under the type pill

The quiz/interactive/PBL config disclosure rendered as a detached chip at the
bottom-left of the card, reading like a stray key point. Pin it to the
bottom-right of the key-points row instead, so it sits directly under the
TypePill it configures (type top-right -> its config bottom-right, same edge),
with key points flowing on the left.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(editor): cascade type config as a connected segment left of the type pill

Replace the standalone config chip with a cascading control in the header: the
type-specific config (quiz count / interactive widget kind / PBL project) renders
as a themed segment joined to the left of the TypePill, the two clipped into one
rounded pill split by a hairline divider. Reads as a single 'config › type'
cascade and groups the config with the selector it refines.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(editor): address cross-review — preserve widget config, drop stale fields

- changeOutlineType: preserve an existing procedural-skill widget config
  instead of replacing it with a seeded simulation (codex P2 — task-engine
  fields were silently dropped on Interactive re-select).
- InteractiveConfigDisclosure.setWidgetType: reset widgetOutline to the shared
  concept only, so switching widget kind drops the previous kind's fields
  (claude P2 — language/gameType/etc. leaked across kinds).
- i18n locale-coverage test now also checks ko-KR and pt-BR.
- Drop a redundant WidgetType cast; add tests for procedural-skill preservation
  and pbl targetSkills dedupe/cap.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(editor): round 2 cross-review nits — procedural-skill label + skill a11y

- InteractiveConfigDisclosure: when an outline carries a preserved
  procedural-skill widget, surface it as the current (selected) kind with its
  own label instead of mislabeling it 'Simulation', and make a same-kind
  re-select a no-op so its task-engine fields are never silently clobbered.
- PBL target-skill remove button uses a dedicated removeSkill aria-label.
- Add widgetProceduralSkill / removeSkill i18n keys (8 locales) + test coverage.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(generation): make re-selecting the current outline type a no-op

changeOutlineType rebuilt the outline on every type-menu click, so re-selecting
the already-current type dropped fields it doesn't re-seed — legacy
interactiveConfig, or a partial pblConfig whose projectTopic is empty — turning a
harmless click into data loss. Short-circuit same-type selections to return the
outline untouched (codex P2).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore(format): prettier --write files left unformatted on main

These 14 agent/edit files (not part of this PR's feature) fail the repo-wide
`prettier . --check` in the required Lint job — they landed on main unformatted,
turning main's CI (and therefore this PR after a branch update) red. Formatting
them here unblocks the required check; pure formatting, no logic changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(lint): suppress intentional set-state-in-effect in reasoning timer

The reasoning timer does a deliberate one-shot setState in its effect to show
the right elapsed value before the first 1s interval tick. main's CI fails the
required Lint job on the new react-hooks/set-state-in-effect rule here; suppress
it with a justification (no behavior change). Unblocks the required check.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 17:48:07 +08:00

59 lines
2.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { applyHtmlEdits, applyEditsToNormalizedContent } from '@/lib/edit/html-edit';
const HTML =
'<!DOCTYPE html>\n<html>\n<head></head>\n<body>\n<button id="go">Go</button>\n<script>document.getElementById("strt").addEventListener("click",fn);</script>\n</body>\n</html>\n';
describe('applyHtmlEdits (vendored pi edit core)', () => {
it('applies a single exact str_replace edit', () => {
const out = applyHtmlEdits(HTML, [
{ oldText: 'getElementById("strt")', newText: 'getElementById("go")' },
]);
expect(out).toContain('getElementById("go").addEventListener');
expect(out).not.toContain('strt');
// everything else preserved
expect(out).toContain('<button id="go">Go</button>');
});
it('applies multiple non-overlapping edits in one call', () => {
const out = applyHtmlEdits(HTML, [
{ oldText: '<button id="go">Go</button>', newText: '<button id="go">Start</button>' },
{ oldText: '"strt"', newText: '"go"' },
]);
expect(out).toContain('>Start<');
expect(out).toContain('getElementById("go")');
});
it('throws a not-found error when oldText is absent', () => {
expect(() => applyHtmlEdits(HTML, [{ oldText: 'does-not-exist', newText: 'x' }])).toThrow(
/Could not find/i,
);
});
it('throws an ambiguity error when oldText is not unique', () => {
expect(() =>
applyHtmlEdits('<p>x</p>\n<p>x</p>\n', [{ oldText: '<p>x</p>', newText: '<p>y</p>' }]),
).toThrow(/occurrences|unique/i);
});
it('throws when an edit makes no change', () => {
expect(() => applyHtmlEdits(HTML, [{ oldText: 'Go', newText: 'Go' }])).toThrow(
/No changes|identical/i,
);
});
it('fuzzy-matches smart quotes against ASCII oldText', () => {
// content has a smart double-quote; oldText uses an ASCII quote
const src = '<p>“hello”</p>\n';
const out = applyEditsToNormalizedContent(src, [{ oldText: '"hello"', newText: '"bye"' }], 'x');
expect(out.newContent).toContain('bye');
});
it('preserves CRLF line endings', () => {
const crlf = '<head></head>\r\n<body><b>old</b></body>\r\n';
const out = applyHtmlEdits(crlf, [{ oldText: '<b>old</b>', newText: '<b>new</b>' }]);
expect(out).toContain('\r\n');
expect(out).toContain('<b>new</b>');
});
});