From 8f03b6decbe095a776de2f55f004f61a07dca905 Mon Sep 17 00:00:00 2001 From: Fabio Colajanni Date: Mon, 8 Jul 2024 19:12:23 +0200 Subject: [PATCH 1/3] writing tests and fixtures --- cypress/e2e/prevConvesations.cy.ts | 128 ++++++++++++++++++ cypress/fixtures/prevConversations.json | 27 ++++ .../fixtures/prevConversationsExpired.json | 27 ++++ 3 files changed, 182 insertions(+) create mode 100644 cypress/e2e/prevConvesations.cy.ts create mode 100644 cypress/fixtures/prevConversations.json create mode 100644 cypress/fixtures/prevConversationsExpired.json diff --git a/cypress/e2e/prevConvesations.cy.ts b/cypress/e2e/prevConvesations.cy.ts new file mode 100644 index 00000000..4647717f --- /dev/null +++ b/cypress/e2e/prevConvesations.cy.ts @@ -0,0 +1,128 @@ +describe("Previous Conversations", () => { + beforeEach(() => { + cy.visitWebchat(); + }); + + it("is possible to navigate to empty convesration list from Home Screen", () => { + cy.initMockWebchat({ + settings: { + homeScreen: { + enabled: true, + previousConversations: { + enabled: true, + buttonText: "View previous conversations", + }, + }, + }, + }); + cy.openWebchat(); + cy.get("button").contains("View previous conversations").click(); + cy.get(".webchat-prev-conversations-content").should("exist"); + + // it should be empty list + cy.get(".webchat-prev-conversations-item").should("have.length", 0); + }); + + it("should list a new conversation", () => { + cy.session("default1", () => { + const localOptions = { + userId: `user-1`, + sessionId: `session-1`, + channel: `channel-1`, + }; + + cy.window().then(window => { + window.localStorage.clear(); + }); + + cy.visitWebchat(); + cy.initWebchat(localOptions).openWebchat().startConversation(); + cy.sendMessage("hello"); + cy.contains('You said "hello".').should("be.visible"); + + // list contains 1 item + cy.get("button.webchat-header-back-button").should("exist").click(); + cy.get("button").contains("Previous conversations").click(); + cy.get(".webchat-prev-conversations-item").should("have.length", 1); + + // check if conversation persists after page reload + cy.reload(); + cy.initWebchat(localOptions).openWebchat(); + cy.get("button").contains("Previous conversations").click(); + cy.get(".webchat-prev-conversations-content").should("exist"); + cy.get(".webchat-prev-conversations-item").should("have.length", 1); + }); + }); + + it("is possible to continue a previous conversation", () => { + cy.session("default2", () => { + const localOptions = { + userId: `user-1`, + sessionId: `session-1`, + channel: `channel-1`, + }; + + const key = [ + "channel-1", + "user-1", + "session-1", + "5e51fcdc2c10fe4c5267c8a798a7134086f60b62998062af620ed73b096e25bd", + ]; + + cy.window().then(window => { + window.localStorage.clear(); + cy.fixture("prevConversations.json").then(jsonData => { + window.localStorage.setItem(JSON.stringify(key), JSON.stringify(jsonData)); + }); + }); + + cy.visitWebchat(); + cy.initWebchat(localOptions).openWebchat(); + cy.get("button").contains("Previous conversations").click(); + cy.get(".webchat-prev-conversations-content").should("exist"); + cy.get(".webchat-prev-conversations-item").should("have.length", 1); + + // go to the first conversation + cy.get(".webchat-prev-conversations-item").eq(0).click(); + + cy.sendMessage("hello 2"); + cy.contains('You said "hello 2".').should("be.visible"); + }); + }); + + it("is not possible to continue expired previous conversation", () => { + cy.session("default3", () => { + const localOptions = { + userId: `user-1`, + sessionId: `session-1`, + channel: `channel-1`, + }; + + const key = [ + "channel-1", + "user-1", + "session-1", + "5e51fcdc2c10fe4c5267c8a798a7134086f60b62998062af620ed73b096e25bd", + ]; + + cy.window().then(window => { + window.localStorage.clear(); + cy.fixture("prevConversationsExpired.json").then(jsonData => { + window.localStorage.setItem(JSON.stringify(key), JSON.stringify(jsonData)); + }); + }); + + cy.visitWebchat(); + cy.initWebchat(localOptions).openWebchat(); + cy.get("button").contains("Previous conversations").click(); + cy.get(".webchat-prev-conversations-content").should("exist"); + cy.get(".webchat-prev-conversations-item").should("have.length", 1); + + // go to the first conversation + cy.get(".webchat-prev-conversations-item").eq(0).click(); + + cy.contains("Conversation ended").should("be.visible"); + cy.get(".webchat-input").should("not.exist"); + }); + }); +}); diff --git a/cypress/fixtures/prevConversations.json b/cypress/fixtures/prevConversations.json new file mode 100644 index 00000000..c75e3c4b --- /dev/null +++ b/cypress/fixtures/prevConversations.json @@ -0,0 +1,27 @@ +{ + "messages": [ + { + "text": "hello", + "source": "user", + "timestamp": 1720453536114 + }, + { + "text": "You said \"hello\".", + "data": {}, + "traceId": "endpoint-realtimeClient-fake-id", + "disableSensitiveLogging": false, + "source": "bot", + "timestamp": 1720453537060 + } + ], + "rating": { + "hasGivenRating": false, + "showRatingScreen": false, + "requestRatingScreenTitle": "", + "customRatingTitle": "", + "customRatingCommentText": "", + "requestRatingSubmitButtonText": "", + "requestRatingEventBannerText": "", + "requestRatingChatStatusBadgeText": "" + } +} \ No newline at end of file diff --git a/cypress/fixtures/prevConversationsExpired.json b/cypress/fixtures/prevConversationsExpired.json new file mode 100644 index 00000000..d25c8680 --- /dev/null +++ b/cypress/fixtures/prevConversationsExpired.json @@ -0,0 +1,27 @@ +{ + "messages": [ + { + "text": "hello 2", + "source": "user", + "timestamp": 1715178199 + }, + { + "text": "You said \"hello 2\".", + "data": {}, + "traceId": "endpoint-realtimeClient-fake-id", + "disableSensitiveLogging": false, + "source": "bot", + "timestamp": 1715178199 + } + ], + "rating": { + "hasGivenRating": false, + "showRatingScreen": false, + "requestRatingScreenTitle": "", + "customRatingTitle": "", + "customRatingCommentText": "", + "requestRatingSubmitButtonText": "", + "requestRatingEventBannerText": "", + "requestRatingChatStatusBadgeText": "" + } +} \ No newline at end of file From d7345b573b53a2dbcb4debab5d537590cb7088af Mon Sep 17 00:00:00 2001 From: Fabio Colajanni Date: Mon, 8 Jul 2024 19:20:20 +0200 Subject: [PATCH 2/3] fix formatting --- cypress/e2e/prevConvesations.cy.ts | 34 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/cypress/e2e/prevConvesations.cy.ts b/cypress/e2e/prevConvesations.cy.ts index 4647717f..d6dfc94e 100644 --- a/cypress/e2e/prevConvesations.cy.ts +++ b/cypress/e2e/prevConvesations.cy.ts @@ -3,7 +3,7 @@ describe("Previous Conversations", () => { cy.visitWebchat(); }); - it("is possible to navigate to empty convesration list from Home Screen", () => { + it("is possible to navigate to empty conversation list from Home Screen", () => { cy.initMockWebchat({ settings: { homeScreen: { @@ -40,7 +40,7 @@ describe("Previous Conversations", () => { cy.sendMessage("hello"); cy.contains('You said "hello".').should("be.visible"); - // list contains 1 item + // list contains 1 item cy.get("button.webchat-header-back-button").should("exist").click(); cy.get("button").contains("Previous conversations").click(); cy.get(".webchat-prev-conversations-item").should("have.length", 1); @@ -67,14 +67,14 @@ describe("Previous Conversations", () => { "user-1", "session-1", "5e51fcdc2c10fe4c5267c8a798a7134086f60b62998062af620ed73b096e25bd", - ]; + ]; - cy.window().then(window => { - window.localStorage.clear(); - cy.fixture("prevConversations.json").then(jsonData => { - window.localStorage.setItem(JSON.stringify(key), JSON.stringify(jsonData)); - }); - }); + cy.window().then(window => { + window.localStorage.clear(); + cy.fixture("prevConversations.json").then(jsonData => { + window.localStorage.setItem(JSON.stringify(key), JSON.stringify(jsonData)); + }); + }); cy.visitWebchat(); cy.initWebchat(localOptions).openWebchat(); @@ -103,14 +103,14 @@ describe("Previous Conversations", () => { "user-1", "session-1", "5e51fcdc2c10fe4c5267c8a798a7134086f60b62998062af620ed73b096e25bd", - ]; - - cy.window().then(window => { - window.localStorage.clear(); - cy.fixture("prevConversationsExpired.json").then(jsonData => { - window.localStorage.setItem(JSON.stringify(key), JSON.stringify(jsonData)); - }); - }); + ]; + + cy.window().then(window => { + window.localStorage.clear(); + cy.fixture("prevConversationsExpired.json").then(jsonData => { + window.localStorage.setItem(JSON.stringify(key), JSON.stringify(jsonData)); + }); + }); cy.visitWebchat(); cy.initWebchat(localOptions).openWebchat(); From b84a2a709e31a6386791eb791c50bcb8694e18a7 Mon Sep 17 00:00:00 2001 From: Fabio Colajanni Date: Tue, 9 Jul 2024 11:00:27 +0200 Subject: [PATCH 3/3] removing fixture for conversation continued test --- cypress/e2e/prevConvesations.cy.ts | 22 ++++++++------------ cypress/fixtures/prevConversations.json | 27 ------------------------- 2 files changed, 8 insertions(+), 41 deletions(-) delete mode 100644 cypress/fixtures/prevConversations.json diff --git a/cypress/e2e/prevConvesations.cy.ts b/cypress/e2e/prevConvesations.cy.ts index d6dfc94e..85dac04e 100644 --- a/cypress/e2e/prevConvesations.cy.ts +++ b/cypress/e2e/prevConvesations.cy.ts @@ -54,7 +54,7 @@ describe("Previous Conversations", () => { }); }); - it("is possible to continue a previous conversation", () => { + it("should be possible to continue a previous conversation", () => { cy.session("default2", () => { const localOptions = { userId: `user-1`, @@ -62,24 +62,18 @@ describe("Previous Conversations", () => { channel: `channel-1`, }; - const key = [ - "channel-1", - "user-1", - "session-1", - "5e51fcdc2c10fe4c5267c8a798a7134086f60b62998062af620ed73b096e25bd", - ]; - cy.window().then(window => { window.localStorage.clear(); - cy.fixture("prevConversations.json").then(jsonData => { - window.localStorage.setItem(JSON.stringify(key), JSON.stringify(jsonData)); - }); }); cy.visitWebchat(); - cy.initWebchat(localOptions).openWebchat(); + cy.initWebchat(localOptions).openWebchat().startConversation(); + cy.sendMessage("hello"); + cy.contains('You said "hello".').should("be.visible"); + + // list contains 1 item + cy.get("button.webchat-header-back-button").should("exist").click(); cy.get("button").contains("Previous conversations").click(); - cy.get(".webchat-prev-conversations-content").should("exist"); cy.get(".webchat-prev-conversations-item").should("have.length", 1); // go to the first conversation @@ -90,7 +84,7 @@ describe("Previous Conversations", () => { }); }); - it("is not possible to continue expired previous conversation", () => { + it("should not be possible to continue expired previous conversation", () => { cy.session("default3", () => { const localOptions = { userId: `user-1`, diff --git a/cypress/fixtures/prevConversations.json b/cypress/fixtures/prevConversations.json deleted file mode 100644 index c75e3c4b..00000000 --- a/cypress/fixtures/prevConversations.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "messages": [ - { - "text": "hello", - "source": "user", - "timestamp": 1720453536114 - }, - { - "text": "You said \"hello\".", - "data": {}, - "traceId": "endpoint-realtimeClient-fake-id", - "disableSensitiveLogging": false, - "source": "bot", - "timestamp": 1720453537060 - } - ], - "rating": { - "hasGivenRating": false, - "showRatingScreen": false, - "requestRatingScreenTitle": "", - "customRatingTitle": "", - "customRatingCommentText": "", - "requestRatingSubmitButtonText": "", - "requestRatingEventBannerText": "", - "requestRatingChatStatusBadgeText": "" - } -} \ No newline at end of file