Skip to content

Cover the admin settings component's uploads and save guards #7913

Description

@mengw15

Task Summary

AdminSettingsComponent is at 85.84 % with 8 uncovered lines and 8 half-taken branches — the image-upload reader, the "settings not loaded yet" guards on each save action, and a couple of reset paths. All are ordinary conditionals reachable by feeding the component the right state; no infrastructure.

Pure EXTEND of admin-settings.component.spec.ts. Vitest/jsdom; see frontend/TESTING.md and frontend/AGENTS.md.

Behavior to add

AdminSettingsComponent (frontend/src/app/dashboard/component/admin/settings/admin-settings.component.ts, codecov 85.84 % — EXTEND)

  • onFileChange (147–153) — reads the uploaded file via a FileReader and, on load, stores the data URL into logoData when type === "logo" or faviconData when type === "mini_logo". Cover both types, and the typeof e.target?.result === "string" ? … : null guard by firing a load whose result is not a string. Stub FileReader deterministically — a fake whose readAsDataURL fires onload via queueMicrotask — rather than relying on jsdom's real async.
  • saveLogos (170–171) — the if (this.faviconData) branch that pushes an extra updateSetting("favicon", …) request. Cover with and without favicon data set, and assert the set of requests issued.
  • resetTabs (227–232) — if (!this.maxFileSizeMiB || !this.chunkSizeMiB) return 0 and if (!this.maxFileSizeMiB) return this.MIN_PART_SIZE_MiB. Cover each missing-value combination so both guards' true sides are taken.
  • saveDatasetSettings (238–240) and saveCsvSettings (294–296) — both begin with if (!this.settingsLoaded) { message.error("Settings have not loaded; refresh before saving."); return }. Assert the error is shown and no save request is made when settings have not loaded, and that a save proceeds when they have.
  • resetCsvSettings (315) — the error handler notificationService.error("Could not reset result panel settings…"). Flush an error from the settings service and assert it is surfaced.

Determinism notes:

  • Stub adminSettingsService, message, and notificationService; use HttpClientTestingModule or of(...) / throwError(...) and flush synchronously — never a real backend.
  • Stub FileReader as above so the upload test does not depend on real async timing.
  • vi.restoreAllMocks() in afterEach; fixture.destroy() so subscriptions stop.
  • Assert on the request/args passed to the stubbed service and on the message shown, not on rendered DOM geometry.

Task Type

  • Refactor / Cleanup
  • DevOps / Deployment / CI
  • Testing / QA
  • Documentation
  • Performance
  • Other

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions