-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for two terms history recording
- Loading branch information
Dayana Ilieva
committed
Apr 16, 2024
1 parent
e1e09a7
commit 944610a
Showing
9 changed files
with
122 additions
and
31 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
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
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
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,88 @@ | ||
/* eslint-env jest */ | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { uuidV4 } from '../../src/utils'; | ||
import { localTearDown } from '../helpers'; | ||
import AppBase from '../../src/components/AppBase'; | ||
import renderWithProviders from '../../src/utils/storeMockWrapper'; | ||
import { serverSocket } from '../../__mocks__/socket.io-client'; | ||
import { Events, Roles, chat as getInitialConfig, initialMessage } from '../../src/config'; | ||
import initialState from '../../src/store/initialState'; | ||
|
||
const textProbe = () => ({ 'type': 'text', 'text': faker.lorem.text(), 'sequence': 2 }); | ||
const contentMock = { | ||
text: [textProbe(), textProbe()], | ||
email: [ | ||
textProbe(), | ||
{ 'type': 'email', 'email': faker.lorem.text(), 'sequence': 2 }, | ||
], | ||
payment: [ | ||
textProbe(), | ||
{ 'type': 'payment', 'payment': faker.lorem.text(), 'sequence': 2 }, | ||
], | ||
}; | ||
|
||
const serverData = { | ||
"region": faker.location.country(), | ||
"history": [], | ||
"errors": [], | ||
} | ||
|
||
jest.useFakeTimers(); | ||
|
||
let root; | ||
|
||
describe('Multiple terms are being saved', () => { | ||
const term = 'default' | ||
const href = `https://example.com/?utm_chat=${term}}`; | ||
const search = `?utm_chat=${term}`; | ||
|
||
beforeEach(async () => { | ||
const mockLocation = { | ||
href, | ||
search, | ||
}; | ||
|
||
Object.defineProperty(window, 'location', { | ||
value: mockLocation, | ||
writable: true, | ||
enumerable: true, | ||
}); | ||
serverData.history = []; | ||
serverData.errors = []; | ||
serverData.region = faker.location.country(); | ||
serverData.term = term; | ||
}) | ||
afterEach(localTearDown); | ||
|
||
test('on preloaded state with history to save the old one and create new record', async () => { | ||
const previousTerm = faker.lorem.word(); | ||
// Arrange | ||
act(() => { | ||
root = renderWithProviders( | ||
<div id="chatbot-container"> | ||
<AppBase config={getInitialConfig({ id: uuidV4(), purpose: '', close: { visible: true } })} /> | ||
</div>, | ||
{ ...initialState, chat: { ...initialState.chat, record: { [previousTerm]: { historyIds: [], historyData: {} } } } } | ||
); | ||
}); | ||
|
||
serverData.history = [{ | ||
id: uuidV4(), | ||
role: Roles.assistant, | ||
time: new Date().getTime(), | ||
content: contentMock.text, | ||
}]; | ||
|
||
// Act | ||
act(() => { | ||
serverSocket.emit(Events.chatHistory, serverData); | ||
jest.advanceTimersByTime((initialMessage.length * 1000) * initialMessage.length - 1); | ||
}); | ||
|
||
// Assert | ||
const { chat } = root.store.getState(); | ||
expect(chat.record[previousTerm].historyIds).toBeDefined(); | ||
expect(chat.record[term].historyIds).toBeDefined(); | ||
}); | ||
}); |
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