-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Update test folder structure to mirror src
- Loading branch information
Showing
11 changed files
with
142 additions
and
142 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
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
12 changes: 6 additions & 6 deletions
12
__tests__/hooks/useAudioInternal.test.ts → ..._/hooks/internal/useAudioInternal.test.ts
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
18 changes: 9 additions & 9 deletions
18
...ts__/hooks/useChatHistoryInternal.test.ts → ...s/internal/useChatHistoryInternal.test.ts
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
12 changes: 6 additions & 6 deletions
12
...sts__/hooks/useChatWindowInternal.test.ts → ...ks/internal/useChatWindowInternal.test.ts
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
74 changes: 74 additions & 0 deletions
74
__tests__/hooks/internal/useFirstInteractionInternal.test.ts
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,74 @@ | ||
import { renderHook, act } from "@testing-library/react"; | ||
import { expect } from "@jest/globals"; | ||
|
||
import { useFirstInteractionInternal } from "../../../src/hooks/internal/useFirstInteractionInternal"; | ||
|
||
jest.mock("../../../src/context/BotStatesContext", () => ({ | ||
useBotStatesContext: jest.fn(() => ({ | ||
hasInteractedPage: false, | ||
setHasInteractedPage: jest.fn(), | ||
hasFlowStarted: false, | ||
setHasFlowStarted: jest.fn(), | ||
})), | ||
})); | ||
|
||
jest.mock("../../../src/context/SettingsContext", () => ({ | ||
useSettingsContext: jest.fn(() => ({ | ||
settings: { | ||
general: { | ||
flowStartTrigger: "ON_PAGE_INTERACT", | ||
}, | ||
}, | ||
})), | ||
})); | ||
class MockSpeechSynthesisUtterance { | ||
text = ""; | ||
onend: () => void = () => {}; | ||
|
||
constructor() { | ||
setTimeout(() => { | ||
this.onend(); | ||
}, 0); | ||
} | ||
} | ||
|
||
const MockSpeechSynthesis = { | ||
speak: jest.fn().mockImplementation((utterance: MockSpeechSynthesisUtterance) => { | ||
utterance.onend(); | ||
}), | ||
}; | ||
|
||
global.SpeechSynthesisUtterance = MockSpeechSynthesisUtterance as any; | ||
global.speechSynthesis = MockSpeechSynthesis as any; | ||
|
||
describe("useFirstInteractionInternal", () => { | ||
let setHasInteractedPage: jest.Mock; | ||
let setHasFlowStarted: jest.Mock; | ||
|
||
beforeEach(() => { | ||
setHasInteractedPage = jest.fn(); | ||
setHasFlowStarted = jest.fn(); | ||
|
||
(require("../../../src/context/BotStatesContext").useBotStatesContext as jest.Mock).mockReturnValue({ | ||
hasInteractedPage: false, | ||
setHasInteractedPage, | ||
hasFlowStarted: false, | ||
setHasFlowStarted, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should call setHasInteractedPage and setHasFlowStarted on interaction", () => { | ||
const { result } = renderHook(() => useFirstInteractionInternal()); | ||
|
||
act(() => { | ||
result.current.handleFirstInteraction(); | ||
}); | ||
|
||
expect(setHasInteractedPage).toHaveBeenCalledWith(true); | ||
expect(setHasFlowStarted).toHaveBeenCalledWith(true); | ||
}); | ||
}); |
12 changes: 6 additions & 6 deletions
12
...__/hooks/useNotificationsInternal.test.ts → ...internal/useNotificationsInternal.test.ts
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
16 changes: 8 additions & 8 deletions
16
__tests__/hooks/useVoiceInternal.test.ts → ..._/hooks/internal/useVoiceInternal.test.ts
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,27 @@ | ||
import { renderHook } from "@testing-library/react"; | ||
import { expect } from "@jest/globals"; | ||
|
||
import { useBotIdInternal } from "../../../src/hooks/internal/useBotIdInternal"; | ||
import { useBotRefsContext } from "../../../src/context/BotRefsContext"; | ||
|
||
// Mock the useBotRefsContext | ||
jest.mock("../../../src/context/BotRefsContext"); | ||
|
||
// Cast the mock to allow TypeScript to recognize jest mock methods | ||
const mockedUseBotRefsContext = useBotRefsContext as jest.Mock; | ||
|
||
describe("useBotIdInternal", () => { | ||
it("should return the correct botId", () => { | ||
// Mock botIdRef | ||
const botIdRef = { current: "test-bot-id" }; | ||
|
||
// Mock implementation of useBotRefsContext | ||
mockedUseBotRefsContext.mockReturnValue({ botIdRef }); | ||
|
||
// Render the hook | ||
const { result } = renderHook(() => useBotIdInternal()); | ||
|
||
// Call the getBotId method and assert the returned value | ||
expect(result.current.getBotId()).toBe("test-bot-id"); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.