From 567849fce0937a670e5631ece56b6e4457a42c77 Mon Sep 17 00:00:00 2001 From: HomeVarela Date: Thu, 29 Aug 2024 14:53:25 -0300 Subject: [PATCH 1/6] feat: add conversations buy link --- src/components/ChatPlan.test.tsx | 14 ++++++++++++++ src/components/ChatPlan.tsx | 7 +++++++ src/components/UserPlan.test.tsx | 2 ++ src/components/UserPlan.tsx | 2 ++ src/model.ts | 4 ++++ src/testUserData.json | 4 +++- src/utils.ts | 2 ++ 7 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/components/ChatPlan.test.tsx b/src/components/ChatPlan.test.tsx index 62c19bbb..d311afc3 100644 --- a/src/components/ChatPlan.test.tsx +++ b/src/components/ChatPlan.test.tsx @@ -14,6 +14,8 @@ const defaultUser: User = { wppDescription: "Available for WhatsApp", conversationsQtyBalance: 100, whatsAppCreditBalance: 25.2, + buttonText: "BUY NOW", + buttonUrl: "https://webappint.fromdoppler.net" }, }; @@ -29,6 +31,8 @@ describe(ChatPlan.name, () => { chatQty={defaultUser.chat.conversationsQtyBalance} wppDescription={defaultUser.chat.wppDescription} wppBalance={defaultUser.chat.whatsAppCreditBalance} + buttonText={defaultUser.chat.buttonText} + buttonUrl={defaultUser.chat.buttonUrl} /> , ); @@ -38,6 +42,8 @@ describe(ChatPlan.name, () => { screen.getByText("Premium Plan Conversations"); screen.getByText("Available conversations"); screen.getByText("Available for WhatsApp"); + expect(screen.getByText(defaultUser.chat.buttonText ?? "").closest('a')) + .toHaveAttribute('href', defaultUser.chat.buttonUrl ?? ""); }); it("should not render chat plan details when conversationsQtyBalance isn't defined", () => { @@ -51,6 +57,8 @@ describe(ChatPlan.name, () => { wppDescription: "Available for WhatsApp", conversationsQtyBalance: undefined, whatsAppCreditBalance: 25.2, + buttonText: "BUY NOW", + buttonUrl: "https://webappint.fromdoppler.net", }, }; @@ -64,6 +72,8 @@ describe(ChatPlan.name, () => { chatQty={chatUser.chat.conversationsQtyBalance} wppDescription={chatUser.chat.wppDescription} wppBalance={chatUser.chat.whatsAppCreditBalance} + buttonText={chatUser.chat.buttonText} + buttonUrl={chatUser.chat.buttonUrl} /> , ); @@ -85,6 +95,8 @@ describe(ChatPlan.name, () => { wppDescription: "Available for WhatsApp", conversationsQtyBalance: 100, whatsAppCreditBalance: undefined, + buttonText: "BUY NOW", + buttonUrl: "https://webappint.fromdoppler.net", }, }; @@ -98,6 +110,8 @@ describe(ChatPlan.name, () => { chatQty={chatUser.chat.conversationsQtyBalance} wppDescription={chatUser.chat.wppDescription} wppBalance={chatUser.chat.whatsAppCreditBalance} + buttonText={chatUser.chat.buttonText} + buttonUrl={chatUser.chat.buttonUrl} /> , ); diff --git a/src/components/ChatPlan.tsx b/src/components/ChatPlan.tsx index e1a58bfa..74e3e16c 100644 --- a/src/components/ChatPlan.tsx +++ b/src/components/ChatPlan.tsx @@ -6,18 +6,25 @@ export const ChatPlan = ({ chatQty, wppBalance, wppDescription, + buttonUrl, + buttonText }: { planName: string; chatDescription: string; chatQty: number | undefined; wppBalance: number | undefined; wppDescription: string; + buttonUrl?: string; + buttonText?: string; }) => ( <>

{planName}

+ + {buttonText} +
{chatQty && wppBalance ? (
{ wppDescription: "whats app", conversationsQtyBalance: 10, whatsAppCreditBalance: 10, + buttonText: "BUY NOW", + buttonUrl: "https://webappint.fromdoppler.net", }, }; diff --git a/src/components/UserPlan.tsx b/src/components/UserPlan.tsx index 6f76b175..bf0a5378 100644 --- a/src/components/UserPlan.tsx +++ b/src/components/UserPlan.tsx @@ -100,6 +100,8 @@ export const UserPlan = ({ user }: UserPlanProps) => { chatQty={user.chat.conversationsQtyBalance} wppBalance={user.chat.whatsAppCreditBalance} wppDescription={user.chat.wppDescription} + buttonUrl={user.chat.buttonUrl} + buttonText={user.chat.buttonText} /> ) : ( <> diff --git a/src/model.ts b/src/model.ts index 0dce66b5..2352b169 100644 --- a/src/model.ts +++ b/src/model.ts @@ -103,6 +103,8 @@ export type User = Readonly< wppDescription: string; conversationsQtyBalance: number | undefined; whatsAppCreditBalance: number | undefined; + buttonUrl: string; + buttonText: string; } | { active: false; @@ -111,6 +113,8 @@ export type User = Readonly< wppDescription?: undefined; conversationsQtyBalance?: undefined; whatsAppCreditBalance?: undefined; + buttonUrl: undefined; + buttonText: undefined; } >; landings: Readonly< diff --git a/src/testUserData.json b/src/testUserData.json index 3772f962..8b232b10 100644 --- a/src/testUserData.json +++ b/src/testUserData.json @@ -192,7 +192,9 @@ "chatDescription": "Available Conversations", "wppDescription": "Available for WhatsApp", "conversationsQtyBalance": 10, - "whatsAppCreditBalance": 25.2 + "whatsAppCreditBalance": 25.2, + "buttonText": "BUY NOW", + "buttonUrl": "https://webappint.fromdoppler.net" }, "landings": { "planName": "Add Ons", diff --git a/src/utils.ts b/src/utils.ts index 27cd9798..fe8c87ce 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -121,6 +121,8 @@ const safeChat = (data: any) => conversationsQtyBalance: data?.conversationsQtyBalance, whatsAppCreditBalance: data?.whatsAppCreditBalance, wppDescription: safeString(data?.wppDescription), + buttonText: safeString(data?.buttonText), + buttonUrl: safeString(data?.buttonUrl), } : { active: false as const }; From 8b5a5a6afdb741e59e485cde518577ef44d4b518 Mon Sep 17 00:00:00 2001 From: HomeVarela Date: Thu, 29 Aug 2024 15:23:01 -0300 Subject: [PATCH 2/6] fix: format --- src/components/ChatPlan.test.tsx | 7 ++++--- src/components/ChatPlan.tsx | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/ChatPlan.test.tsx b/src/components/ChatPlan.test.tsx index d311afc3..ae98cf01 100644 --- a/src/components/ChatPlan.test.tsx +++ b/src/components/ChatPlan.test.tsx @@ -15,7 +15,7 @@ const defaultUser: User = { conversationsQtyBalance: 100, whatsAppCreditBalance: 25.2, buttonText: "BUY NOW", - buttonUrl: "https://webappint.fromdoppler.net" + buttonUrl: "https://webappint.fromdoppler.net", }, }; @@ -42,8 +42,9 @@ describe(ChatPlan.name, () => { screen.getByText("Premium Plan Conversations"); screen.getByText("Available conversations"); screen.getByText("Available for WhatsApp"); - expect(screen.getByText(defaultUser.chat.buttonText ?? "").closest('a')) - .toHaveAttribute('href', defaultUser.chat.buttonUrl ?? ""); + expect( + screen.getByText(defaultUser.chat.buttonText ?? "").closest("a"), + ).toHaveAttribute("href", defaultUser.chat.buttonUrl ?? ""); }); it("should not render chat plan details when conversationsQtyBalance isn't defined", () => { diff --git a/src/components/ChatPlan.tsx b/src/components/ChatPlan.tsx index 74e3e16c..c748bc7e 100644 --- a/src/components/ChatPlan.tsx +++ b/src/components/ChatPlan.tsx @@ -7,7 +7,7 @@ export const ChatPlan = ({ wppBalance, wppDescription, buttonUrl, - buttonText + buttonText, }: { planName: string; chatDescription: string; From 8d8a56f3e4d3a53b958a4bbdcd1f32d05979ed9f Mon Sep 17 00:00:00 2001 From: HomeVarela Date: Thu, 29 Aug 2024 15:41:23 -0300 Subject: [PATCH 3/6] fix: show allways conversation buy link --- src/components/UserPlan.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/UserPlan.tsx b/src/components/UserPlan.tsx index bf0a5378..05a6567e 100644 --- a/src/components/UserPlan.tsx +++ b/src/components/UserPlan.tsx @@ -93,13 +93,13 @@ export const UserPlan = ({ user }: UserPlanProps) => { buttonUrl={landings.buttonUrl} /> )} - {!user.hasClientManager && user.chat.active ? ( + {!user.hasClientManager ? ( From 5923d1ed13dc2ce820fc59ba13136811eb8c87db Mon Sep 17 00:00:00 2001 From: HomeVarela Date: Thu, 29 Aug 2024 15:49:55 -0300 Subject: [PATCH 4/6] fix: remove unnecessary test --- src/components/UserPlan.test.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/UserPlan.test.tsx b/src/components/UserPlan.test.tsx index d6c1a570..5a21cf1f 100644 --- a/src/components/UserPlan.test.tsx +++ b/src/components/UserPlan.test.tsx @@ -280,14 +280,14 @@ describe(UserPlan.name, () => { screen.getByText("Premium Plan Conversations"); }); - it("should not display chat plan information when is disabled", () => { - // Act - render( - - - , - ); - const description = screen.queryByTestId("chat-plan-test-id"); - expect(description).not.toBeInTheDocument(); - }); + // it("should not display chat plan information when is disabled", () => { + // // Act + // render( + // + // + // , + // ); + // const description = screen.queryByTestId("chat-plan-test-id"); + // expect(description).not.toBeInTheDocument(); + // }); }); From 847dd8b53e38f6215221b471764f69e8eeb9df80 Mon Sep 17 00:00:00 2001 From: HomeVarela Date: Thu, 29 Aug 2024 17:10:45 -0300 Subject: [PATCH 5/6] fix: load chat data when is not active --- src/utils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index fe8c87ce..1a2d32bd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -124,7 +124,14 @@ const safeChat = (data: any) => buttonText: safeString(data?.buttonText), buttonUrl: safeString(data?.buttonUrl), } - : { active: false as const }; + : { + active: false as const, + planName: safeString(data?.planName), + chatDescription: safeString(data?.chatDescription), + wppDescription: safeString(data?.wppDescription), + buttonText: safeString(data?.buttonText), + buttonUrl: safeString(data?.buttonUrl), + }; const safeLandings = (data: any) => ({ planName: safeString(data?.landings?.planName), From 46288de8e90594bfaf94cc8769a78a60e41fa01d Mon Sep 17 00:00:00 2001 From: HomeVarela Date: Fri, 30 Aug 2024 09:50:29 -0300 Subject: [PATCH 6/6] feat: add test --- src/components/UserPlan.test.tsx | 33 ++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/components/UserPlan.test.tsx b/src/components/UserPlan.test.tsx index 5a21cf1f..da8bcb2a 100644 --- a/src/components/UserPlan.test.tsx +++ b/src/components/UserPlan.test.tsx @@ -280,14 +280,27 @@ describe(UserPlan.name, () => { screen.getByText("Premium Plan Conversations"); }); - // it("should not display chat plan information when is disabled", () => { - // // Act - // render( - // - // - // , - // ); - // const description = screen.queryByTestId("chat-plan-test-id"); - // expect(description).not.toBeInTheDocument(); - // }); + it("should display chat buy link when conversation is not active", () => { + // Arrange + const chatPlanUser: User = { + ...defaultUser, + chat: { + active: false, + planName: "Premium Plan Conversations", + chatDescription: "chat", + wppDescription: "whats app", + buttonText: "BUY NOW", + buttonUrl: "https://webappint.fromdoppler.net", + }, + }; + + // Act + render( + + + , + ); + screen.getByTestId("chat-plan-test-id"); + screen.getByText("Premium Plan Conversations"); + }); });