Skip to content

Commit

Permalink
Allow for existing chats in chat-history tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinEtchells committed Nov 12, 2024
1 parent eb9f948 commit a5106ae
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions django_app/frontend/tests-web-components/chat-history.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,43 @@ test(`Chat history functionality works as expected`, async ({ page }) => {

await page.goto("/chats");

const count1 = await page.evaluate(
() => document.querySelectorAll(".rb-chat-history__link").length
);

await page.evaluate(() => {
document.querySelector("chat-history").addChat("session-id", "Test chat");
});

// The chat history item has been created
const chatHistoryItem = page.locator(".rb-chat-history__link");
const chatHistoryItem = page.locator(".rb-chat-history__link").first();
const count2 = await page.evaluate(
() => document.querySelectorAll(".rb-chat-history__link").length
);
await expect(chatHistoryItem).toContainText("Test chat");
await expect(chatHistoryItem).toHaveAttribute("href", "/chats/session-id");
expect(count2).toEqual(count1 + 1);

// A "Today" heading has been created
await expect(page.locator(".rb-chat-history__date_group")).toContainText(
"Today"
);

// A chat can be renamed
await page.locator(".rb-chat-history__actions-button").click();
await page.locator('button[data-action="rename"]').click();
const textInput = page.locator(".rb-chat-history__text-input input");
await page.locator(".rb-chat-history__actions-button").first().click();
await page.locator('button[data-action="rename"]').first().click();
const textInput = page.locator(".rb-chat-history__text-input input").first();
await textInput.fill("Renamed chat");
await textInput.press("Enter");
await expect(chatHistoryItem).toContainText("Renamed chat");

// A chat can be deleted
await page.locator(".rb-chat-history__actions-button").click();
await page.locator('button[data-action="delete"]').click();
await page.locator('button[data-action="delete-confirm"]').click();
await page.locator(".rb-chat-history__actions-button").first().click();
await page.locator('button[data-action="delete"]').first().click();
await page.locator('button[data-action="delete-confirm"]').first().click();
await page.waitForTimeout(100);
expect(await page.$(".rb-chat-history__link")).toBeFalsy();
const count3 = await page.evaluate(
() => document.querySelectorAll(".rb-chat-history__link").length
);
expect(count3).toEqual(count1);
});

0 comments on commit a5106ae

Please sign in to comment.