-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tasks): add tests to TasksEnabledProvider
- Loading branch information
1 parent
e840861
commit d040b1c
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
packages/sanity/src/tasks/src/tasks/context/enabled/TasksEnabledProvider.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import {beforeEach, describe, expect, it, jest} from '@jest/globals' | ||
import {renderHook} from '@testing-library/react' | ||
|
||
import {TasksEnabledProvider} from './TasksEnabledProvider' | ||
import {useTasksEnabled} from './useTasksEnabled' | ||
|
||
// Mocks for useFeatureEnabled and useWorkspace hooks | ||
jest.mock('sanity', () => { | ||
return { | ||
useFeatureEnabled: jest.fn(), | ||
useWorkspace: jest.fn(), | ||
} | ||
}) | ||
|
||
describe('TasksEnabledProvider', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should not show tasks if user opt out and the feature is not enabled (any plan)', () => { | ||
require('sanity').useFeatureEnabled.mockReturnValue({enabled: false, isLoading: false}) | ||
require('sanity').useWorkspace.mockReturnValue({tasks: {enabled: false}}) | ||
|
||
const value = renderHook(useTasksEnabled, {wrapper: TasksEnabledProvider}) | ||
|
||
expect(value.result.current).toEqual({enabled: false, mode: null}) | ||
}) | ||
it('should not show tasks if user opt out and the feature is enabled (any plan)', () => { | ||
require('sanity').useFeatureEnabled.mockReturnValue({enabled: true, isLoading: false}) | ||
require('sanity').useWorkspace.mockReturnValue({tasks: {enabled: false}}) | ||
|
||
const value = renderHook(useTasksEnabled, {wrapper: TasksEnabledProvider}) | ||
|
||
expect(value.result.current).toEqual({enabled: false, mode: null}) | ||
}) | ||
|
||
it('should show default mode if user hasnt opted out and the feature is enabled (growth or above)', () => { | ||
require('sanity').useFeatureEnabled.mockReturnValue({enabled: true, isLoading: false}) | ||
require('sanity').useWorkspace.mockReturnValue({tasks: {enabled: true}}) | ||
|
||
const value = renderHook(useTasksEnabled, {wrapper: TasksEnabledProvider}) | ||
|
||
expect(value.result.current).toEqual({enabled: true, mode: 'default'}) | ||
}) | ||
|
||
it('should show upsell mode if user has not opt out and the feature is not enabled (free plans)', () => { | ||
require('sanity').useFeatureEnabled.mockReturnValue({enabled: false, isLoading: false}) | ||
require('sanity').useWorkspace.mockReturnValue({tasks: {enabled: true}}) | ||
|
||
const value = renderHook(useTasksEnabled, {wrapper: TasksEnabledProvider}) | ||
|
||
expect(value.result.current).toEqual({enabled: true, mode: 'upsell'}) | ||
}) | ||
|
||
it('should not show tasks if it is loading the feature', () => { | ||
require('sanity').useFeatureEnabled.mockReturnValue({enabled: false, isLoading: true}) | ||
require('sanity').useWorkspace.mockReturnValue({tasks: {enabled: true}}) | ||
|
||
const value = renderHook(useTasksEnabled, {wrapper: TasksEnabledProvider}) | ||
|
||
expect(value.result.current).toEqual({enabled: false, mode: null}) | ||
}) | ||
}) |