Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/composables/useFeatureFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ServerFeatureFlag,
useFeatureFlags
} from '@/composables/useFeatureFlags'
import * as distributionTypes from '@/platform/distribution/types'
import { api } from '@/scripts/api'

// Mock the API module
Expand All @@ -14,6 +15,12 @@ vi.mock('@/scripts/api', () => ({
}
}))

// Mock the distribution types module
vi.mock('@/platform/distribution/types', () => ({
isCloud: false,
isNightly: false
}))

describe('useFeatureFlags', () => {
beforeEach(() => {
vi.clearAllMocks()
Expand Down Expand Up @@ -131,4 +138,41 @@ describe('useFeatureFlags', () => {
expect(maxUploadSize.value).toBe(104857600)
})
})

describe('linearToggleEnabled', () => {
it('should return true when isNightly is true', () => {
vi.mocked(distributionTypes).isNightly = true

const { flags } = useFeatureFlags()
expect(flags.linearToggleEnabled).toBe(true)
expect(api.getServerFeature).not.toHaveBeenCalled()
})

it('should check remote config and server feature when isNightly is false', () => {
vi.mocked(distributionTypes).isNightly = false
vi.mocked(api.getServerFeature).mockImplementation(
(path, defaultValue) => {
if (path === ServerFeatureFlag.LINEAR_TOGGLE_ENABLED) return true
return defaultValue
}
)

const { flags } = useFeatureFlags()
expect(flags.linearToggleEnabled).toBe(true)
expect(api.getServerFeature).toHaveBeenCalledWith(
ServerFeatureFlag.LINEAR_TOGGLE_ENABLED,
false
)
})

it('should return false when isNightly is false and flag is disabled', () => {
vi.mocked(distributionTypes).isNightly = false
vi.mocked(api.getServerFeature).mockImplementation(
(_path, defaultValue) => defaultValue
)

const { flags } = useFeatureFlags()
expect(flags.linearToggleEnabled).toBe(false)
})
})
})
4 changes: 3 additions & 1 deletion src/composables/useFeatureFlags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { computed, reactive, readonly } from 'vue'

import { isCloud } from '@/platform/distribution/types'
import { isCloud, isNightly } from '@/platform/distribution/types'
import {
isAuthenticatedConfigLoaded,
remoteConfig
Expand Down Expand Up @@ -84,6 +84,8 @@ export function useFeatureFlags() {
)
},
get linearToggleEnabled() {
if (isNightly) return true

return (
remoteConfig.value.linear_toggle_enabled ??
api.getServerFeature(ServerFeatureFlag.LINEAR_TOGGLE_ENABLED, false)
Expand Down