LibreChat/e2e/specs/mock/scenarios/message-row.spec.ts
Marco Beretta 287a718688
Some checks failed
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
🪟 refactor: Move Message Row and Timestamp into @librechat/chat (#17554)
* refactor: Move Message Row and Timestamp into @librechat/chat

Add a MessagesHost the message list reads the viewer's clock format and row
slots from, registered by the app at load, and move MessageRow,
MessageTimestamp, the row width helper, the timestamp formatters and the
minute ticker into the package with their specs. The user attachments a row
shows reach it through the host's files slot until they move.

* test: Cover Message Rows on Chat and Shared Routes
2026-10-28 22:54:40 +01:00

103 lines
3.7 KiB
TypeScript

import { randomUUID } from 'crypto';
import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
import {
withMongo,
seedMessages,
seedConversations,
deleteConversations,
deleteMessagesByConversation,
} from '../db';
import { getAccessToken, requestJson } from '../helpers';
import { getE2EUser } from '../../../setup/user';
/** Rows built from the package's MessageRow and MessageTimestamp, with the attachments the app
* host renders into them, on the chat route and on a public shared link. */
const NO_PARENT = '00000000-0000-0000-0000-000000000000';
const TEXT = 'Rows keep their header, timestamp and attachments.';
async function seedThread(email: string, createdAt: Date) {
const conversationId = randomUUID();
const userId = randomUUID();
const replyId = randomUUID();
await seedConversations(email, [
{ conversationId, title: 'Message row fixture', updatedAt: new Date() },
]);
await seedMessages(email, conversationId, [
{
messageId: userId,
parentMessageId: NO_PARENT,
text: TEXT,
isCreatedByUser: true,
sender: 'User',
files: [{ file_id: randomUUID(), filename: 'row-notes.txt', type: 'text/plain', bytes: 64 }],
},
{
messageId: replyId,
parentMessageId: userId,
text: `Reply to ${TEXT}`,
isCreatedByUser: false,
sender: 'Assistant',
},
]);
await withMongo((db) =>
db.collection('messages').updateMany({ conversationId }, { $set: { createdAt } }),
);
return { conversationId, userId, replyId };
}
const row = (page: Page, id: string) => page.locator(`[id="${id}"]`);
test.describe('message row', () => {
test('a recent message is stamped with its relative time and exact date @scenario:message-row-shows-relative-timestamp', async ({
page,
}) => {
const { email } = getE2EUser();
const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000);
const { conversationId, replyId } = await seedThread(email, twoHoursAgo);
try {
await page.goto(`/c/${conversationId}`);
const reply = row(page, replyId);
await expect(reply).toContainText(`Reply to ${TEXT}`);
const time = reply.locator('time').first();
await expect(time).toHaveAttribute('datetime', twoHoursAgo.toISOString());
await expect(time).toHaveText('2 hours ago');
await expect(time).toHaveAttribute('title', /\d/);
} finally {
await deleteMessagesByConversation([conversationId]);
await deleteConversations([conversationId]);
}
});
test('a shared link shows the attachments of a user message @scenario:shared-row-shows-user-attachments', async ({
page,
}) => {
const { email } = getE2EUser();
const { conversationId, userId } = await seedThread(email, new Date());
try {
await page.goto(`/c/${conversationId}`);
await expect(
row(page, userId).getByTestId('message-attachments').getByRole('button'),
).toHaveCount(1);
const token = await getAccessToken(page);
const share = await requestJson<{ shareId?: string }>(page, {
path: `/api/share/${conversationId}`,
token,
method: 'POST',
body: {},
});
if (!share.shareId) {
throw new Error('Expected the share response to include a shareId');
}
await page.goto(`/share/${share.shareId}`);
const shared = page.locator('.message-render').filter({ hasText: TEXT }).first();
await expect(shared).toBeVisible({ timeout: 15000 });
await expect(shared.getByTestId('message-attachments')).toBeVisible();
} finally {
await deleteMessagesByConversation([conversationId]);
await deleteConversations([conversationId]);
}
});
});