Skip to content

Commit

Permalink
fixed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
akanshaaa19 committed Feb 26, 2025
1 parent a3c2636 commit 13184f5
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import AddToMessageTemplate from './AddToMessageTemplate';
let resultReturned = false;

const mocks = [
filterTemplatesQuery('', {}),
filterTemplatesQuery('', []),
{
request: {
query: SAVE_MESSAGE_TEMPLATE_MUTATION,
Expand Down
10 changes: 5 additions & 5 deletions src/containers/Flow/Flow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const mocks = [
isActive: true,
isPinned: false,
isBackground: false,
name: 'Copy of Help',
keywords: [],
description: '',
name: 'Help flow',
keywords: ['help'],
description: 'Copy of Help',
ignoreKeywords: false,
addRoleIds: [],
deleteRoleIds: [],
Expand All @@ -50,7 +50,7 @@ const mocks = [
isBackground: false,
name: 'Copy of Help',
keywords: ['help', 'activity'],
description: 'Help flow',
description: 'Copy of Help',
ignoreKeywords: false,
addRoleIds: [],
deleteRoleIds: [],
Expand Down Expand Up @@ -372,7 +372,7 @@ it('should create copy of a template flow', async () => {

const { container, getByTestId } = render(copyFlow());
await waitFor(() => {
expect(screen.getByText('Copy of Help')).toBeInTheDocument();
expect(screen.getAllByText('Copy of Help')[0]).toBeInTheDocument();
});

const button = getByTestId('submitActionButton');
Expand Down
10 changes: 8 additions & 2 deletions src/containers/HSM/HSM.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,19 @@ describe('Add mode', () => {
fireEvent.click(screen.getByText('Add Variable'));

await waitFor(() => {
expect(screen.getByText('Hi {{1}}')).toBeInTheDocument();
expect(screen.getAllByTestId('variable')).toHaveLength(1);
});

fireEvent.click(screen.getByText('Add Variable'));

await waitFor(() => {
expect(screen.getAllByTestId('variable')).toHaveLength(2);
});

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

await waitFor(() => {

Check failure on line 212 in src/containers/HSM/HSM.test.tsx

View workflow job for this annotation

GitHub Actions / CI

src/containers/HSM/HSM.test.tsx > Add mode > it should add and remove variables

TestingLibraryElementError: Unable to find an element by: [data-testid="variable"] Ignored nodes: comments, script, style <body> <div /> <div> <div class="_ItemAdd_787cd5" data-testid="add-container" > <div class="_Heading_7e7077" data-testid="heading" > <div class="_HeadingWrapper_7e7077" > <div class="_BackIcon_7e7077" > <svg data-testid="back-button" fill="none" height="40" viewBox="0 0 40 40" width="40" xmlns="http://www.w3.org/2000/svg" > <circle cx="20" cy="20" fill="white" r="19.5" stroke="#CCCCCC" /> <path d="M22.9292 28L15 20L22.9292 12L24.3333 13.4167L17.8083 20L24.3333 26.5833L22.9292 28Z" fill="#717971" /> </svg> </div> <div> <div class="_HeadingTitle_7e7077" > <div class="_TitleText_7e7077" data-testid="headerTitle" > Add a new HSM Template </div> </div> <div class="_TextHeading_7e7077" > Please enter below details. </div> </div> </div> </div> <form> <div class="_Form_787cd5 " data-testid="formLayout" > <h5 class="MuiTypography-root MuiTypography-h5 _FieldLabel_787cd5 css-16xl4zq-MuiTypography-root" data-testid="formLabel" > Language* </h5> <div class="_Input_029ace" > <div class="MuiFormControl-root MuiFormControl-fullWidth css-ytlejw-MuiFormControl-root" > <div class="MuiAutocomplete-root MuiAutocomplete-hasClearIcon MuiAutocomplete-hasPopupIcon css-1tlcqt-MuiAutocomplete-root" data-testid="autocomplete-element" > <div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-cmpglg-MuiFormControl-root-MuiTextField-root" data-testid="AutocompleteInput" > <div class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-colorPrimary MuiInputBase-fullWidth MuiInputBase-formControl MuiInputBase-adornedEnd MuiAutocomplete-inputRoot _DefaultInputRoot_029ace css-1n04w30-MuiInputBase-root-MuiOutlinedInput-root" > <input aria-autocomplete="list" aria-expanded="false" aria-invalid="false" autocapitalize="none" autocomplete="off" class="MuiInputBase-input MuiOutlinedInput-input MuiInputBase-inputAdornedEnd MuiAutocomplete-input MuiAutocomplete-inputFocused css-1dune0f-MuiInputBase-input-MuiOutlinedInput-input" id=":r30:" placeholder="" role="combobox" spellcheck="false" type="text" value="English" /> <div class="MuiAutocomplete-endAdornment css-1uhhrmm-MuiAutocomplete-endAdornment" > <button aria-label="Clear" class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium MuiAutocomplete-clearIndicator css-1x7n7v0-MuiButtonBase-root-MuiIconButton-root-MuiAutocomplete-clearIndicator" tabindex="-1" title="Clear" type="button" > <svg aria-
expect(screen.queryByPlaceholderText('Define value ')).not.toBeInTheDocument();
expect(screen.getAllByTestId('variable')).toHaveLength(1);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/containers/HSM/TemplateVariables/TemplateVariables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const TemplateVariables = ({
<div className={styles.Variables}>
{variables.length !== 0 && <h2>Set custom variable values for the message</h2>}
{variables.map((variable: any, index: number) => (
<div key={variable.id} className={styles.VariableContainer}>
<div data-testid="variable" key={variable.id} className={styles.VariableContainer}>
<div className={styles.Variable} key={index}>
<OutlinedInput
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export const ReachOutToUs = ({ open, setOpen, handleStepChange, saveData }: Reac
const [success, setSuccess] = useState(false);

const helperText = (
<p>
<span>
You can also reachout to us on <a href="mailto:support@glific.org">support@glific.org</a>.
</p>
</span>
);

const formFields = [
Expand Down
5 changes: 2 additions & 3 deletions src/containers/SpeedSend/SpeedSend.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@
}

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

.IsActive {
color: #555555;
font-weight: 400;
line-height: 18px;
font-size: 16px;
}
}
12 changes: 3 additions & 9 deletions src/containers/SpeedSend/SpeedSend.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ describe('test creating a speed send', () => {
});

test('should validate media', async () => {
mockedAxios.get.mockImplementationOnce(() =>
Promise.resolve({ data: { is_valid: true, message: 'valid media' } })
);
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: { is_valid: true, message: 'valid media' } }));

render(addSpeedSendContainer);

Expand Down Expand Up @@ -135,9 +133,7 @@ describe('test creating a speed send', () => {
});

test('should create a speed send', async () => {
mockedAxios.get.mockImplementationOnce(() =>
Promise.resolve({ data: { is_valid: true, message: 'valid media' } })
);
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: { is_valid: true, message: 'valid media' } }));

render(addSpeedSendContainer);

Expand Down Expand Up @@ -243,9 +239,7 @@ describe('test creating a speed send', () => {

describe('test editing a speed send', () => {
test('should render speed send form', async () => {
mockedAxios.get.mockImplementationOnce(() =>
Promise.resolve({ data: { is_valid: true, message: 'valid media' } })
);
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: { is_valid: true, message: 'valid media' } }));

render(editSpeedSendContainer('2'));

Expand Down
49 changes: 14 additions & 35 deletions src/containers/SpeedSend/SpeedSend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ export const SpeedSend = () => {
variables: { opts: { order: 'ASC' } },
});

const [getSessionTemplate, { data: template, loading: templateLoading }] =
useLazyQuery<any>(GET_SPEED_SEND);
const [getSessionTemplate, { data: template, loading: templateLoading }] = useLazyQuery<any>(GET_SPEED_SEND);

useEffect(() => {
if (languages) {
Expand Down Expand Up @@ -137,11 +136,7 @@ export const SpeedSend = () => {
const translationsCopy = JSON.parse(translationsValue);
const currentLanguage = language?.id || languageIdValue.id;

if (
Object.keys(translationsCopy).length > 0 &&
translationsCopy[currentLanguage] &&
!location.state?.language
) {
if (Object.keys(translationsCopy).length > 0 && translationsCopy[currentLanguage] && !location.state?.language) {
let content = translationsCopy[currentLanguage];
title = content.label;
body = content.body || '';
Expand All @@ -156,16 +151,12 @@ export const SpeedSend = () => {

if (languageOptions.length > 0 && languageIdValue) {
if (location.state && location.state !== 'copy') {
const selectedLangauge = languageOptions.find(
(lang: any) => lang.label === location.state.language
);
const selectedLangauge = languageOptions.find((lang: any) => lang.label === location.state.language);
navigate(location.pathname);

setLanguageId(selectedLangauge);
} else if (!language?.id) {
const selectedLangauge = languageOptions.find(
(lang: any) => lang.id === languageIdValue.id
);
const selectedLangauge = languageOptions.find((lang: any) => lang.id === languageIdValue.id);
setLanguageId(selectedLangauge);
} else {
setLanguageId(language);
Expand Down Expand Up @@ -307,9 +298,7 @@ export const SpeedSend = () => {
language: value,
label: translationsCopy[translationId].label,
body: translationsCopy[translationId].body,
type: translationsCopy[translationId].MessageMedia
? translationsCopy[translationId].MessageMedia.type
: null,
type: translationsCopy[translationId].MessageMedia ? translationsCopy[translationId].MessageMedia.type : null,
MessageMedia: translationsCopy[translationId].MessageMedia,
});
} else {
Expand All @@ -325,9 +314,7 @@ export const SpeedSend = () => {
};

const handleLanguageChange = (value: any) => {
const selected = languageOptions.find(
({ label: languageLabel }: any) => languageLabel === value
);
const selected = languageOptions.find(({ label: languageLabel }: any) => languageLabel === value);
if (selected && isEditing) {
updateTranslation(selected);
} else if (selected) {
Expand Down Expand Up @@ -360,21 +347,15 @@ export const SpeedSend = () => {
const displayWarning = () => {
if (type && type.id === 'STICKER') {
setWarning(
<div className={styles.Warning}>
<ol>
<li>{t('Animated stickers are not supported.')}</li>
<li>{t('Captions along with stickers are not supported.')}</li>
</ol>
</div>
<span className={styles.Warning}>
<span>{t('Animated stickers are not supported.')}</span>
<br />
<span>{t('Captions along with stickers are not supported.')}</span>
<span></span>
</span>
);
} else if (type && type.id === 'AUDIO') {
setWarning(
<div className={styles.Warning}>
<ol>
<li>{t('Captions along with audio are not supported.')}</li>
</ol>
</div>
);
setWarning(<span className={styles.Warning}>{t('Captions along with audio are not supported.')}</span>);
} else {
setWarning(null);
}
Expand All @@ -396,9 +377,7 @@ export const SpeedSend = () => {
is: (val: any) => val && val.id,
then: (schema) => schema.required(t('Attachment URL is required.')),
}),
body: Yup.string()
.required(t('Message is required.'))
.max(1024, 'Maximum 1024 characters are allowed'),
body: Yup.string().required(t('Message is required.')).max(1024, 'Maximum 1024 characters are allowed'),
},
[['type', 'attachmentURL']]
);
Expand Down
1 change: 1 addition & 0 deletions src/mocks/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ export const createAndSendMessageMutation = (input: any) => ({
body: 'Hey There Wow',
insertedAt: '2020-06-25T13:36:43Z',
id: '10388',
media: null,
receiver: {
id: '2',
},
Expand Down
12 changes: 1 addition & 11 deletions src/mocks/Collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,17 +453,7 @@ export const deleteContactFromCollection = {
export const getCollectionsList = (label?: any) => ({
request: {
query: GET_COLLECTIONS_LIST,
variables: {
filter: {
groupType: 'WABA',
label,
},
opts: {
limit: 50,
offset: 0,
order: 'ASC',
},
},
variables: { filter: { groupType: 'WABA', label: '' }, opts: { limit: 50, offset: 0, order: 'ASC' } },
},
result: {
data: {
Expand Down
10 changes: 10 additions & 0 deletions src/mocks/Groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,8 @@ export const waMessageReceivedSubscription = {
__typename: 'WaGroup',
id: '1',
},
poll: null,
pollContent: '{}',
},
},
},
Expand Down Expand Up @@ -867,6 +869,8 @@ export const waMessageSendSubscription = {
__typename: 'WaGroup',
id: '1',
},
poll: null,
pollContent: '{}',
},
},
},
Expand All @@ -893,6 +897,8 @@ export const waSentMessageCollectionQuery = {
contact: null,
contextMessage: null,
waGroup: null,
poll: null,
pollContent: '{}',
},
},
},
Expand All @@ -913,6 +919,8 @@ const updateWaSatatusMock = {
__typename: 'WaGroup',
id: '4',
},
poll: null,
pollContent: '{}',
},
},
},
Expand Down Expand Up @@ -1165,6 +1173,8 @@ export const getWaGroupQuery = {
id: '1',
label: 'Arkansas ducks',
lastCommunicationAt: '2024-03-28T10:41:18Z',
fields: '{}',
groups: null,
waManagedPhone: {
id: '1',
phone: '468/236-8754',
Expand Down

0 comments on commit 13184f5

Please sign in to comment.