Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring: Separating HSM and Speed sends #3063

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cypress-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
git clone https://github.com/glific/cypress-testing.git
echo done. go to dir.
cd cypress-testing
git checkout main
git checkout templates
cd ..
cp -r cypress-testing/cypress cypress
yarn add [email protected]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { render, fireEvent, cleanup, waitFor } from '@testing-library/react';
import { MockedProvider } from '@apollo/client/testing';

import { SAVE_MESSAGE_TEMPLATE_MUTATION } from 'graphql/mutations/MessageTemplate';
import { TEMPLATE_MOCKS } from 'mocks/Template';
import { filterTemplatesQuery } from 'mocks/Template';
import AddToMessageTemplate from './AddToMessageTemplate';

let resultReturned = false;

const mocks = [
...TEMPLATE_MOCKS,
filterTemplatesQuery('', {}),
{
request: {
query: SAVE_MESSAGE_TEMPLATE_MUTATION,
Expand Down
11 changes: 7 additions & 4 deletions src/containers/Chat/ChatMessages/ChatInput/ChatInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, waitFor, fireEvent, screen } from '@testing-library/react';
import { vi } from 'vitest';

import ChatInput from './ChatInput';
import { TEMPLATE_MOCKS } from 'mocks/Template';
import { filterTemplatesQuery } from 'mocks/Template';
import {
createMediaMessageMock,
getAttachmentPermissionMock,
Expand All @@ -17,7 +17,10 @@ const mocks = [
searchInteractive,
searchInteractive,
searchInteractiveHi,
...TEMPLATE_MOCKS,
filterTemplatesQuery('', { isHsm: true }),
filterTemplatesQuery('', { isHsm: true }),
filterTemplatesQuery('hi', { isHsm: true }),
filterTemplatesQuery('', { isHsm: false }),
getAttachmentPermissionMock,
uploadBlobMock,
createMediaMessageMock({
Expand Down Expand Up @@ -177,12 +180,12 @@ describe('<ChatInput />', () => {
const interactiveMessages = getAllByTestId('shortcutButton')[2];
fireEvent.click(interactiveMessages);
await waitFor(() => {
expect(getAllByTestId('templateItem')).toHaveLength(2);
expect(getAllByTestId('templateItem')).toHaveLength(3);
});
const listItem = getAllByTestId('templateItem')[0];
fireEvent.click(listItem);
await waitFor(() => {
expect(getAllByText('some description')).toHaveLength(1);
expect(getAllByText('description')).toHaveLength(1);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { MockedProvider } from '@apollo/client/testing';
import ChatTemplates from './ChatTemplates';
import { TEMPLATE_MOCKS } from '../../../../mocks/Template';
import { filterTemplatesQuery } from 'mocks/Template';
import { render, fireEvent, waitFor } from '@testing-library/react';

const mocks = TEMPLATE_MOCKS;
const mocks = [
filterTemplatesQuery('', { isHsm: true }),
filterTemplatesQuery('hi', { isHsm: true }, false),
];

describe('<ChatTemplates />', () => {
let defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const TemplateButtons = ({
onClick={() => handleButtonClick(type, value)}
startIcon={icon}
disabled={!isSimulator}
data-testid="templateButton"
>
{title}
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Form/FormLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export const FormLayout = ({
}
});
// for template create media for attachment
if (isAttachment && payload.type !== 'TEXT' && payload.type) {
if (isAttachment && payload.type && payload.type !== 'TEXT') {
getMediaId(payload)
.then((data: any) => {
if (data) {
Expand Down
102 changes: 102 additions & 0 deletions src/containers/HSM/HSM.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
.Template {
margin: 20px auto;
width: 80%;
text-align: center;
box-shadow: 0 2px 3px #cccccc;
border: 1px solid #eeeeee;
padding: 10px;
box-sizing: border-box;
}

@media (min-width: 600px) {
.Template {
width: 500px;
}
}

.DeleteIcon {
margin-right: 9px !important;
}

.DialogText {
margin-top: 0px;
text-align: center;
color: #073f24;
font-weight: 400;
}

.DeleteButton {
margin-left: auto !important;
}

.Title {
margin-left: 24px !important;
margin-top: 16px !important;
vertical-align: middle;
font-weight: 500 !important;
color: #073f24;
}

.Input {
display: flex;
padding: 8px;
}

.Label {
width: 50%;
align-self: center;
font-weight: bold;
}

.TemplateAdd {
width: fit-content;
}

.Form {
padding: 16px 16px;
width: 470px;
}

.Buttons {
margin-top: 24px;
margin-left: 8px;
display: flex;
justify-content: flex-start;
}

.Icon {
background-color: #eaedec !important;
margin-right: 10px !important;
}

.ButtonsCenter {
justify-content: center !important;
}

.Button {
margin-right: 24px !important;
}

.Warning {
color: #ff0000;
margin-left: -43px;
}

.IsActive {
color: #555555;
font-weight: 400;
line-height: 18px;
font-size: 16px;
}

.TemplateIcon {
width: 29px;
height: 29px;
}

.Checkbox {
color: #555555;
font-weight: 400;
line-height: 18px;
font-size: 16px;
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import { render, waitFor, within, fireEvent, screen } from '@testing-library/react';
import { render, waitFor, within, fireEvent, screen, cleanup } from '@testing-library/react';
import { MockedProvider } from '@apollo/client/testing';
import userEvent from '@testing-library/user-event';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
import { HSM } from './HSM';
import {
TEMPLATE_MOCKS,
HSM_TEMPLATE_MOCKS,
getHSMTemplateTypeMedia,
getHSMTemplateTypeText,
} from 'containers/Template/Template.test.helper';
} from 'mocks/Template';
import { setNotification } from 'common/notification';

const mocks = TEMPLATE_MOCKS;
const mocks = HSM_TEMPLATE_MOCKS;

vi.mock('common/notification', async (importOriginal) => {
const mod = await importOriginal<typeof import('common/notification')>();
return {
...mod,
setNotification: vi.fn((...args) => {
return args[1];
}),
};
});

beforeEach(() => {
vi.restoreAllMocks();
cleanup();
});

vi.mock('lexical-beautiful-mentions', async (importOriginal) => {
Expand Down Expand Up @@ -80,6 +91,7 @@ describe('Add mode', () => {
</MemoryRouter>
</MockedProvider>
);

const user = userEvent.setup();

test('check for validations for the HSM form', async () => {
Expand Down Expand Up @@ -121,7 +133,6 @@ describe('Add mode', () => {
const inputs = screen.getAllByRole('textbox');

fireEvent.change(inputs[0], { target: { value: 'element_name' } });
fireEvent.change(inputs[1], { target: { value: 'element_name' } });
const lexicalEditor = inputs[2];

await user.click(lexicalEditor);
Expand All @@ -148,8 +159,17 @@ describe('Add mode', () => {
fireEvent.change(inputs[1], { target: { value: 'element_name' } });

fireEvent.change(screen.getByPlaceholderText('Define value'), { target: { value: 'User' } });
fireEvent.change(inputs[1], { target: { value: 'title' } });

autocompletes[3].focus();
fireEvent.keyDown(autocompletes[3], { key: 'ArrowDown' });
fireEvent.click(screen.getByText('Messages'), { key: 'Enter' });

fireEvent.click(screen.getByTestId('submitActionButton'));

await waitFor(() => {
expect(setNotification).toHaveBeenCalled();
});
});

test('it should add and remove variables', async () => {
Expand Down Expand Up @@ -177,6 +197,10 @@ describe('Add mode', () => {
});

fireEvent.click(screen.getAllByTestId('delete-variable')[0]);

await waitFor(() => {
expect(screen.queryByPlaceholderText('Define value ')).not.toBeInTheDocument();
});
});

test('it adds quick reply buttons', async () => {
Expand Down Expand Up @@ -225,7 +249,10 @@ describe('Add mode', () => {
fireEvent.click(screen.getByText('ACCOUNT_UPDATE'), { key: 'Enter' });

fireEvent.click(screen.getByTestId('submitActionButton'));
fireEvent.click(screen.getByTestId('submitActionButton'));

await waitFor(() => {
expect(setNotification).toHaveBeenCalled();
});
});

test('it adds call to action buttons', async () => {
Expand Down Expand Up @@ -273,7 +300,10 @@ describe('Add mode', () => {
fireEvent.click(screen.getByText('ACCOUNT_UPDATE'), { key: 'Enter' });

fireEvent.click(screen.getByTestId('submitActionButton'));
fireEvent.click(screen.getByTestId('submitActionButton'));

await waitFor(() => {
expect(setNotification).toHaveBeenCalled();
});
});

test('adding attachments', async () => {
Expand Down
Loading
Loading