Repository navigation
Add a ProductChooser fed from the product registry #417
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 all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
05f0642
Add a product registry and check every product name against it
eugenia-scandit b5f5cd7
feat: add ProductChooser ("Choose this if / not for" + framework matrix)
eugenia-scandit b520cdb
fix: exclude unavailable frameworks (version n/a) from ProductChooser…
eugenia-scandit 944508c
feat(ProductChooser): link the referenced product in each 'consider a…
eugenia-scandit d38a07d
Feed the ProductChooser from the product registry
eugenia-scandit 333d9c7
Address review: placement, contrast, list semantics, versions
eugenia-scandit e500b5e
Fix .NET links, version labels and frozen-version detection
eugenia-scandit abfd0cc
Typecheck the registry plugin; render the chooser on current docs only
eugenia-scandit d759916
Add the chooser to the Kotlin Multiplatform overviews
eugenia-scandit b1d7728
Accept chooser entries for sdk products only
eugenia-scandit f6084c4
Name the sequence product MatrixScan Sequence
eugenia-scandit b286372
Document the chooser file and accept it before its first entry
eugenia-scandit b733832
Merge remote-tracking branch 'origin/feat/product-registry' into docs…
eugenia-scandit 124fa24
Test the chooser's links; hide alternatives a framework lacks
eugenia-scandit be49732
Read the chooser file the same way on js-yaml 4 and 5
eugenia-scandit cbe80db
Merge commit 'be49732d8b' into docs/product-chooser
eugenia-scandit 0f6af2c
Strip a byte-order mark before parsing the registry files
eugenia-scandit 78ef970
Merge remote-tracking branch 'origin/feat/product-registry' into docs…
eugenia-scandit 183c36a
Parse the chooser file through the verifier; test the alternatives fi…
eugenia-scandit 21ac92c
Merge main into docs/product-chooser
eugenia-scandit 2037e72
Say which component uses isSupportedVersion after the merge
eugenia-scandit 0ca83bd
Merge main into docs/product-chooser
eugenia-scandit 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
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
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
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,125 @@ | ||
| #!/usr/bin/env node | ||
| "use strict"; | ||
| /** | ||
| * Tests for the Product Chooser's links and the alternatives it shows | ||
| * (src/components/ProductChooser/links.ts). | ||
| * | ||
| * The chooser renders nothing until content/registry/product-chooser.yml has | ||
| * an approved entry, so a build does not reach this code yet. These cases pin | ||
| * what it links to: the doc paths the docs plugin publishes carry the base | ||
| * URL, and a preview build serves the site under /data-capture-documentation/ | ||
| * pr-preview/pr-N/, so the prefix cut from the pathname must line up with them. | ||
| * | ||
| * Transpiles the TypeScript source with the repo's own `typescript`, so it | ||
| * runs on the Node version CI uses, which cannot load .ts files. | ||
| * | ||
| * Usage: node scripts/test-product-chooser.cjs | ||
| */ | ||
|
|
||
| const assert = require("assert"); | ||
| const path = require("path"); | ||
| const fs = require("fs"); | ||
| const { createRequire } = require("module"); | ||
| const ts = require("typescript"); | ||
|
|
||
| function loadTs(file) { | ||
| const { outputText } = ts.transpileModule(fs.readFileSync(file, "utf8"), { | ||
| compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2019 }, | ||
| fileName: file, | ||
| }); | ||
| const mod = { exports: {} }; | ||
| // `require` relative to the loaded file, not to this script. | ||
| new Function("module", "exports", "require", outputText)(mod, mod.exports, createRequire(file)); | ||
| return mod.exports; | ||
| } | ||
|
|
||
| let passed = 0; | ||
| function test(name, fn) { | ||
| try { | ||
| fn(); | ||
| passed++; | ||
| } catch (e) { | ||
| console.error(`✗ ${name}\n ${e.message}`); | ||
| process.exitCode = 1; | ||
| } | ||
| } | ||
|
|
||
| const { docsPrefix, overviewUrl, visibleAlternatives } = loadTs(path.join(__dirname, "../src/components/ProductChooser/links.ts")); | ||
|
|
||
| const PREVIEW = "/data-capture-documentation/pr-preview/pr-1"; | ||
| // Doc paths as the docs plugin publishes them, base URL included. Some with a | ||
| // trailing slash and some without, as both occur. | ||
| const docs = (base) => | ||
| [ | ||
| "/sdks/ios/sparkscan/intro/", | ||
| "/sdks/ios/matrixscan/intro", | ||
| "/sdks/ios/barcode-capture/get-started/", | ||
| "/sdks/ios/barcode-generator/", | ||
| "/sdks/kmp/matrixscan/intro/", | ||
| "/sdks/net/ios/matrixscan/intro/", | ||
| "/hosted/express/overview/", | ||
| ].map((p) => ({ path: `${base}${p}` })); | ||
| const sdk = (folder) => ({ kind: "sdk", folder }); | ||
| const hosted = (folder) => ({ kind: "hosted", folder }); | ||
|
|
||
| test("docsPrefix is everything before /sdks/", () => { | ||
| assert.strictEqual(docsPrefix("/sdks/ios/sparkscan/intro/"), ""); | ||
| assert.strictEqual(docsPrefix(`${PREVIEW}/sdks/ios/sparkscan/intro/`), PREVIEW); | ||
| assert.strictEqual(docsPrefix("/next/sdks/ios/sparkscan/intro/"), "/next"); | ||
| assert.strictEqual(docsPrefix("/hosted/express/overview/"), ""); | ||
| }); | ||
|
|
||
| for (const [label, base] of [["at the site root", ""], ["on a preview build", PREVIEW]]) { | ||
| const prefix = docsPrefix(`${base}/sdks/ios/sparkscan/intro/`); | ||
| test(`${label}: links to an intro, with or without a trailing slash`, () => { | ||
| assert.strictEqual(overviewUrl(docs(base), prefix, "ios", sdk("sparkscan")), `${base}/sdks/ios/sparkscan/intro/`); | ||
| assert.strictEqual(overviewUrl(docs(base), prefix, "ios", sdk("matrixscan")), `${base}/sdks/ios/matrixscan/intro/`); | ||
| }); | ||
| test(`${label}: falls back to get-started, then to a flat page`, () => { | ||
| assert.strictEqual( | ||
| overviewUrl(docs(base), prefix, "ios", sdk("barcode-capture")), | ||
| `${base}/sdks/ios/barcode-capture/get-started/`, | ||
| ); | ||
| assert.strictEqual( | ||
| overviewUrl(docs(base), prefix, "ios", sdk("barcode-generator")), | ||
| `${base}/sdks/ios/barcode-generator/`, | ||
| ); | ||
| }); | ||
| test(`${label}: no page on this framework gives null`, () => { | ||
| assert.strictEqual(overviewUrl(docs(base), prefix, "android", sdk("sparkscan")), null); | ||
| assert.strictEqual(overviewUrl(docs(base), prefix, "ios", sdk("smart-label-capture")), null); | ||
| }); | ||
| test(`${label}: a hosted product links to its one overview`, () => { | ||
| assert.strictEqual(overviewUrl(docs(base), prefix, "ios", hosted("express")), `${base}/hosted/express/overview/`); | ||
| assert.strictEqual(overviewUrl(docs(base), prefix, "ios", hosted("id-bolt")), null); | ||
| }); | ||
| test(`${label}: uses the route segment, not the slug`, () => { | ||
| assert.strictEqual(overviewUrl(docs(base), prefix, "kmp", sdk("matrixscan")), `${base}/sdks/kmp/matrixscan/intro/`); | ||
| assert.strictEqual( | ||
| overviewUrl(docs(base), prefix, "net/ios", sdk("matrixscan")), | ||
| `${base}/sdks/net/ios/matrixscan/intro/`, | ||
| ); | ||
| assert.strictEqual(overviewUrl(docs(base), prefix, "net-ios", sdk("matrixscan")), null); | ||
| }); | ||
| } | ||
|
|
||
| const notFor = [ | ||
| { when: "count many", use: "matrixscan-count" }, | ||
| { when: "hosted flow", use: "express" }, | ||
| ]; | ||
| test("shows only the alternatives available on the framework, in order", () => { | ||
| const onWeb = (key) => key !== "matrixscan-count"; | ||
| assert.deepStrictEqual(visibleAlternatives(notFor, onWeb), [notFor[1]]); | ||
| assert.deepStrictEqual(visibleAlternatives(notFor, () => true), notFor); | ||
| }); | ||
| test("no available alternative leaves an empty list (one column)", () => { | ||
| assert.deepStrictEqual(visibleAlternatives(notFor, () => false), []); | ||
| assert.deepStrictEqual(visibleAlternatives([], () => true), []); | ||
| }); | ||
| test("asks about each alternative's product key", () => { | ||
| const asked = []; | ||
| visibleAlternatives(notFor, (key) => (asked.push(key), true)); | ||
| assert.deepStrictEqual(asked, ["matrixscan-count", "express"]); | ||
| }); | ||
|
|
||
| console.log(`test-product-chooser: ${passed} passed${process.exitCode ? ", some FAILED" : ""}`); |
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.