Skip to content

Commit

Permalink
test: Adding Cypress integration testcase for Sensitive input (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
arulk8 authored Oct 6, 2024
1 parent ab7a206 commit bbb9269
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
21 changes: 15 additions & 6 deletions cypress/e2e/tests.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ describe("Chat Bot Test Suite", () => {
it("Sends name and verifies bot reply", () => {
cy.get(".rcb-chat-input-textarea").type("Tan Jin{enter}");
cy.get(".rcb-bot-message").contains("Hey Tan Jin!").should("be.visible");
cy.get(".rcb-bot-message").contains("Before we processed").should("be.visible");
});

it("Senstive input should be masked", () => {
cy.get(".rcb-chat-input-textarea").type("123456");
cy.get('input[type="password"]').should('exist');
cy.get(".rcb-chat-input-textarea").should('have.value',"123456");
cy.get(".rcb-send-button").click();
cy.get(".rcb-user-message").contains("******").should("be.visible");
});

it("Disabled chat input", () => {
Expand Down Expand Up @@ -86,19 +95,17 @@ describe("Chat Bot Test Suite", () => {
cy.get(".rcb-emoji-button-enabled").click();
cy.get(".rcb-emoji").should('exist').should('be.visible').first().click();
cy.get(".rcb-send-button").click();
cy.get(".rcb-bot-message")
.eq(9)
.contains("Your answer is incorrect, try again!")
.should("be.visible");
cy.get(".rcb-chat-body-container").scrollTo('bottom', { duration: 1000 });
cy.get(".rcb-bot-message").contains("Your answer is incorrect, try again!");
});

it("Sends correct color guess and verifies bot reply", () => {
cy.get(".rcb-chat-input-textarea").should("be.visible");
cy.get(".rcb-chat-input-textarea").scrollIntoView().should("be.visible");
cy.get(".rcb-chat-input-textarea").type("black{enter}");
});

it("Closes chat window and verifies bot reply", () => {
cy.get(".rcb-window-close").should("exist");
cy.get(".rcb-button-show").should("exist");
});

it("Reopens chat window and verifies bot reply", () => {
Expand All @@ -108,6 +115,8 @@ describe("Chat Bot Test Suite", () => {
});

it("Send food and verifies bot reply", () => {
cy.get(".bold").should('have.css', 'font-weight')
.then((fontWeight) => +fontWeight).and('be.gte', 700)
cy.get(".rcb-chat-input-textarea")
.should("be.visible")
.type("pasta{enter}");
Expand Down
32 changes: 27 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
import { useState } from "react";
import ChatBot from "./components/ChatBot";
import { Flow } from "./types/Flow";
import { Params } from "./types/Params";

function App() {
const [name, setName] = useState("")

// Serves as an example flow used during the development phase - covers all possible attributes in a block.
// restore to default state before running selenium tests (or update the test cases if necessary)!
const flow: Flow = {
start: {
message: "Hello! What is your name?",
path: "ask_age_group",
path: "show_name",
},
show_name : {
message: (params: Params) => `Hey ${params.userInput}! Nice to meet you.`,
function: (params: Params) => setName(params.userInput),
transition: {duration: 1000},
path: "ask_token",
},
ask_token: {
message: () => "Before we processed, we need to verify your profile id, "
+ "Enter your 6 digit profile id",
isSensitive: true,
path: (params: Params) => {
if (params.userInput.length !== 6) {
return "incorrect_answer"
} else {
return "ask_age_group";
}
},
},
ask_age_group: {
message: (params: Params) => `Hey ${params.userInput}! Nice to meet you, what is your age group?`,
message: () => `Hey ${name}!, Your account got verified, May i know your age group?`,
options: ["child", "teen", "adult"],
chatDisabled: true,
path: () => "ask_math_question",
Expand Down Expand Up @@ -85,7 +105,8 @@ function App() {
},
},
close_chat: {
message: "I went into hiding but you found me! Ok tell me, what's your favourite food?",
message: "I went into hiding but you found me! Ok tell me, "+
"<b class='bold'>what's your favourite food?</b>",
path: "ask_image"
},
ask_image: {
Expand Down Expand Up @@ -123,9 +144,10 @@ function App() {
settings={{
audio: {disabled: false},
chatInput: {botDelay: 1000},
userBubble: {showAvatar: true},
botBubble: {showAvatar: true},
userBubble: {showAvatar: true, dangerouslySetInnerHtml: true},
botBubble: {showAvatar: true, dangerouslySetInnerHtml: true},
voice: {disabled: false},
sensitiveInput: {asterisksCount: 6},
}}
></ChatBot>
</div>
Expand Down

0 comments on commit bbb9269

Please sign in to comment.