-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Cognigy/messages-collation
Messages collation
- Loading branch information
Showing
12 changed files
with
162 additions
and
39 deletions.
There are no files selected for viewing
File renamed without changes.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,106 @@ | ||
import { render } from "@testing-library/react"; | ||
import { it, describe, expect } from "vitest"; | ||
import Message from "../src/messages/Message"; | ||
import { IMessage } from "@cognigy/socket-client"; | ||
|
||
describe("Collation", () => { | ||
it("collates if timestamp is in limit", () => { | ||
const message1: IMessage = { | ||
text: "Hello", | ||
source: "bot", | ||
timestamp: String(Date.now() - 1000 * 50), | ||
}; | ||
const message2: IMessage = { | ||
text: "World", | ||
source: "bot", | ||
timestamp: String(Date.now()), | ||
}; | ||
|
||
const { getAllByTestId } = render( | ||
<> | ||
<Message message={message1} /> | ||
<Message message={message2} prevMessage={message1} /> | ||
</>, | ||
); | ||
|
||
const messageHeaders = getAllByTestId("message-header"); | ||
expect(messageHeaders).toHaveLength(1); | ||
}); | ||
|
||
it("does NOT collate if timestamp is NOT in limit", () => { | ||
const message1: IMessage = { | ||
text: "Hello", | ||
source: "bot", | ||
timestamp: String(Date.now() - 1000 * 120), | ||
}; | ||
const message2: IMessage = { | ||
text: "World", | ||
source: "bot", | ||
timestamp: String(Date.now()), | ||
}; | ||
|
||
const { getAllByTestId } = render( | ||
<> | ||
<Message message={message1} /> | ||
<Message message={message2} prevMessage={message1} /> | ||
</>, | ||
); | ||
|
||
const messageHeaders = getAllByTestId("message-header"); | ||
expect(messageHeaders).toHaveLength(2); | ||
}); | ||
|
||
it("does NOT collate if source is different", () => { | ||
const message1: IMessage = { | ||
text: "Hello", | ||
source: "bot", | ||
timestamp: String(Date.now() - 1000), | ||
}; | ||
const message2: IMessage = { | ||
text: "World", | ||
source: "user", | ||
timestamp: String(Date.now()), | ||
}; | ||
|
||
const { getAllByTestId } = render( | ||
<> | ||
<Message message={message1} /> | ||
<Message message={message2} prevMessage={message1} /> | ||
</>, | ||
); | ||
|
||
const messageHeaders = getAllByTestId("message-header"); | ||
expect(messageHeaders).toHaveLength(2); | ||
}); | ||
|
||
it("collates multiple if all are in limit", () => { | ||
const message1: IMessage = { text: "Hello", source: "user", timestamp: String(Date.now()) }; | ||
const message2: IMessage = { | ||
text: "World", | ||
source: "user", | ||
timestamp: String(Date.now()), | ||
}; | ||
const message3: IMessage = { | ||
text: "World2", | ||
source: "user", | ||
timestamp: String(Date.now()), | ||
}; | ||
const message4: IMessage = { | ||
text: "World3", | ||
source: "user", | ||
timestamp: String(Date.now()), | ||
}; | ||
|
||
const { getAllByTestId } = render( | ||
<> | ||
<Message message={message1} /> | ||
<Message message={message2} prevMessage={message1} /> | ||
<Message message={message3} prevMessage={message2} /> | ||
<Message message={message4} prevMessage={message3} /> | ||
</>, | ||
); | ||
|
||
const messageHeaders = getAllByTestId("message-header"); | ||
expect(messageHeaders).toHaveLength(1); | ||
}); | ||
}); |