diff --git a/src/components/UI/Form/Input/Input.tsx b/src/components/UI/Form/Input/Input.tsx index 316c6ae04..a9051d755 100644 --- a/src/components/UI/Form/Input/Input.tsx +++ b/src/components/UI/Form/Input/Input.tsx @@ -112,7 +112,11 @@ export const Input = ({ return ( <> - {translation &&
{translation}
} + {translation && ( +
+ {translation} +
+ )}
{inputLabel && ( diff --git a/src/containers/Chat/ChatInterface/ChatInterface.test.tsx b/src/containers/Chat/ChatInterface/ChatInterface.test.tsx index a5c04f909..8d50c9cd2 100644 --- a/src/containers/Chat/ChatInterface/ChatInterface.test.tsx +++ b/src/containers/Chat/ChatInterface/ChatInterface.test.tsx @@ -20,6 +20,7 @@ import { OrganizationStateMock } from 'mocks/Organization'; import { collectionCountSubscription } from 'mocks/Search'; import ChatInterface from './ChatInterface'; +import { getWhatsAppManagedPhonesStatusMock } from 'mocks/StatusBar'; const mockedUsedNavigate = vi.fn(); vi.mock('react-router-dom', async () => ({ @@ -103,6 +104,7 @@ const mocks = [ getAttachmentPermissionMock, savedSearchQuery, markAsReadMock('2'), + getWhatsAppManagedPhonesStatusMock, ]; const wrapper = ( diff --git a/src/containers/InteractiveMessage/InteractiveMessage.test.tsx b/src/containers/InteractiveMessage/InteractiveMessage.test.tsx index 311f0e5c2..0aa7adf0b 100644 --- a/src/containers/InteractiveMessage/InteractiveMessage.test.tsx +++ b/src/containers/InteractiveMessage/InteractiveMessage.test.tsx @@ -7,6 +7,10 @@ import { vi } from 'vitest'; import { setUserSession } from 'services/AuthService'; import { + getTemplateMocks1, + getTemplateMocks2, + getTemplateMocks3, + getTemplateMocks4, mocks, translateInteractiveTemplateMock, translateWitTrimmingMocks, @@ -96,13 +100,9 @@ const mockData = [...mocks, ...mocks]; setUserSession(JSON.stringify({ organization: { id: '1' }, roles: ['Admin'] })); -const renderInteractiveMessage = (id: string, mocks?: any) => { - let MOCKS = mockData; - if (mocks) { - MOCKS = [...MOCKS, ...mocks]; - } +const renderInteractiveMessage = (id: string, mocks: any) => { return ( - + } /> @@ -324,25 +324,25 @@ describe('Add mode', () => { describe('Edit mode', () => { test('it renders quick reply in edit mode and changes language', async () => { - render(renderInteractiveMessage('1')); + render(renderInteractiveMessage('1', getTemplateMocks1)); await waitFor(() => { expect(screen.getByText('Title')).toBeInTheDocument(); - expect(screen.getByText('Details Confirmation')).toBeInTheDocument(); + expect(screen.getByText('Are you excited for *Glific*?')).toBeInTheDocument(); + expect(screen.getByText('yes')).toBeInTheDocument(); expect(screen.getByText('Marathi')).toBeInTheDocument(); }); fireEvent.click(screen.getByText('Marathi')); await waitFor(() => { - expect(screen.getByText('Title')).toBeInTheDocument(); - expect(screen.getByText('सही')).toBeInTheDocument(); + expect(screen.getByTestId('translation')).toBeInTheDocument(); }); fireEvent.click(screen.getByText('English')); await waitFor(() => { - expect(screen.getByText('Details Confirmation')).toBeInTheDocument(); + expect(screen.queryAllByTestId('translation')).toHaveLength(0); }); fireEvent.click(screen.getByTestId('submitActionButton')); @@ -353,19 +353,19 @@ describe('Edit mode', () => { }); test('it renders interactive list in edit mode', async () => { - render(renderInteractiveMessage('2')); + render(renderInteractiveMessage('2', getTemplateMocks2)); await waitFor(() => { - const saveButton = screen.getByText('Save'); - expect(saveButton).toBeInTheDocument(); - fireEvent.click(saveButton); + expect(screen.getByText('List header*')).toBeInTheDocument(); }); }); test('it renders interactive quick reply with media in edit mode', async () => { - render(renderInteractiveMessage('3')); + render(renderInteractiveMessage('3', getTemplateMocks3)); - // vi.spyOn(axios, 'get').mockResolvedValueOnce(responseMock3); + await waitFor(() => { + expect(screen.getByText('Button text')).toBeInTheDocument(); + }); }); }); @@ -481,7 +481,9 @@ describe('translates the template', () => { }); test('it shows error on translating an already exisiting template', async () => { - render(renderInteractiveMessage('1', [translateInteractiveTemplateMock(true)])); + render( + renderInteractiveMessage('1', [...getTemplateMocks1, translateInteractiveTemplateMock(true)]) + ); await waitFor(() => { expect(screen.getByText('Edit Interactive message')).toBeInTheDocument(); @@ -525,20 +527,17 @@ describe('translates the template', () => { }); test('it shows warning if contents are trimmed', async () => { - render(renderInteractiveMessage('4')); + render(renderInteractiveMessage('4', getTemplateMocks4)); await waitFor(() => { expect(screen.getByText('Title')).toBeInTheDocument(); - expect(screen.getByText('Details Confirmation')).toBeInTheDocument(); expect(screen.getByText('Marathi')).toBeInTheDocument(); + expect(screen.getByText('Are you excited for *Glific*?')).toBeInTheDocument(); + expect(screen.getByText('yes')).toBeInTheDocument(); }); fireEvent.click(screen.getByText('Marathi')); - await waitFor(() => { - expect(screen.getByText('Details Confirmation')).toBeInTheDocument(); - }); - await waitFor(() => { expect(screen.getByText('Translations exceeding limit.')).toBeInTheDocument(); }); @@ -551,13 +550,13 @@ describe('copy interactive message', () => { test('it renders copy interactive quick reply message', async () => { mockUseLocationValue.state = 'copy'; - const { getByText, getAllByTestId } = render(renderInteractiveMessage('1')); + const { getByText, getAllByTestId } = render(renderInteractiveMessage('1', getTemplateMocks1)); // vi.spyOn(axios, 'get').mockResolvedValueOnce(responseMock1); await waitFor(() => { expect(getByText('Copy Interactive Message')).toBeInTheDocument(); const input = getAllByTestId('input'); - expect(input[0]?.querySelector('input')).toHaveValue('Copy of Details Confirmation'); + expect(input[0]?.querySelector('input')).toHaveValue('Copy of Are you excited for *Glific*?'); }); }); }); diff --git a/src/containers/StaffManagement/StaffManagement.test.helper.tsx b/src/containers/StaffManagement/StaffManagement.test.helper.tsx index fa0f00fbc..6b17463b2 100644 --- a/src/containers/StaffManagement/StaffManagement.test.helper.tsx +++ b/src/containers/StaffManagement/StaffManagement.test.helper.tsx @@ -183,18 +183,12 @@ const GET_GROUPS = { }, }; -const UPDATE_USER_MOCK = { +const updateUserMock = (input?: any) => ({ request: { query: UPDATE_USER, variables: { id: '1', - input: { - name: 'Staff', - isRestricted: false, - addRoleIds: ['3'], - deleteRoleIds: ['2'], - groupIds: ['2'], - }, + input, }, }, result: { @@ -217,7 +211,7 @@ const UPDATE_USER_MOCK = { }, }, }, -}; +}); const UPDATE_USER_DEMOTE_ADMIN_MOCK = { request: { @@ -325,9 +319,23 @@ export const STAFF_MANAGEMENT_MOCKS = [ GET_ROLES_MOCK, GET_USER_LANGUAGE_MOCK, GET_GROUPS, - UPDATE_USER_MOCK, + UPDATE_USER_MULTIPLE_ROLES_MOCK, getRoleNamesMock, + updateUserMock({ + name: 'Staff', + isRestricted: false, + addRoleIds: ['3'], + deleteRoleIds: ['2'], + groupIds: ['2'], + }), + updateUserMock({ + name: 'Staff', + isRestricted: false, + addRoleIds: [], + deleteRoleIds: [], + groupIds: ['2'], + }), ]; export const STAFF_MANAGEMENT_MOCKS_WITH_EMPTY_ROLES = [ diff --git a/src/containers/Template/Form/SpeedSend/SpeedSend.test.tsx b/src/containers/Template/Form/SpeedSend/SpeedSend.test.tsx index 246c44f64..b6de312cf 100644 --- a/src/containers/Template/Form/SpeedSend/SpeedSend.test.tsx +++ b/src/containers/Template/Form/SpeedSend/SpeedSend.test.tsx @@ -9,6 +9,7 @@ import { SpeedSend } from './SpeedSend'; import * as Notification from 'common/notification'; import { LexicalComposer } from '@lexical/react/LexicalComposer'; import { BeautifulMentionNode } from 'lexical-beautiful-mentions'; +import axios from 'axios'; setUserSession(JSON.stringify({ roles: ['Admin'] })); @@ -37,8 +38,17 @@ vi.mock('lexical-beautiful-mentions', async (importOriginal) => { }; }); +vi.mock('axios'); +const mockedAxios = axios as any; + +const mockAxios = () => { + const responseData = { data: { message: 'success', is_valid: true } }; + mockedAxios.get.mockImplementationOnce(() => Promise.resolve(responseData)); +}; + describe('SpeedSend', () => { test('cancel button should redirect to SpeedSendlist page', async () => { + mockAxios(); const { container, getByText } = render( @@ -62,6 +72,8 @@ describe('SpeedSend', () => { }); test('should have correct validations ', async () => { + mockAxios(); + const { container } = render( @@ -99,12 +111,15 @@ describe('SpeedSend', () => { }); test('should test translations', async () => { + mockAxios(); + const notificationSpy = vi.spyOn(Notification, 'setNotification'); render( } /> + } /> diff --git a/src/containers/Template/Template.test.helper.ts b/src/containers/Template/Template.test.helper.ts index 633b7ca70..a15f64440 100644 --- a/src/containers/Template/Template.test.helper.ts +++ b/src/containers/Template/Template.test.helper.ts @@ -915,4 +915,5 @@ export const SPEED_SENDS_MOCKS = [ getFilterTagQuery, getFilterTagQuery, updateSessiontemplate, + updateSessiontemplate, ]; diff --git a/src/mocks/Collection.tsx b/src/mocks/Collection.tsx index fa4689bfc..1778a0c85 100644 --- a/src/mocks/Collection.tsx +++ b/src/mocks/Collection.tsx @@ -445,7 +445,7 @@ export const deleteContactFromCollection = { }, }; -export const getCollectionsList = (label?: string) => ({ +export const getCollectionsList = (label?: any) => ({ request: { query: GET_COLLECTIONS_LIST, variables: { diff --git a/src/mocks/Flow.tsx b/src/mocks/Flow.tsx index 22009b7ac..d2d9a0224 100644 --- a/src/mocks/Flow.tsx +++ b/src/mocks/Flow.tsx @@ -286,6 +286,7 @@ const getFlowDetails = (isActive = true, keywords = ['help']) => ({ isActive, name: 'help workflow', keywords, + isTemplate: false, }, ], }, diff --git a/src/mocks/InteractiveMessage.tsx b/src/mocks/InteractiveMessage.tsx index 554cda637..38e78b5fb 100644 --- a/src/mocks/InteractiveMessage.tsx +++ b/src/mocks/InteractiveMessage.tsx @@ -146,39 +146,16 @@ export const getInteractiveCountQuery = { const quickReplyMock = { id: '1', interactiveContent: - '{"type":"quick_reply","options":[{"type":"text","title":"Correct"},{"type":"text","title":"Re-enter details"}],"content":{"type":"text","text":"Please *confirm* if the below details are correct-\\n\\n*Name:* results.name\\n*Profile of:* results.role","header":"Details Confirmation"}}', - label: 'Details Confirmation', + '{"type":"quick_reply","options":[{"type":"text","title":"yes"},{"type":"text","title":"no"}],"content":{"type":"text","text":"Glific comes with all new features","header":"Are you excited for *Glific*?"}}', + label: 'Are you excited for *Glific*?', language: { - __typename: 'Language', id: '1', label: 'English', }, - sendWithTitle: true, - tag: null, - translations: - '{"2":{"type":"quick_reply","options":[{"type":"text","title":"सही"},{"type":"text","title":"विवरण प"}],"content":{"type":"text","text":"कृपया पुष्टि करें कि नीचे दी गई जानकारी सही है या नहीं-\\n\\n*नाम:* results.name\\n*प्रोफ़ाइल:* results.role","header":"विवरण पुष्टि"}},"1":{"type":"quick_reply","options":[{"type":"text","title":"Correct"},{"type":"text","title":"Re-enter details"}],"content":{"type":"text","text":"Please *confirm* if the below details are correct-\\n\\n*Name:* results.name\\n*Profile of:* results.role","header":"Details Confirmation"}}}', - type: 'QUICK_REPLY', -}; - -const quickReplyMockInput = { - type: 'QUICK_REPLY', - interactiveContent: - '{"type":"quick_reply","content":{"type":"text","header":"Details Confirmation","text":"Please *confirm* if the below details are correct-\\n\\n*Name:* results.name\\n*Profile of:* results.role"},"options":[{"type":"text","title":"Correct"},{"type":"text","title":"Re-enter details"}]}', - languageId: '1', - label: 'Details Confirmation', - sendWithTitle: true, translations: - '{"1":{"type":"quick_reply","content":{"type":"text","header":"Details Confirmation","text":"Please *confirm* if the below details are correct-\\n\\n*Name:* results.name\\n*Profile of:* results.role"},"options":[{"type":"text","title":"Correct"},{"type":"text","title":"Re-enter details"}]},"2":{"type":"quick_reply","options":[{"type":"text","title":"सही"},{"type":"text","title":"विवरण प"}],"content":{"type":"text","text":"कृपया पुष्टि करें कि नीचे दी गई जानकारी सही है या नहीं-\\n\\n*नाम:* results.name\\n*प्रोफ़ाइल:* results.role","header":"विवरण पुष्टि"}}}', -}; - -const quickReplyMockInput2 = { + '{"2":{"type":"quick_reply","options":[{"type":"text","title":"हाँ"},{"type":"text","title":"ना"}],"content":{"type":"text","text":"ग्लिफ़िक सभी नई सुविधाओं के साथ आता है","header":"आप ग्लिफ़िक के लिए कितने उत्साहित हैं?"}},"1":{"type":"quick_reply","options":[{"type":"text","title":"yes"},{"type":"text","title":"no"}],"content":{"type":"text","text":"Glific comes with all new features","header":"Are you excited for *Glific*?"}}}', type: 'QUICK_REPLY', - interactiveContent: - '{"type":"quick_reply","options":[{"type":"text","title":"Correct"},{"type":"text","title":"Re-enter details"}],"content":{"type":"text","text":"Please *confirm* if the below details are correct-\\n\\n*Name:* results.name\\n*Profile of:* results.role","header":"Details Confirmation"}}', - languageId: '1', sendWithTitle: true, - translations: - '{"1":{"type":"quick_reply","content":{"type":"text","header":"Details Confirmation","text":"Please *confirm* if the below details are correct-\\n\\n*Name:* results.name\\n*Profile of:* results.role"},"options":[{"type":"text","title":"Correct"},{"type":"text","title":"Re-enter details"}]},"2":{"type":"quick_reply","content":{"type":"text","header":"विवरण पुष्टि","text":"कृपया पुष्टि करें कि नीचे दी गई जानकारी सही है या नहीं-\\n\\n*नाम:* results.name\\n*प्रोफ़ाइल:* results.role"},"options":[{"type":"text","title":"सही"},{"type":"text","title":"विवरण प"}]}}', }; const quickReplyMedia = { @@ -278,19 +255,14 @@ const createInteractiveCustomMock = () => ({ }, }); -const updateMockByType = (id: string, input: any, response: any, message: any = null) => ({ +const updateMockByType = (response: any, message: any = null) => ({ request: { query: UPDATE_INTERACTIVE, - variables: { - id, - input, - }, }, result: { data: { updateInteractiveTemplate: { interactiveTemplate: { - id, insertedAt: '2021-07-14T11:12:42Z', updatedAt: '2021-07-14T11:26:00Z', tag: null, @@ -303,6 +275,7 @@ const updateMockByType = (id: string, input: any, response: any, message: any = errors: null, }, }, + variableMatcher: (variables: any) => true, }); const getTemplateByType = (id: string, body: any) => ({ @@ -482,22 +455,44 @@ export const mocks: any = [ createMockByType(quickReplyMock), createMockByType(listReplyMock), createInteractiveCustomMock(), - updateMockByType('1', quickReplyMockInput, quickReplyMock), - updateMockByType('1', quickReplyMockInput2, quickReplyMock), - updateMockByType('2', listReplyMock, listReplyMock), - updateMockByType('3', quickReply, quickReplyResult), - getTemplateByType('1', quickReplyMock), - getTemplateByType('2', listReplyMock), - getTemplateByType('3', quickReplyMedia), - getTemplateByType('4', quickReplyMock), - updateMockByType('4', quickReplyMockInput, quickReplyMock, trimmingMessage), createMockByType(quick_reply), deleteMock, getFilterTagQuery, getOrganizationLanguagesWithoutOrder, ]; +export const getTemplateMocks1 = [ + ...mocks, + getTemplateByType('1', quickReplyMock), + getTemplateByType('1', quickReplyMock), + updateMockByType(quickReplyMock), + updateMockByType(quickReplyMock), + updateMockByType(quickReplyMock), +]; + +export const getTemplateMocks2 = [ + ...mocks, + getTemplateByType('2', listReplyMock), + getTemplateByType('2', listReplyMock), + updateMockByType(listReplyMock), +]; + +export const getTemplateMocks3 = [ + ...mocks, + getTemplateByType('3', quickReplyMedia), + getTemplateByType('3', quickReplyMedia), + updateMockByType(quickReplyResult), +]; + +export const getTemplateMocks4 = [ + ...mocks, + getTemplateByType('4', quickReplyMock), + getTemplateByType('4', quickReplyMock), + updateMockByType(quickReplyMock, trimmingMessage), +]; + export const translateWithoutTrimmingMocks = [ + ...getTemplateMocks1, translateInteractiveTemplateMock(), importInteractiveTemplateMock(), exportInteractiveTemplateMock(), @@ -505,6 +500,7 @@ export const translateWithoutTrimmingMocks = [ ]; export const translateWitTrimmingMocks = [ + ...getTemplateMocks1, translateInteractiveTemplateWithTrimMock, importInteractiveTemplateWithTrimmingMock, ];