Repository navigation
fix(bestax-migrate): keep a title's heading level when its size carries over #1071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6bbb3c5
fix(bestax-migrate): keep a title's heading level when its size carri…
allxsmith 9e8a803
docs(bulma-ui): keep the ProfileCard name an h3 by sizing it with tex…
allxsmith 5b1c6d8
Merge remote-tracking branch 'origin/main' into gate-fix-1069-title-l…
allxsmith 7601b06
fix(bestax-migrate): carry a title size of 7, and read a spread the s…
allxsmith 3da1c2a
docs: say textSize's class is !important, and send heading sizes to a…
allxsmith e66c1ba
fix(create-bestax): send the scaffolded CLAUDE.md's heading sizes to …
allxsmith 4b48f5c
chore: regenerate
allxsmith 795e233
Merge remote-tracking branch 'origin/main' into gate-fix-1069-title-l…
allxsmith 2871c2a
Merge remote-tracking branch 'origin/main' into gate-fix-1069-title-l…
allxsmith 7e95f94
chore: regenerate after merging main
allxsmith d1dd5e5
fix(bestax-migrate): say what an out-of-range title size loses, and f…
allxsmith 1868195
chore: regenerate
allxsmith 5a687a5
Merge remote-tracking branch 'origin/main' into gate-fix-1069-title-l…
allxsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /** | ||
| * A migrated title keeps its heading level (#1069). | ||
| * | ||
| * Every source library rendered a title at the element its tag prop named, | ||
| * or at its own default, whatever the size. bestax's `Title` and `SubTitle` | ||
| * render the heading their `size` names unless `as="p"`, so a plain rename | ||
| * of the size turned bloomer's `<Subtitle isSize={4}>` from an <h2> into an | ||
| * <h4>, which a fixture that compares text cannot see. This renders the | ||
| * migrated output against the built library and compares the opening tag | ||
| * with what the source library rendered, class list included. `is-size-N` | ||
| * (from `textSize`) reads as `is-N` there, because Bulma gives both the same | ||
| * font size. | ||
| * | ||
| * Only the OUTPUT runs. The inputs import libraries this repo never | ||
| * installs, so what each one rendered is written beside it, read off the | ||
| * library's own component at the SHA its corpus script pins. | ||
| */ | ||
|
|
||
| import { SOURCES } from '../src/sources/registry.js'; | ||
| import { runTransform } from '../src/runner.js'; | ||
| import type { TodoEntry } from '../src/types.js'; | ||
| import { | ||
| loadModules, | ||
| normalizeHtml, | ||
| renderExports, | ||
| } from './support/render-module.js'; | ||
|
|
||
| /** [source JSX, the opening tag the source library rendered for it] */ | ||
| type Case = [string, string]; | ||
|
|
||
| const LIBRARIES: Array<[source: string, imports: string, cases: Case[]]> = [ | ||
| [ | ||
| // Title defaulted to an <h1> and Subtitle to an <h2>. | ||
| 'bloomer', | ||
| "import { Subtitle, Title } from 'bloomer';", | ||
| [ | ||
| ['<Title>x</Title>', '<h1 class="title">'], | ||
| ['<Title isSize={1}>x</Title>', '<h1 class="title is-1">'], | ||
| ['<Title isSize={4}>x</Title>', '<h1 class="title is-4">'], | ||
| ['<Title isSize={4} tag="h2">x</Title>', '<h2 class="title is-4">'], | ||
| ['<Title isSize={4} tag="h4">x</Title>', '<h4 class="title is-4">'], | ||
| ['<Title isSize={6} tag="p">x</Title>', '<p class="title is-6">'], | ||
| ['<Title isSize={7}>x</Title>', '<h1 class="title is-7">'], | ||
| ['<Title isSize={7} tag="p">x</Title>', '<p class="title is-7">'], | ||
| ['<Subtitle>x</Subtitle>', '<h2 class="subtitle">'], | ||
| ['<Subtitle isSize={2}>x</Subtitle>', '<h2 class="subtitle is-2">'], | ||
| ['<Subtitle isSize={4}>x</Subtitle>', '<h2 class="subtitle is-4">'], | ||
| [ | ||
| '<Subtitle isSize="5" tag="h3">x</Subtitle>', | ||
| '<h3 class="subtitle is-5">', | ||
| ], | ||
| ], | ||
| ], | ||
| [ | ||
| // Title defaulted to an <h1>, subtitle or not. | ||
| 'rbx', | ||
| "import { Title } from 'rbx';", | ||
| [ | ||
| ['<Title size={1}>x</Title>', '<h1 class="title is-1">'], | ||
| ['<Title size={4}>x</Title>', '<h1 class="title is-4">'], | ||
| ['<Title subtitle size={6}>x</Title>', '<h1 class="subtitle is-6">'], | ||
| ['<Title as="h3" size={3}>x</Title>', '<h3 class="title is-3">'], | ||
| ['<Title as="h2" size={5}>x</Title>', '<h2 class="title is-5">'], | ||
| [ | ||
| '<Title as="p" subtitle size={5}>x</Title>', | ||
| '<p class="subtitle is-5">', | ||
| ], | ||
| ['<Title as="p" size={7}>x</Title>', '<p class="title is-7">'], | ||
| ], | ||
| ], | ||
| [ | ||
| // Heading's `renderAs` defaulted to an <h1>, subtitle or not. | ||
| 'react-bulma-components', | ||
| "import { Heading } from 'react-bulma-components';", | ||
| [ | ||
| ['<Heading size={1}>x</Heading>', '<h1 class="title is-1">'], | ||
| ['<Heading size={4}>x</Heading>', '<h1 class="title is-4">'], | ||
| ['<Heading subtitle size={6}>x</Heading>', '<h1 class="subtitle is-6">'], | ||
| [ | ||
| '<Heading renderAs="h3" size={3}>x</Heading>', | ||
| '<h3 class="title is-3">', | ||
| ], | ||
| [ | ||
| '<Heading renderAs="h2" size="5">x</Heading>', | ||
| '<h2 class="title is-5">', | ||
| ], | ||
| [ | ||
| '<Heading renderAs="p" subtitle size={5}>x</Heading>', | ||
| '<p class="subtitle is-5">', | ||
| ], | ||
| ['<Heading size={7}>x</Heading>', '<h1 class="title is-7">'], | ||
| ], | ||
| ], | ||
| ]; | ||
|
|
||
| /** The rendered element's opening tag, with `is-size-N` read as `is-N`. */ | ||
| function openingTag(html: string): string { | ||
| return normalizeHtml( | ||
| html.slice(0, html.indexOf('>') + 1).replace(/\bis-size-(\d)\b/g, 'is-$1') | ||
| ); | ||
| } | ||
|
|
||
| describe.each(LIBRARIES)('a %s title', (source, imports, cases) => { | ||
| test.each(cases)('%s keeps its element', (input, rendered) => { | ||
| const todos: TodoEntry[] = []; | ||
| const { output } = runTransform( | ||
| SOURCES[source].transform, | ||
| 'title.tsx', | ||
| `${imports}\nexport const A = () => ${input};\n`, | ||
| { add: entry => todos.push(entry) } | ||
| ); | ||
| expect(todos).toEqual([]); | ||
| const { A } = renderExports(loadModules({ title: output ?? '' }).title); | ||
| expect(openingTag(A)).toBe(normalizeHtml(rendered)); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
bestax-migrate/src/sources/bloomer/__testfixtures__/title-levels.input.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import React from "react"; | ||
| import { Subtitle, Title } from "bloomer"; | ||
|
|
||
| // bloomer rendered Title as an <h1> and Subtitle as an <h2> at every isSize, | ||
| // or the element `tag` named. bestax renders the heading `size` names, so | ||
| // the size moves to textSize wherever `size` would change the element. | ||
| export const Levels = () => ( | ||
| <section> | ||
| <Title>h1</Title> | ||
| <Title isSize={1}>h1, which size 1 renders too</Title> | ||
| <Title isSize={4}>h1</Title> | ||
| <Title isSize={4} tag="h2">h2</Title> | ||
| <Title isSize={4} tag="h4">h4, which size 4 renders too</Title> | ||
| <Title isSize={6} tag="p">p, which size never changes</Title> | ||
| <Title isSize={7}>h1, at a size bestax's size does not take</Title> | ||
| <Title isSize={7} tag="p">p, where size 7 would lose its class</Title> | ||
| <Subtitle>h2</Subtitle> | ||
| <Subtitle isSize={2}>h2, which size 2 renders too</Subtitle> | ||
| <Subtitle isSize={4}>h2</Subtitle> | ||
| <Subtitle isSize="5" tag="h3">h3</Subtitle> | ||
| </section> | ||
| ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.