Skip to content

Commit 1afd840

Browse files
SW-1764 fix Zephyr objective normalization
1 parent f1419c6 commit 1afd840

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

scripts/zephyr/__tests__/sync-storybook-zephyr.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,14 @@ export const Warning: Story = {
361361
"Component: Elevation & Shape<br>Story: Brand — Active<br>File: `src/foo.stories.tsx`",
362362
);
363363
});
364+
365+
it("does not recursively decode entities produced by earlier replacements", () => {
366+
const objective = "Component: Copy<br>Story: Literal &amp;mdash; Text<br>File: `src/foo.stories.tsx`";
367+
368+
expect(normalizeZephyrObjective(objective)).toBe(
369+
"Component: Copy<br>Story: Literal &mdash; Text<br>File: `src/foo.stories.tsx`",
370+
);
371+
});
364372
});
365373

366374
describe("selectReusableTestCase", () => {

scripts/zephyr/sync-storybook-zephyr.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ const folderIdCache: FolderCache = {};
123123
let generatedTestCaseCache: ZephyrTestCase[] | null = null;
124124
const testCaseDetailCache = new Map<string, ZephyrTestCase>();
125125
const executionCountCache = new Map<string, number>();
126+
const OBJECTIVE_ENTITY_REPLACEMENTS: Record<string, string> = {
127+
"#39": "'",
128+
amp: "&",
129+
mdash: "—",
130+
ndash: "–",
131+
quot: "\"",
132+
};
126133

127134
function findStoryFiles(dir: string): string[] {
128135
const storyFiles: string[] = [];
@@ -462,11 +469,7 @@ export function findDuplicateZephyrIds(stories: StoryCase[]): DuplicateZephyrId[
462469

463470
export function normalizeZephyrObjective(objective: string | null | undefined): string {
464471
return (objective ?? "")
465-
.replace(/&amp;/g, "&")
466-
.replace(/&mdash;/g, "—")
467-
.replace(/&ndash;/g, "–")
468-
.replace(/&quot;/g, "\"")
469-
.replace(/&#39;/g, "'")
472+
.replace(/&(#39|amp|mdash|ndash|quot);/g, (_, entity: string) => OBJECTIVE_ENTITY_REPLACEMENTS[entity])
470473
.replace(/<br\s*\/?\s*>/gi, "<br>")
471474
.replace(/\s+/g, " ")
472475
.trim();

0 commit comments

Comments
 (0)