Skip to content

Commit

Permalink
test: Improve e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tjtanjin committed Oct 1, 2024
1 parent 502ae27 commit dc64d6b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
28 changes: 12 additions & 16 deletions cypress/e2e/tests.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,19 @@ describe("Chat Bot Test Suite", () => {
);
});

it("Sends goodbye and verifies bot reply", () => {
it("Sends goodbye, scrolls away, and verifies new message prompt", () => {
cy.getShadow(".rcb-chat-input-textarea").type("Goodbye!{enter}");
cy.getShadow(".rcb-chat-body-container").scrollTo("top");
cy.getShadow(".rcb-message-prompt-container").should("be.visible");
});

it("Scrolls to bottom on new message prompt click", () => {
cy.getShadow(".rcb-message-prompt-container").click();
cy.getShadow(".rcb-chat-body-container").should(($el) => {
const scrollPosition = $el[0].scrollTop + $el[0].offsetHeight;
const totalHeight = $el[0].scrollHeight;
expect(scrollPosition).to.be.closeTo(totalHeight, 5);
});
cy.getShadow(".rcb-bot-message").contains("You have reached the end of the conversation!")
.should("be.visible");
});
Expand Down Expand Up @@ -171,21 +182,6 @@ describe("Chat Bot Test Suite", () => {
});
});

it("Verifies new message prompt", () => {
cy.getShadow(".rcb-chat-input-textarea").type("Hello{enter}");
cy.getShadow(".rcb-chat-body-container").scrollTo("top");
cy.getShadow(".rcb-message-prompt-container").should("be.visible");
});

it("Scrolls to bottom on new message prompt click", () => {
cy.getShadow(".rcb-message-prompt-container").click();
cy.getShadow(".rcb-chat-body-container").should(($el) => {
const scrollPosition = $el[0].scrollTop + $el[0].offsetHeight;
const totalHeight = $el[0].scrollHeight;
expect(scrollPosition).to.be.closeTo(totalHeight, 5);
});
});

const themeId = "new-theme";
const themeVersion = "1.0.0";
const defaultExpiration = 3;
Expand Down
7 changes: 6 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ function App() {
path: "loop"
},
loop: {
message: "You have reached the end of the conversation!",
message: (params: Params) => {
// sends the message half a second later to facilitate testing of new message prompt
setTimeout(() => {
params.injectMessage("You have reached the end of the conversation!");
}, 500)
},
path: "loop"
},
incorrect_answer: {
Expand Down

0 comments on commit dc64d6b

Please sign in to comment.