|
| 1 | +import { BrowserRouter } from 'react-router-dom'; |
| 2 | +import { ConversationPlan } from '.'; |
| 3 | +import { AppServicesProvider } from '../../../../../services/pure-di'; |
| 4 | +import { render, screen, waitForElementToBeRemoved } from '@testing-library/react'; |
| 5 | +import '@testing-library/jest-dom/extend-expect'; |
| 6 | +import { IntlProvider } from 'react-intl'; |
| 7 | + |
| 8 | +describe('ConversationPlan component', () => { |
| 9 | + it('should render component', async () => { |
| 10 | + // Assert |
| 11 | + var conversationPlan = { |
| 12 | + active: true, |
| 13 | + additionalConversation: 0, |
| 14 | + }; |
| 15 | + |
| 16 | + const dependencies = { |
| 17 | + dopplerBeplicApiClient: { |
| 18 | + getConversations: () => ({ success: true }), |
| 19 | + }, |
| 20 | + dopplerConversationsApiClient: { |
| 21 | + getConversations: () => ({ success: true }), |
| 22 | + }, |
| 23 | + appSessionRef: { |
| 24 | + current: { |
| 25 | + userData: { |
| 26 | + user: { |
| 27 | + conversationsEnvSource: 'DOPPLER', |
| 28 | + addOnPromotions: [], |
| 29 | + plan: { |
| 30 | + isFreeAccount: false, |
| 31 | + planType: 'subscribers', |
| 32 | + maxSubscribers: 500, |
| 33 | + itemDescription: 'subscribers', |
| 34 | + remainingCredits: 500, |
| 35 | + planSubscription: 1, |
| 36 | + }, |
| 37 | + chat: { |
| 38 | + active: false, |
| 39 | + plan: { |
| 40 | + conversationsQty: 200, |
| 41 | + fee: 0, |
| 42 | + }, |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }; |
| 49 | + |
| 50 | + // Act |
| 51 | + render( |
| 52 | + <AppServicesProvider forcedServices={dependencies}> |
| 53 | + <AppServicesProvider forcedServices={dependencies}> |
| 54 | + <BrowserRouter> |
| 55 | + <IntlProvider> |
| 56 | + <ConversationPlan addOnPromotions={[]} conversationPlan={conversationPlan} /> |
| 57 | + </IntlProvider> |
| 58 | + </BrowserRouter> |
| 59 | + </AppServicesProvider> |
| 60 | + , |
| 61 | + </AppServicesProvider>, |
| 62 | + ); |
| 63 | + |
| 64 | + // Assert |
| 65 | + const loader = screen.getByTestId('wrapper-loading'); |
| 66 | + await waitForElementToBeRemoved(loader); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should show the information about conversation plan', async () => { |
| 70 | + // Assert |
| 71 | + var conversationPlan = { |
| 72 | + active: true, |
| 73 | + additionalConversation: 0, |
| 74 | + }; |
| 75 | + |
| 76 | + const dependencies = { |
| 77 | + dopplerBeplicApiClient: { |
| 78 | + getConversations: () => ({ success: true }), |
| 79 | + }, |
| 80 | + dopplerConversationsApiClient: { |
| 81 | + getConversations: () => ({ success: true }), |
| 82 | + }, |
| 83 | + appSessionRef: { |
| 84 | + current: { |
| 85 | + userData: { |
| 86 | + user: { |
| 87 | + conversationsEnvSource: 'DOPPLER', |
| 88 | + addOnPromotions: [], |
| 89 | + plan: { |
| 90 | + isFreeAccount: false, |
| 91 | + planType: 'subscribers', |
| 92 | + maxSubscribers: 500, |
| 93 | + itemDescription: 'subscribers', |
| 94 | + remainingCredits: 500, |
| 95 | + planSubscription: 1, |
| 96 | + }, |
| 97 | + chat: { |
| 98 | + active: false, |
| 99 | + plan: { |
| 100 | + conversationsQty: 200, |
| 101 | + fee: 0, |
| 102 | + trialExpired: false |
| 103 | + }, |
| 104 | + }, |
| 105 | + }, |
| 106 | + }, |
| 107 | + }, |
| 108 | + }, |
| 109 | + }; |
| 110 | + |
| 111 | + // Act |
| 112 | + render( |
| 113 | + <AppServicesProvider forcedServices={dependencies}> |
| 114 | + <AppServicesProvider forcedServices={dependencies}> |
| 115 | + <BrowserRouter> |
| 116 | + <IntlProvider> |
| 117 | + <ConversationPlan addOnPromotions={[]} conversationPlan={conversationPlan} /> |
| 118 | + </IntlProvider> |
| 119 | + </BrowserRouter> |
| 120 | + </AppServicesProvider> |
| 121 | + , |
| 122 | + </AppServicesProvider>, |
| 123 | + ); |
| 124 | + |
| 125 | + // Assert |
| 126 | + const loader = screen.getByTestId('wrapper-loading'); |
| 127 | + await waitForElementToBeRemoved(loader); |
| 128 | + |
| 129 | + expect(screen.getByText('my_plan.subscription_details.addon.conversation_plan.title')).toBeInTheDocument(); |
| 130 | + expect(screen.getByText('my_plan.subscription_details.change_plan_button')).toBeInTheDocument(); |
| 131 | + }); |
| 132 | +}); |
0 commit comments