test: cover post-merge gaps in utils, services, and hooks
All checks were successful
CI / verify (push) Successful in 59s
All checks were successful
CI / verify (push) Successful in 59s
Adds specs for the files added or modified in the recent merge that
weren't yet covered: oauthReturnPath, withATProtoImages, link,
displayLanguage, and the useGitHubContent / useImageUpload /
useNoteFreshness hooks. Locks in the new pullLatest contract
({raw, failureStatus}) and the fetchLatestSha branch semantics
(ok/unauthorized/offline).
This commit is contained in:
38
src/utils/displayLanguage.spec.ts
Normal file
38
src/utils/displayLanguage.spec.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest"
|
||||
|
||||
import { displayLanguage } from "./displayLanguage"
|
||||
|
||||
describe("displayLanguage", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it("returns null when no language code is given", () => {
|
||||
expect(displayLanguage()).toBeNull()
|
||||
expect(displayLanguage("")).toBeNull()
|
||||
})
|
||||
|
||||
it("returns a human-readable name for a known language code", () => {
|
||||
expect(displayLanguage("en")).toMatch(/^English/i)
|
||||
})
|
||||
|
||||
it("works for French", () => {
|
||||
expect(displayLanguage("fr")).toBeTruthy()
|
||||
})
|
||||
|
||||
it("returns null and logs a warning when Intl.DisplayNames throws", () => {
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => {})
|
||||
const original = Intl.DisplayNames
|
||||
// Force the constructor to throw
|
||||
;(Intl as unknown as { DisplayNames: unknown }).DisplayNames = function () {
|
||||
throw new Error("boom")
|
||||
}
|
||||
|
||||
try {
|
||||
expect(displayLanguage("en")).toBeNull()
|
||||
expect(warn).toHaveBeenCalled()
|
||||
} finally {
|
||||
;(Intl as unknown as { DisplayNames: unknown }).DisplayNames = original
|
||||
}
|
||||
})
|
||||
})
|
||||
33
src/utils/link.spec.ts
Normal file
33
src/utils/link.spec.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import { isExternalLink } from "./link"
|
||||
|
||||
describe("isExternalLink", () => {
|
||||
const ORIGIN = window.location.origin
|
||||
|
||||
it("returns false for same-origin absolute URLs", () => {
|
||||
expect(isExternalLink(`${ORIGIN}/alice/notes`)).toBe(false)
|
||||
})
|
||||
|
||||
it("returns true for an https URL on a different origin", () => {
|
||||
expect(isExternalLink("https://github.com/anywhere")).toBe(true)
|
||||
})
|
||||
|
||||
it("returns true for an http URL on a different origin", () => {
|
||||
expect(isExternalLink("http://example.com")).toBe(true)
|
||||
})
|
||||
|
||||
it("returns false for relative paths (no http/https prefix)", () => {
|
||||
expect(isExternalLink("/alice/notes")).toBe(false)
|
||||
expect(isExternalLink("./neighbor.md")).toBe(false)
|
||||
})
|
||||
|
||||
it("returns false for mailto and other non-http schemes", () => {
|
||||
expect(isExternalLink("mailto:user@example.com")).toBe(false)
|
||||
expect(isExternalLink("ftp://files.example.com")).toBe(false)
|
||||
})
|
||||
|
||||
it("returns false for an https URL that happens to start with the origin", () => {
|
||||
expect(isExternalLink(`${ORIGIN}/deep/path`)).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user