Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
import { expect, it, describe } from "vitest"
import { i18n } from "~~/test/unit/test-utils/i18n"
import type { License, LicenseVersion } from "#shared/constants/license"
import { getFullLicenseName, getElements } from "#shared/utils/license"
const t = i18n.t
describe("getFullLicenseName", () => {
it.each`
license | licenseVersion | sendI18n | fullName
${"by"} | ${""} | ${false} | ${"CC BY"}
${"by-nc-nd"} | ${"4.0"} | ${false} | ${"CC BY-NC-ND 4.0"}
${"cc0"} | ${""} | ${false} | ${"CC0"}
${"sampling+"} | ${""} | ${false} | ${"CC Sampling+"}
${"nc-sampling+"} | ${""} | ${false} | ${"CC NC-Sampling+"}
${"pdm"} | ${""} | ${false} | ${"PDM"}
${"pdm"} | ${""} | ${true} | ${"Public Domain Mark"}
`(
"returns license name for license $license and version $licenseVersion",
({
license,
licenseVersion,
sendI18n,
fullName,
}: {
license: License
licenseVersion: LicenseVersion
sendI18n: boolean
fullName: string
}) => {
expect(
getFullLicenseName(license, licenseVersion, sendI18n ? t : null)
).toBe(fullName)
}
)
})
describe("getElements", () => {
it.each`
license | icons
${"by"} | ${["cc", "by"]}
${"by-sa"} | ${["cc", "by", "sa"]}
${"by-nd"} | ${["cc", "by", "nd"]}
${"by-nc"} | ${["cc", "by", "nc"]}
${"by-nc-sa"} | ${["cc", "by", "nc", "sa"]}
${"by-nc-nd"} | ${["cc", "by", "nc", "nd"]}
${"nc-sampling+"} | ${["cc", "nc", "sampling-plus"]}
${"sampling+"} | ${["cc", "sampling-plus"]}
${"pdm"} | ${["pd"]}
${"cc0"} | ${["cc", "zero"]}
`(
"returns $icons for $license",
({ license, icons }: { license: License; icons: string[] }) => {
expect(getElements(license)).toEqual(icons)
}
)
})