-
-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
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,55 @@ | ||
import { act, fireEvent, render, screen } from '@testing-library/react'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { useUserStore } from '@/store/user'; | ||
|
||
import Avatar from './Avatar'; | ||
|
||
// Mock UserAvatar and UserPanel components | ||
vi.mock('@/features/User/UserAvatar', () => ({ | ||
default: vi.fn(() => <div>Mocked UserAvatar</div>), | ||
})); | ||
|
||
vi.mock('@/features/User/UserPanel', () => ({ | ||
default: vi.fn(({ children }) => <div>Mocked UserPanel {children}</div>), | ||
})); | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe('Avatar', () => { | ||
it('should render UserAvatar and UserPanel when hideSettingsMoveGuide is true', () => { | ||
render(<Avatar />); | ||
|
||
expect(screen.getByText('Mocked UserPanel')).toBeInTheDocument(); | ||
expect(screen.getByText('Mocked UserAvatar')).toBeInTheDocument(); | ||
expect(screen.queryByText('userPanel.moveGuide')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render Tooltip with guide content when hideSettingsMoveGuide is false', () => { | ||
act(() => { | ||
useUserStore.getState().updateGuideState({ moveSettingsToAvatar: false }); | ||
}); | ||
|
||
render(<Avatar />); | ||
|
||
expect(screen.getByText('userPanel.moveGuide')).toBeInTheDocument(); | ||
expect(screen.getByText('Mocked UserPanel')).toBeInTheDocument(); | ||
expect(screen.getByText('Mocked UserAvatar')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call updateGuideState when close icon is clicked in Tooltip', () => { | ||
const updateGuideStateMock = vi.fn(); | ||
act(() => { | ||
useUserStore.getState().updateGuideState({ moveSettingsToAvatar: false }); | ||
useUserStore.setState({ updateGuideState: updateGuideStateMock }); | ||
}); | ||
|
||
render(<Avatar />); | ||
|
||
fireEvent.click(screen.getByRole('close-guide')); | ||
|
||
expect(updateGuideStateMock).toHaveBeenCalledWith({ moveSettingsToAvatar: true }); | ||
}); | ||
}); |
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
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,82 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { UserStore } from '@/store/user'; | ||
|
||
import { initialPreferenceState } from './initialState'; | ||
import { preferenceSelectors } from './selectors'; | ||
|
||
describe('preferenceSelectors', () => { | ||
let store: UserStore; | ||
|
||
beforeEach(() => { | ||
store = { | ||
...initialPreferenceState, | ||
} as unknown as UserStore; | ||
}); | ||
|
||
describe('useCmdEnterToSend', () => { | ||
it('should return the value of useCmdEnterToSend preference', () => { | ||
store.preference.useCmdEnterToSend = true; | ||
expect(preferenceSelectors.useCmdEnterToSend(store)).toBe(true); | ||
|
||
store.preference.useCmdEnterToSend = false; | ||
expect(preferenceSelectors.useCmdEnterToSend(store)).toBe(false); | ||
}); | ||
|
||
it('should return false if useCmdEnterToSend preference is undefined', () => { | ||
store.preference.useCmdEnterToSend = undefined; | ||
expect(preferenceSelectors.useCmdEnterToSend(store)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('userAllowTrace', () => { | ||
it('should return the value of telemetry preference', () => { | ||
store.preference.telemetry = true; | ||
expect(preferenceSelectors.userAllowTrace(store)).toBe(true); | ||
|
||
store.preference.telemetry = false; | ||
expect(preferenceSelectors.userAllowTrace(store)).toBe(false); | ||
|
||
store.preference.telemetry = null; | ||
expect(preferenceSelectors.userAllowTrace(store)).toBe(null); | ||
}); | ||
}); | ||
|
||
describe('hideSyncAlert', () => { | ||
it('should return the value of hideSyncAlert preference', () => { | ||
store.preference.hideSyncAlert = true; | ||
expect(preferenceSelectors.hideSyncAlert(store)).toBe(true); | ||
|
||
store.preference.hideSyncAlert = false; | ||
expect(preferenceSelectors.hideSyncAlert(store)).toBe(false); | ||
|
||
store.preference.hideSyncAlert = undefined; | ||
expect(preferenceSelectors.hideSyncAlert(store)).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('hideSettingsMoveGuide', () => { | ||
it('should return the value of moveSettingsToAvatar guide preference', () => { | ||
store.preference.guide = { moveSettingsToAvatar: true }; | ||
expect(preferenceSelectors.hideSettingsMoveGuide(store)).toBe(true); | ||
|
||
store.preference.guide = { moveSettingsToAvatar: false }; | ||
expect(preferenceSelectors.hideSettingsMoveGuide(store)).toBe(false); | ||
}); | ||
|
||
it('should return undefined if guide preference is undefined', () => { | ||
store.preference.guide = undefined; | ||
expect(preferenceSelectors.hideSettingsMoveGuide(store)).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('isPreferenceInit', () => { | ||
it('should return the value of isPreferenceInit state', () => { | ||
store.isPreferenceInit = true; | ||
expect(preferenceSelectors.isPreferenceInit(store)).toBe(true); | ||
|
||
store.isPreferenceInit = false; | ||
expect(preferenceSelectors.isPreferenceInit(store)).toBe(false); | ||
}); | ||
}); | ||
}); |