Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
fa41d0e
refactor: remove the unused media type helper from the swagger 2 parser
ludomikula Nov 22, 2026
173ef45
test: cover the node-service core: encryption, sandbox, controllers, …
ludomikula Nov 22, 2026
0a176f8
test: cover the OpenAPI parser, request builder and the spec-driven w…
ludomikula Nov 22, 2026
0ca2d52
test: cover the storage, AWS and query plugins with mocked clients
ludomikula Nov 22, 2026
0101416
build: collect coverage over src and require 85% lines and branches
ludomikula Nov 22, 2026
17fac78
test: record the runJs host escape and the shared OpenAPI spec leak a…
ludomikula Nov 22, 2026
c519d87
fix: stop OpenAPI runs from writing a server URL into the shared spec…
ludomikula Nov 22, 2026
8677d0b
fix: harden the npm registry proxy against bad input, upstream errors…
ludomikula Nov 22, 2026
1676eb0
fix: cache only successful plugin responses, key them by language, an…
ludomikula Nov 22, 2026
1aaa445
fix: map non-finite numbers to 0 and keep 0 and false in key-value lists
ludomikula Nov 22, 2026
cfe3f11
fix: stop getSchemaExample from recursing forever on circular schemas
ludomikula Nov 22, 2026
a8f6d95
fix: send the uiPath and openAi credentials and call the boomi and hu…
ludomikula Nov 22, 2026
f19d129
fix: accept only hex-pair encrypted bodies and ignore non-cookie cont…
ludomikula Nov 22, 2026
d26b375
fix: report supabase storage errors with the server's message, expire…
ludomikula Nov 22, 2026
6dd9641
fix: keep aliyunOss STS credentials per data source, use the STS endp…
ludomikula Nov 22, 2026
412059c
fix: harden the AWS plugins and reject the AppConfig actions that nev…
ludomikula Nov 22, 2026
75a906d
fix: release duckdb and firebird resources, scan firebird parameters …
ludomikula Nov 23, 2026
e28aade
fix: forward shopify headers and token, correct firestore NaN and int…
ludomikula Nov 23, 2026
1ae895d
test: pin how a saved datasource of the removed fauna plugin loads in…
ludomikula Nov 23, 2026
c29d44d
build(node-service): add isolated-vm 6.2.0 and start node with --no-n…
ludomikula Nov 23, 2026
edd3308
fix(node-service): run /runJs code in an isolated-vm isolate (B43, cl…
ludomikula Nov 23, 2026
36af799
chore(proxy-service): stop tracking the compiled build/ output
ludomikula Nov 25, 2026
40e6511
test(proxy-service): pin HTTP behaviour of the typeform, google-forms…
ludomikula Nov 25, 2026
2daec7c
fix(proxy-service): refuse IPv6 literals of private and loopback addr…
ludomikula Nov 25, 2026
a3857ff
test(agora-token-service): pin the token endpoint and add a lockfile
ludomikula Nov 25, 2026
d1e8f72
test(hocuspocus): add server tests and a version guard for the image …
ludomikula Nov 25, 2026
9b4184c
build(proxy-service): run the standalone image on Node 26.13.1 with t…
ludomikula Nov 25, 2026
ac21da4
build(agora-token-service): run the standalone image on Node 26.13.1 …
ludomikula Nov 25, 2026
5c1a6db
build(hocuspocus): pin the standalone image to node:26.13.1-alpine
ludomikula Nov 25, 2026
fc1d772
ci: run the proxy-service, agora-token-service and hocuspocus tests o…
ludomikula Nov 25, 2026
0946be0
fix(node-service): refresh jwa so Google and Firebase libraries load …
ludomikula Nov 25, 2026
e7aec16
build(docker): compile tree-sitter with C++20 in the node-service bui…
ludomikula Nov 25, 2026
2c7856b
build(node-service): type-check against Node 24 and test on Node 22 a…
ludomikula Nov 25, 2026
46349e6
build(docker): build node-service and run its standalone image on Nod…
ludomikula Nov 25, 2026
d17417f
build(docker): run the all-in-one image's shared Node on 24.22.3
ludomikula Nov 25, 2026
920c5c3
test(hocuspocus): destroy providers when a document fails to sync
ludomikula Nov 25, 2026
e0255e5
build(docker): build the all-in-one proxy, agora and hocuspocus stage…
ludomikula Nov 25, 2026
91ce7c7
ci: stop testing proxy-service, agora-token-service and hocuspocus on…
ludomikula Nov 25, 2026
bf22d3c
build(proxy-service): type-check against Node 24 and require Node 24 …
ludomikula Nov 25, 2026
a06a5a0
build(node-service): move isolated-vm to 7.0.2 and require Node 24 or…
ludomikula Nov 25, 2026
daafcc0
ci(node-service): also test on Node 26
ludomikula Nov 25, 2026
22cc5da
build(docker): build node-service and run its standalone image on Nod…
ludomikula Nov 25, 2026
7ba2093
build(docker): run the all-in-one image's shared Node on 26.13.1
ludomikula Nov 25, 2026
e92aac9
build(docker): build the all-in-one image's proxy, agora and hocuspoc…
ludomikula Nov 25, 2026
94f6985
ci: test proxy-service, agora-token-service and hocuspocus on Node 26…
ludomikula Nov 25, 2026
f98a89e
build(proxy-service): build in a separate stage so the dev dependenci…
ludomikula Nov 25, 2026
a7b0ec8
test(e2e): pin the node-service plugin behaviour the upgrade changed
ludomikula Nov 26, 2026
1c77413
test(e2e): pin that a failed Firebird query detaches its attachment
ludomikula Nov 26, 2026
9a2034d
fix(api-service): publish the bundle recycle event from the stored bu…
ludomikula Nov 26, 2026
5c0d77a
fix(client): keep a dropped component's width while the canvas is unm…
ludomikula Nov 26, 2026
0148108
fix(client): draw an image value at once after an icon name
ludomikula Nov 26, 2026
eebee02
test(client): name the icon stand-in as a hook
ludomikula Nov 26, 2026
d3d0423
test(e2e): take the bundle recycle, drop width and icon switch out of…
ludomikula Nov 26, 2026
3306d8a
test(e2e): pin the join through a workspace's sign-in and sign-up pag…
ludomikula Nov 26, 2026
6b3eedc
test(e2e): pin the creator's permanent right to its app, bundle and f…
ludomikula Nov 26, 2026
bb8bac7
fix(api-service): answer the anonymous workspace lookup with id and n…
ludomikula Nov 26, 2026
69c8b97
fix(api-service): name both bundles in the event of an app moved betw…
ludomikula Nov 27, 2026
5f7cb50
test(e2e): pin the minimal anonymous workspace lookup and the bundle …
ludomikula Nov 27, 2026
6a8449b
fix(api-service): redeem the invitation before the sign-in joins the …
ludomikula Nov 27, 2026
829c654
test(e2e): pin that a sign-up or sign-in through an invitation succee…
ludomikula Nov 27, 2026
065d918
test(hocuspocus): use bridge rooms in the server tests and the helm r…
ludomikula Nov 27, 2026
90834bd
fix(node-service): write the unpacked tarball under a name of the ser…
ludomikula Nov 27, 2026
308c426
chore(sonar): leave tests and test infrastructure out of the analysis
ludomikula Nov 27, 2026
0817493
test(hocuspocus): wait for the rejection log lines instead of countin…
ludomikula Nov 27, 2026
7a2a4b1
ci: install the test packages without running dependency lifecycle sc…
ludomikula Nov 27, 2026
7fe96f2
build(proxy-service): install without dependency lifecycle scripts an…
ludomikula Nov 27, 2026
5c0c4f4
build(docker): install the proxy-service and agora-token-service buil…
ludomikula Nov 27, 2026
8507142
fix(api-service): keep request values on one log line and stop loggin…
ludomikula Nov 27, 2026
6c1faf2
fix(api-service): answer a page number below 1 as the page-number err…
ludomikula Nov 27, 2026
d77ddad
chore(api-service): remove unused locals, fix a javadoc parameter and…
ludomikula Nov 27, 2026
0f37fda
refactor(api-service): replace calls of deprecated library methods by…
ludomikula Nov 27, 2026
b6ec223
fix(api-service): publish an application addressed by gid or slug cou…
ludomikula Nov 27, 2026
20fd707
fix(api-service): the bundle lists show the bundles of the current wo…
ludomikula Nov 27, 2026
ad5e4ea
fix(api-service): a restart without a configured super-admin password…
ludomikula Nov 27, 2026
ad90ef2
test(api-service): print the arguments of a failed Google Sheets resu…
ludomikula Nov 27, 2026
baa892e
fix(api-service): keep the refusal message key of setPasswordIfAbsent…
ludomikula Nov 27, 2026
a62c1c9
fix(node-service): keep every unpack path inside the package cache an…
ludomikula Nov 27, 2026
bc0d535
fix(node-service): the cache-hit check of a package also stays inside…
ludomikula Nov 27, 2026
dae2cf4
ci: run the tests with coverage in the SonarCloud build and hand the …
ludomikula Nov 27, 2026
2d8b71f
fix(redis-plugin): a lone double quote in a raw command is an argumen…
ludomikula Nov 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/agora-token-service-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: agora-token-service tests
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'deploy/docker/agora-token-service/**'
- '.github/workflows/agora-token-service-tests.yml'
permissions:
contents: read
jobs:
test:
name: Test (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [26.x]
defaults:
run:
shell: bash
working-directory: deploy/docker/agora-token-service
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: deploy/docker/agora-token-service/package-lock.json
- name: Install
run: npm ci --ignore-scripts
- name: Test
env:
NODE_OPTIONS: --test-reporter=tap
run: |
set -o pipefail
node -v
npm test 2>&1 | tee "$RUNNER_TEMP/node-test.tap"
- name: Check the test summary
env:
MIN_PASS: 14
TODO: 1
REQUIRED_TITLES: |
token: publisher uid token has channel, uid, expiry and privileges
token: signature verifies with the certificate and fails with another
token: subscriber userAccount token defaults to 3600 s and privilege 1
errors: short path, unknown path and POST are 404
run: |
log="$RUNNER_TEMP/node-test.tap"
grep -qx 'TAP version 13' "$log" || { echo "::error::$log is not TAP output"; exit 1; }
read -r pass fail cancelled skipped todo < <(awk '/^# (pass|fail|cancelled|skipped|todo) [0-9]+$/ { v[$2] = $3 } END { printf "%s %s %s %s %s\n", v["pass"] == "" ? -1 : v["pass"], v["fail"] == "" ? -1 : v["fail"], v["cancelled"] == "" ? -1 : v["cancelled"], v["skipped"] == "" ? -1 : v["skipped"], v["todo"] == "" ? -1 : v["todo"] }' "$log")
echo "pass $pass, fail $fail, cancelled $cancelled, skipped $skipped, todo $todo"
grep -E '^ *(not )?ok [0-9]+ - .* # TODO' "$log" || echo "no todo tests"
[ "$fail" = 0 ] && [ "$cancelled" = 0 ] && [ "$skipped" = 0 ] && [ "$todo" = "$TODO" ] && [ "$pass" -ge "$MIN_PASS" ] \
|| { echo "::error::expected fail 0, cancelled 0, skipped 0, todo $TODO, pass >= $MIN_PASS"; exit 1; }
n=0
while IFS= read -r t; do
[ -n "$t" ] || continue
awk -v t="$t" '{ l = $0 } sub(/^ *ok [0-9]+ - /, "", l) && l == t { f = 1 } END { exit !f }' "$log" || { echo "::error::no passing test titled: $t"; exit 1; }
n=$((n + 1))
done <<< "$REQUIRED_TITLES"
[ "$n" -gt 0 ] || { echo "::error::REQUIRED_TITLES is empty"; exit 1; }
echo "$n required titles passed"
1 change: 1 addition & 0 deletions .github/workflows/agora-token-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'deploy/docker/agora-token-service/**'
- '.github/workflows/agora-token-service.yml'
- '.github/workflows/build-service-image.yml'
- '!deploy/docker/agora-token-service/test/**'

permissions:
contents: read
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/hocuspocus-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: hocuspocus tests
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'client/packages/lowcoder/hocuspocus-server.js'
- 'deploy/docker/hocuspocus/**'
- 'deploy/docker/Dockerfile'
- 'deploy/helm/tests/runtime/hocuspocus-sync.mjs'
- 'deploy/helm/tests/runtime-test.sh'
- 'client/yarn.lock'
- 'server/proxy-service/yarn.lock'
- '.github/workflows/hocuspocus-tests.yml'
permissions:
contents: read
jobs:
test:
name: Test (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [26.x]
defaults:
run:
shell: bash
working-directory: deploy/docker/hocuspocus/test
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: deploy/docker/hocuspocus/test/package-lock.json
- name: Install
run: npm ci --ignore-scripts
- name: Test
env:
NODE_OPTIONS: --test-reporter=tap
run: |
set -o pipefail
node -v
npm test 2>&1 | tee "$RUNNER_TEMP/node-test.tap"
- name: Check the test summary
env:
MIN_PASS: 11
TODO: 1
REQUIRED_TITLES: |
health: GET /health reports ok and the auth state
secret: sync with the secret
secret: wrong and empty tokens are refused with permission-denied
versions: @hocuspocus/server matches both Dockerfile ARGs
start: a second server on the same port exits non-zero
run: |
log="$RUNNER_TEMP/node-test.tap"
grep -qx 'TAP version 13' "$log" || { echo "::error::$log is not TAP output"; exit 1; }
read -r pass fail cancelled skipped todo < <(awk '/^# (pass|fail|cancelled|skipped|todo) [0-9]+$/ { v[$2] = $3 } END { printf "%s %s %s %s %s\n", v["pass"] == "" ? -1 : v["pass"], v["fail"] == "" ? -1 : v["fail"], v["cancelled"] == "" ? -1 : v["cancelled"], v["skipped"] == "" ? -1 : v["skipped"], v["todo"] == "" ? -1 : v["todo"] }' "$log")
echo "pass $pass, fail $fail, cancelled $cancelled, skipped $skipped, todo $todo"
grep -E '^ *(not )?ok [0-9]+ - .* # TODO' "$log" || echo "no todo tests"
[ "$fail" = 0 ] && [ "$cancelled" = 0 ] && [ "$skipped" = 0 ] && [ "$todo" = "$TODO" ] && [ "$pass" -ge "$MIN_PASS" ] \
|| { echo "::error::expected fail 0, cancelled 0, skipped 0, todo $TODO, pass >= $MIN_PASS"; exit 1; }
n=0
while IFS= read -r t; do
[ -n "$t" ] || continue
awk -v t="$t" '{ l = $0 } sub(/^ *ok [0-9]+ - /, "", l) && l == t { f = 1 } END { exit !f }' "$log" || { echo "::error::no passing test titled: $t"; exit 1; }
n=$((n + 1))
done <<< "$REQUIRED_TITLES"
[ "$n" -gt 0 ] || { echo "::error::REQUIRED_TITLES is empty"; exit 1; }
echo "$n required titles passed"
1 change: 1 addition & 0 deletions .github/workflows/hocuspocus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'deploy/docker/hocuspocus/**'
- '.github/workflows/hocuspocus.yml'
- '.github/workflows/build-service-image.yml'
- '!deploy/docker/hocuspocus/test/**'

permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/node-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 22.x ]
node-version: [ 24.x, 26.x ]
steps:
- uses: actions/checkout@v3
with:
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/proxy-service-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: proxy-service tests
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'server/proxy-service/**'
- '.github/workflows/proxy-service-tests.yml'
permissions:
contents: read
jobs:
test:
name: Test (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [26.x]
defaults:
run:
shell: bash
working-directory: server/proxy-service
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Ensure Yarn 1.22.22
run: |
if [ "$(yarn --version 2>/dev/null)" = 1.22.22 ]; then echo "yarn 1.22.22 already on PATH"; else echo "yarn on PATH: $(yarn --version 2>/dev/null || echo none); installing 1.22.22"; npm install -g --ignore-scripts yarn@1.22.22; fi
[ "$(yarn --version)" = 1.22.22 ] || { echo "::error::yarn $(yarn --version), expected 1.22.22"; exit 1; }
- name: Install
run: yarn install --frozen-lockfile --ignore-scripts
- name: Test
env:
NODE_OPTIONS: --test-reporter=tap
run: |
set -o pipefail
node -v
yarn test 2>&1 | tee "$RUNNER_TEMP/node-test.tap"
- name: Check the test summary
env:
MIN_PASS: 58
TODO: 0
REQUIRED_TITLES: |
auth: secret rejects a token of another scope
google: published responder URL is accepted and cleaned
website session: public https URL gives 200 and a proxied URL
typeform route: upstream headers are rewritten
google-forms route: http target with a session token is 502
website route: loopback target with a session token is 400
run: |
log="$RUNNER_TEMP/node-test.tap"
grep -qx 'TAP version 13' "$log" || { echo "::error::$log is not TAP output"; exit 1; }
read -r pass fail cancelled skipped todo < <(awk '/^# (pass|fail|cancelled|skipped|todo) [0-9]+$/ { v[$2] = $3 } END { printf "%s %s %s %s %s\n", v["pass"] == "" ? -1 : v["pass"], v["fail"] == "" ? -1 : v["fail"], v["cancelled"] == "" ? -1 : v["cancelled"], v["skipped"] == "" ? -1 : v["skipped"], v["todo"] == "" ? -1 : v["todo"] }' "$log")
echo "pass $pass, fail $fail, cancelled $cancelled, skipped $skipped, todo $todo"
grep -E '^ *(not )?ok [0-9]+ - .* # TODO' "$log" || echo "no todo tests"
[ "$fail" = 0 ] && [ "$cancelled" = 0 ] && [ "$skipped" = 0 ] && [ "$todo" = "$TODO" ] && [ "$pass" -ge "$MIN_PASS" ] \
|| { echo "::error::expected fail 0, cancelled 0, skipped 0, todo $TODO, pass >= $MIN_PASS"; exit 1; }
n=0
while IFS= read -r t; do
[ -n "$t" ] || continue
awk -v t="$t" '{ l = $0 } sub(/^ *ok [0-9]+ - /, "", l) && l == t { f = 1 } END { exit !f }' "$log" || { echo "::error::no passing test titled: $t"; exit 1; }
n=$((n + 1))
done <<< "$REQUIRED_TITLES"
[ "$n" -gt 0 ] || { echo "::error::REQUIRED_TITLES is empty"; exit 1; }
echo "$n required titles passed"
13 changes: 10 additions & 3 deletions .github/workflows/sonarcloud-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ jobs:

- name: Build Java
run: |
# Downstream modules need the SDK's shared test-helper JAR, which is
# attached during package. Keep test compilation enabled for that JAR.
mvn --batch-mode --no-transfer-progress clean package -DskipTests -f ./server/api-service/pom.xml
# verify, not package: it runs the unit and integration tests under JaCoCo (the
# integration tests start Mongo and Redis containers through Docker, which the
# runner provides), writes the aggregate coverage report that Sonar reads, and runs
# the coverage gate of lowcoder-coverage-report, which fails the build when a module
# falls below its floor. The SDK's shared test-helper JAR is attached on the way.
mvn --batch-mode --no-transfer-progress clean verify -f ./server/api-service/pom.xml

- name: Package binaries and metadata
env:
Expand All @@ -59,6 +62,10 @@ jobs:
IFS=',' read -r -a dirs <<< "$binaries"
# tar fails if a listed directory is missing.
tar --create --file "$out/sonar-binaries.tar" -- "${dirs[@]}"
# The aggregate JaCoCo report of every module; the scan job hands it to Sonar as data.
report=server/api-service/lowcoder-coverage-report/target/site/jacoco-aggregate/jacoco.xml
[ -f "$report" ] || { echo "$report not found" >&2; exit 1; }
cp -- "$report" "$out/jacoco.xml"
jq -n \
--arg event "$EVENT_NAME" \
--arg pr_number "$PR_NUMBER" \
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name: Sonarcloud
# TRUSTED half of the SonarCloud analysis; the only place SONAR_TOKEN is used.
# It runs from the default branch via workflow_run and never executes PR code: the PR
# tree is checked out as data and the artifact from "Sonarcloud Build" is validated
# before use. Not covered: the scanner still parses untrusted sources and class files.
# before use. Not covered: the scanner still parses untrusted sources, class files and the
# JaCoCo coverage report (jacoco.xml) from that artifact.
on:
workflow_run: # zizmor: ignore[dangerous-triggers] artifact and PR tree are handled as data only
workflows: ["Sonarcloud Build"]
Expand Down Expand Up @@ -91,4 +92,5 @@ jobs:
-Dsonar.organization=lowcoder
-Dsonar.projectKey=lowcoder-org_lowcoder
-Dsonar.working.directory=${{ runner.temp }}/scannerwork
-Dsonar.coverage.jacoco.xmlReportPaths=${{ runner.temp }}/sonar-artifact/jacoco.xml
${{ steps.target.outputs.scanner_args }}
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"required": true
},
"LOWCODER_SUPERUSER_PASSWORD": {
"description": "Password of the Super-User, if not present or empty, it will be generated",
"description": "Password of the Super-User. When set, it replaces the stored password at every start. When empty, a password is generated only while the account has none (first start) and printed once into the log; later starts keep the stored password",
"value": "`generated and printed into log file",
"required": true
},
Expand Down
110 changes: 110 additions & 0 deletions client/packages/lowcoder/src/comps/controls/iconControl.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { render, screen } from "@testing-library/react";
import { IconDictionary, resetIconDictionary } from "@lowcoder-ee/constants/iconConstants";
import { IconControlView } from "./iconControl";

/**
* `useIcon` of lowcoder-design loads its icon table asynchronously and keeps the icon in state, set in an effect keyed by the
* `/icon:` key of the value (`""` for any other value). The stand-in has the same shape over a fake table, and sets the icon
* synchronously inside the effect, so a rerender settles within `act`. It is a plain function, not `jest.fn`: the shared jest
* config has `resetMocks: true`, which clears `jest.fn` implementations before each test.
*/
jest.mock("lowcoder-design", () => {
const actual = jest.requireActual("lowcoder-design");
const React = jest.requireActual("react");
const FAKE_ICONS: Record<string, { title: string; getView: () => unknown }> = {
"solid/star": { title: "Star", getView: () => React.createElement("span", { "data-testid": "icon-marker" }) },
};
const keyOf = (value?: string) => {
const unquoted = actual.removeQuote(value);
return unquoted.startsWith(actual.iconPrefix) ? unquoted.slice(actual.iconPrefix.length) : "";
};
function useStandInIcon(value?: string) {
const key = keyOf(value);
const [icon, setIcon] = React.useState(undefined);
React.useEffect(() => {
setIcon(FAKE_ICONS[key]);
}, [key]);
return icon;
}
return { ...actual, useIcon: useStandInIcon };
});

const ICON_VALUE = "/icon:solid/star";
const IMAGE_URI = "data:image/png;base64,iVBORw0KGgo=";
const PLAIN_TEXT = "hello";
const QUOTED_EMPTY = '""';
const MARKER = "icon-marker";

function drawnAs(container: HTMLElement) {
const img = container.querySelector("img");
return {
marker: screen.queryByTestId(MARKER) !== null,
imgSrc: img ? img.getAttribute("src") : null,
markup: container.innerHTML,
};
}

function show(label: string, value: string, container: HTMLElement) {
console.log(`[iconControl.test] ${label}: value=${JSON.stringify(value)} -> ${JSON.stringify(drawnAs(container))}`);
}

beforeEach(() => {
resetIconDictionary();
});

describe("IconControlView after the value changes", () => {
it("draws the image of a data URI after an icon name, and caches nothing under the URI", () => {
const { container, rerender } = render(<IconControlView value={ICON_VALUE} />);
show("start", ICON_VALUE, container);
expect(drawnAs(container).marker).toBe(true);

rerender(<IconControlView value={IMAGE_URI} />);
show("after the switch", IMAGE_URI, container);
expect(drawnAs(container).imgSrc).toBe(IMAGE_URI);
expect(drawnAs(container).marker).toBe(false);
expect(IconDictionary[IMAGE_URI]).toBeUndefined();
});

it("draws the icon again when the value goes from an image to an icon name", () => {
const { container, rerender } = render(<IconControlView value={IMAGE_URI} />);
show("start", IMAGE_URI, container);
expect(drawnAs(container).imgSrc).toBe(IMAGE_URI);

rerender(<IconControlView value={ICON_VALUE} />);
show("after the switch", ICON_VALUE, container);
expect(drawnAs(container).marker).toBe(true);
expect(drawnAs(container).imgSrc).toBeNull();
});

it("draws plain text as an image after an icon name, as a page loaded with that text does", () => {
const { container, rerender } = render(<IconControlView value={ICON_VALUE} />);
expect(drawnAs(container).marker).toBe(true);

rerender(<IconControlView value={PLAIN_TEXT} />);
show("after the switch", PLAIN_TEXT, container);
expect(drawnAs(container).imgSrc).toBe(PLAIN_TEXT);
expect(drawnAs(container).marker).toBe(false);
});

it("draws nothing for an empty value after an icon name", () => {
const { container, rerender } = render(<IconControlView value={ICON_VALUE} />);
expect(drawnAs(container).marker).toBe(true);

rerender(<IconControlView value="" />);
show("after the switch", "", container);
expect(drawnAs(container).marker).toBe(false);
expect(drawnAs(container).imgSrc).toBeNull();
});

it("pins the known limit: a quoted empty value keeps the old icon after an icon name, cached under it", () => {
const { container, rerender } = render(<IconControlView value={ICON_VALUE} />);
expect(drawnAs(container).marker).toBe(true);

rerender(<IconControlView value={QUOTED_EMPTY} />);
show("after the switch", QUOTED_EMPTY, container);
// not wanted, only not covered by the fix: a later change of what the quoted empty value draws changes this case on purpose
expect(drawnAs(container).marker).toBe(true);
expect(drawnAs(container).imgSrc).toBeNull();
expect(IconDictionary[QUOTED_EMPTY]).toBeDefined();
});
});
Loading
Loading