|
| 1 | +import { expect, test } from "vitest"; |
| 2 | +import { buildTopicListQuery, shouldIncludeInternalTabsInTopicList } from "../src/routes/topic"; |
| 3 | + |
| 4 | +test("public all topic list excludes internal tabs for admins too", () => { |
| 5 | + expect(shouldIncludeInternalTabsInTopicList(undefined, true)).toBe(false); |
| 6 | + expect(shouldIncludeInternalTabsInTopicList("all", true)).toBe(false); |
| 7 | + expect(shouldIncludeInternalTabsInTopicList("share", true)).toBe(false); |
| 8 | +}); |
| 9 | + |
| 10 | +test("internal tabs are only available when explicitly selected by admins", () => { |
| 11 | + expect(shouldIncludeInternalTabsInTopicList("dev", true)).toBe(true); |
| 12 | + expect(shouldIncludeInternalTabsInTopicList("test", true)).toBe(true); |
| 13 | + expect(shouldIncludeInternalTabsInTopicList("dev", false)).toBe(false); |
| 14 | +}); |
| 15 | + |
| 16 | +test("topic list query keeps all and normal tab filters outside internal tabs", () => { |
| 17 | + expect(buildTopicListQuery(undefined, false)).toMatchObject({ excludeTabs: ["job"], publicVisible: true, includeInternalTabs: false }); |
| 18 | + expect(buildTopicListQuery("all", true)).toMatchObject({ excludeTabs: ["job"], publicVisible: true, includeInternalTabs: false }); |
| 19 | + expect(buildTopicListQuery("share", true)).toMatchObject({ tab: "share", publicVisible: true, includeInternalTabs: false }); |
| 20 | + expect(buildTopicListQuery("ask", false)).toMatchObject({ tab: "ask", publicVisible: true, includeInternalTabs: false }); |
| 21 | + expect(buildTopicListQuery("good", true)).toMatchObject({ good: 1, publicVisible: true, includeInternalTabs: false }); |
| 22 | +}); |
| 23 | + |
| 24 | +test("topic list query only allows explicit internal tabs for admins", () => { |
| 25 | + expect(buildTopicListQuery("dev", false)).toBeNull(); |
| 26 | + expect(buildTopicListQuery("test", false)).toBeNull(); |
| 27 | + expect(buildTopicListQuery("dev", true)).toMatchObject({ tab: "dev", publicVisible: true, includeInternalTabs: true }); |
| 28 | + expect(buildTopicListQuery("test", true)).toMatchObject({ tab: "test", publicVisible: true, includeInternalTabs: true }); |
| 29 | +}); |
0 commit comments