mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 09:20:15 +01:00
* chore: playwright setup update * refactor: update ChatRoute component with accessible loading spinner with live region * chore(Message): typing * ci: first pass, a11y testing * refactor: update lang attribute in index.html to "en-US" * ci: jsx-a11y dev eslint plugin * ci: jsx plugin * fix: Exclude 'vite.config.ts' from TypeScript compilation for testing * fix(a11y): Remove tabIndex from non-interactive element in MessagesView component * fix(a11y): - Visible, non-interactive elements with click handlers must have at least one keyboard listener.eslintjsx-a11y/click-events-have-key-events - Avoid non-native interactive elements. If using native HTML is not possible, add an appropriate role and support for tabbing, mouse, keyboard, and touch inputs to an interactive content element.eslintjsx-a11y/no-static-element-interactions chore: remove unused bookmarks panel - fix some "Unexpected nullable boolean value in conditional" warnings * fix(NewChat): a11y, nested button issue, add aria-label, remove implicit role * fix(a11y): - partially address #3515 with `main` landmark other: - eslint@typescript-eslint/strict-boolean-expressions * chore(MenuButton): Use button element instead of div for accessibility * chore: Update TitleButton to use button element for accessibility * chore: Update TitleButton to use button element for accessibility * refactor(ChatMenuItem): Improve focus accessibility and code readability * chore(MenuButton): Update aria-label to dynamically include primaryText * fix(a11y): SearchBar - If a form control does not have a properly associated text label, the function or purpose of that form control may not be presented to screen reader users. Visible form labels also provide visible descriptions and larger clickable targets for form controls which placeholders do not. * chore: remove duplicate SearchBar twcss * fix(a11y): - The edit and copy buttons that are visually hidden are exposed to Assistive technology and are announced to screen reader users. * fix(a11y): visible focus outline * fix(a11y): The button to select the LLM Model has the aria-haspopup and aria- expanded attributes which makes its role ambuguous and unclear. It functions like a combobox but doesn't fully support that interaction and also fucntions like a dialog but doesn't completely support that interaction either. * fix(a11y): fix visible focus outline * fix(a11y): Scroll to bottom button missing accessible name #3474 * fix(a11y): The page lacks any heading structure. There should be at least one H1 and other headings to help users understand the orgainzation of the page and the contents. Note: h1 won't be correct here so made it h2 * fix(a11y): LLM controls aria-labels * fix(a11y): There is no visible focus outline to the 'send message' button * fix(a11y): fix visible focus outline for Fork button * refactor(MessageRender): add focus ring to message cards, consolidate complex conditions, add logger for setting latest message, add tabindex for card * fix: focus border color and fix set latest message card condition * fix(a11y): Adequate contrast for MessageAudio buttton * feat: Add GitHub Actions workflow for accessibility linting * chore: Update GitHub Actions workflow for accessibility linting to include client/src/** path * fix(Nav): navmask and accessibility * fix: Update Nav component to handle potential undefined type in SearchContext * fix(a11y): add focus visibility to attach files button #3475 * fix(a11y): discernible text for NewChat button * fix(a11y): accessible landmark names, all page content in landmarks, ensures landmarks are unique #3514 #3515 * fix(Prompts): update isChatRoute prop to be required in List component * fix(a11y): buttons must have discernible text
164 lines
6.3 KiB
TypeScript
164 lines
6.3 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
import type { Response, Page, BrowserContext } from '@playwright/test';
|
|
|
|
const basePath = 'http://localhost:3080/c/';
|
|
const initialUrl = `${basePath}new`;
|
|
const endpoints = ['google', 'openAI', 'azureOpenAI', 'bingAI', 'chatGPTBrowser', 'gptPlugins'];
|
|
const endpoint = endpoints[1];
|
|
|
|
function isUUID(uuid: string) {
|
|
const regex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
return regex.test(uuid);
|
|
}
|
|
|
|
const waitForServerStream = async (response: Response) => {
|
|
const endpointCheck =
|
|
response.url().includes(`/api/ask/${endpoint}`) ||
|
|
response.url().includes(`/api/edit/${endpoint}`);
|
|
return endpointCheck && response.status() === 200;
|
|
};
|
|
|
|
async function clearConvos(page: Page) {
|
|
await page.goto(initialUrl, { timeout: 5000 });
|
|
await page.getByRole('button', { name: 'test' }).click();
|
|
await page.getByText('Settings').click();
|
|
await page.getByTestId('clear-convos-initial').click();
|
|
await page.getByTestId('clear-convos-confirm').click();
|
|
await page.waitForSelector('[data-testid="convo-icon"]', { state: 'detached' });
|
|
await page.getByRole('button', { name: 'Close' }).click();
|
|
}
|
|
|
|
let beforeAfterAllContext: BrowserContext;
|
|
|
|
test.beforeAll(async ({ browser }) => {
|
|
console.log('🤖: clearing conversations before message tests.');
|
|
beforeAfterAllContext = await browser.newContext();
|
|
const page = await beforeAfterAllContext.newPage();
|
|
await clearConvos(page);
|
|
await page.close();
|
|
});
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto(initialUrl, { timeout: 5000 });
|
|
});
|
|
|
|
test.afterEach(async ({ page }) => {
|
|
await page.close();
|
|
});
|
|
|
|
test.describe('Messaging suite', () => {
|
|
test('textbox should be focused after generation, test expected navigation, & test editing messages', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(120000);
|
|
const message = 'hi';
|
|
await page.goto(initialUrl, { timeout: 5000 });
|
|
await page.locator('#new-conversation-menu').click();
|
|
await page.locator(`#${endpoint}`).click();
|
|
await page.locator('form').getByRole('textbox').click();
|
|
await page.locator('form').getByRole('textbox').fill(message);
|
|
|
|
const responsePromise = [
|
|
page.waitForResponse(waitForServerStream),
|
|
page.locator('form').getByRole('textbox').press('Enter'),
|
|
];
|
|
|
|
const [response] = (await Promise.all(responsePromise)) as [Response];
|
|
const responseBody = await response.body();
|
|
const messageSuccess = responseBody.includes('"final":true');
|
|
expect(messageSuccess).toBe(true);
|
|
|
|
// Check if textbox is focused
|
|
await page.waitForTimeout(250);
|
|
const isTextboxFocused = await page.evaluate(() => {
|
|
return document.activeElement === document.querySelector('[data-testid="text-input"]');
|
|
});
|
|
expect(isTextboxFocused).toBeTruthy();
|
|
const currentUrl = page.url();
|
|
expect(currentUrl).toBe(initialUrl);
|
|
|
|
//cleanup the conversation
|
|
await page.getByTestId('new-chat-button').click();
|
|
expect(page.url()).toBe(initialUrl);
|
|
|
|
// Click on the first conversation
|
|
await page.getByTestId('convo-icon').first().click({ timeout: 5000 });
|
|
const finalUrl = page.url();
|
|
const conversationId = finalUrl.split(basePath).pop() ?? '';
|
|
expect(isUUID(conversationId)).toBeTruthy();
|
|
|
|
// Check if editing works
|
|
const editText = 'All work and no play makes Johnny a poor boy';
|
|
await page.getByRole('button', { name: 'edit' }).click();
|
|
const textEditor = page.getByTestId('message-text-editor');
|
|
await textEditor.click();
|
|
await textEditor.fill(editText);
|
|
await page.getByRole('button', { name: 'Save', exact: true }).click();
|
|
|
|
const updatedTextElement = page.getByText(editText);
|
|
expect(updatedTextElement).toBeTruthy();
|
|
|
|
// Check edit response
|
|
await page.getByRole('button', { name: 'edit' }).click();
|
|
const editResponsePromise = [
|
|
page.waitForResponse(waitForServerStream),
|
|
await page.getByRole('button', { name: 'Save & Submit' }).click(),
|
|
];
|
|
|
|
const [editResponse] = (await Promise.all(editResponsePromise)) as [Response];
|
|
const editResponseBody = await editResponse.body();
|
|
const editSuccess = editResponseBody.includes('"final":true');
|
|
expect(editSuccess).toBe(true);
|
|
|
|
// The generated message should include the edited text
|
|
const currentTextContent = await updatedTextElement.innerText();
|
|
expect(currentTextContent.includes(editText)).toBeTruthy();
|
|
});
|
|
|
|
test('message should stop and continue', async ({ page }) => {
|
|
const message = 'write me a 10 stanza poem about space';
|
|
await page.goto(initialUrl, { timeout: 5000 });
|
|
|
|
await page.locator('#new-conversation-menu').click();
|
|
await page.locator(`#${endpoint}`).click();
|
|
await page.click('button[data-testid="select-dropdown-button"]:has-text("Model:")');
|
|
await page.getByRole('option', { name: 'gpt-3.5-turbo', exact: true }).click();
|
|
await page.locator('form').getByRole('textbox').click();
|
|
await page.locator('form').getByRole('textbox').fill(message);
|
|
|
|
let responsePromise = [
|
|
page.waitForResponse(waitForServerStream),
|
|
page.locator('form').getByRole('textbox').press('Enter'),
|
|
];
|
|
|
|
(await Promise.all(responsePromise)) as [Response];
|
|
|
|
// Wait for first Partial tick (it takes 500 ms for server to save the current message stream)
|
|
await page.waitForTimeout(250);
|
|
await page.getByRole('button', { name: 'Stop' }).click();
|
|
|
|
responsePromise = [
|
|
page.waitForResponse(waitForServerStream),
|
|
page.getByTestId('continue-generation-button').click(),
|
|
];
|
|
|
|
(await Promise.all(responsePromise)) as [Response];
|
|
|
|
const regenerateButton = page.getByRole('button', { name: 'Regenerate' });
|
|
expect(regenerateButton).toBeTruthy();
|
|
|
|
// Clear conversation since it seems to persist despite other tests clearing it
|
|
await page.getByTestId('convo-item').getByRole('button').nth(1).click();
|
|
});
|
|
|
|
// in this spec as we are testing post-message navigation, we are not testing the message response
|
|
test('Page navigations', async ({ page }) => {
|
|
await page.goto(initialUrl, { timeout: 5000 });
|
|
await page.getByTestId('convo-icon').first().click({ timeout: 5000 });
|
|
const currentUrl = page.url();
|
|
const conversationId = currentUrl.split(basePath).pop() ?? '';
|
|
expect(isUUID(conversationId)).toBeTruthy();
|
|
await page.getByTestId('new-chat-button').click();
|
|
expect(page.url()).toBe(initialUrl);
|
|
});
|
|
});
|