Skip to content

Commit

Permalink
Fix the initialization of the messages component (#60)
Browse files Browse the repository at this point in the history
* Fix the messages in the component at initilization

* Fix tests on unread ?

* Fix tests on unread
  • Loading branch information
brichet authored Jul 1, 2024
1 parent e9bda5e commit 2a9d68f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/jupyter-chat/src/components/chat-messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type BaseMessageProps = {
*/
export function ChatMessages(props: BaseMessageProps): JSX.Element {
const { model } = props;
const [messages, setMessages] = useState<IChatMessage[]>([]);
const [messages, setMessages] = useState<IChatMessage[]>(model.messages);
const refMsgBox = useRef<HTMLDivElement>(null);
const inViewport = useRef<number[]>([]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1605,8 +1605,11 @@ test.describe('#markUnread', () => {
test.describe('with previous unread message', () => {
test.beforeEach(async ({ page }) => {
const newMessagesList = [message];
// Add new message to the document.
for (let i = 1; i < 30; i++) {
// Add new messages to the document.
// We need to add many messages because they are currently marked unread
// before being fully rendered by the markdownRenderer. Many messages are marked
// unread even if they are not in the viewport after render.
for (let i = 1; i < 50; i++) {
newMessagesList.push({
type: 'msg',
id: UUID.uuid4(),
Expand Down Expand Up @@ -1643,7 +1646,7 @@ test.describe('#markUnread', () => {

await expect(button).toBeAttached();
await expect(navigationBottom).toBeAttached();
expect(navigationBottom).toHaveClass(/jp-chat-navigation-unread/);
await expect(navigationBottom).toHaveClass(/jp-chat-navigation-unread/);

await button.click();
await expect(navigationBottom).not.toHaveClass(
Expand All @@ -1665,7 +1668,7 @@ test.describe('#markUnread', () => {

await expect(button).toBeAttached();
await expect(navigationBottom).toBeAttached();
expect(navigationBottom).toHaveClass(/jp-chat-navigation-unread/);
await expect(navigationBottom).toHaveClass(/jp-chat-navigation-unread/);

await button.click();
await expect(navigationBottom).not.toHaveClass(
Expand Down

0 comments on commit 2a9d68f

Please sign in to comment.