| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import { describe, expect, it } from "vitest";
- import {
- getCommunityUrlFromConfig,
- getCommunityUrlFromConfigs,
- getFeedbackUrlFromConfig,
- getForceUpdateMinimalVersionFromConfig,
- } from "../src/remoteAppConfig.js";
- describe("remoteAppConfig", () => {
- it("读取 feedback_url", () => {
- expect(
- getFeedbackUrlFromConfig({
- feedback_url: "https://example.com/feedback",
- }),
- ).toBe("https://example.com/feedback");
- });
- it("中文界面只读取中文社群地址", () => {
- expect(
- getCommunityUrlFromConfig(
- {
- community_urls: {
- "zh-CN": "https://example.com/zh-community",
- "en-US": "https://example.com/en-community",
- },
- },
- "zh-CN",
- ),
- ).toBe("https://example.com/zh-community");
- expect(
- getCommunityUrlFromConfig(
- {
- community_urls: {
- "en-US": "https://example.com/en-community",
- },
- },
- "zh-CN",
- ),
- ).toBeUndefined();
- });
- it("英文界面只读取英文社群地址", () => {
- expect(
- getCommunityUrlFromConfig(
- {
- community_urls: {
- "zh-CN": "https://example.com/zh-community",
- "en-US": "https://example.com/en-community",
- },
- },
- "en-US",
- ),
- ).toBe("https://example.com/en-community");
- expect(
- getCommunityUrlFromConfig(
- {
- community_urls: {
- "zh-CN": "https://example.com/zh-community",
- },
- },
- "en-US",
- ),
- ).toBeUndefined();
- });
- it("两个语言渠道都缺失时返回 undefined", () => {
- expect(getCommunityUrlFromConfig({}, "zh-CN")).toBeUndefined();
- });
- it("远端缺少当前语言时优先使用内置同语言入口", () => {
- expect(
- getCommunityUrlFromConfigs(
- {
- community_urls: {
- "zh-CN": "https://remote.example.com/feishu",
- },
- },
- {
- community_urls: {
- "zh-CN": "https://local.example.com/feishu",
- "en-US": "https://local.example.com/discord",
- },
- },
- "en-US",
- ),
- ).toBe("https://local.example.com/discord");
- });
- it("读取 forceUpdate minimalVersion", () => {
- expect(
- getForceUpdateMinimalVersionFromConfig({
- forceUpdate: {
- minimalVersion: " 4.0.0 ",
- },
- }),
- ).toBe("4.0.0");
- expect(getForceUpdateMinimalVersionFromConfig({})).toBeUndefined();
- expect(
- getForceUpdateMinimalVersionFromConfig({
- forceUpdate: {
- minimalVersion: "",
- },
- }),
- ).toBeUndefined();
- });
- });
|