Skip to content

Commit

Permalink
added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
akanshaaa19 committed Feb 19, 2025
1 parent 7997c1d commit c247dd1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
22 changes: 22 additions & 0 deletions src/containers/WaGroups/WaPolls/WaPolls.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ const mockUseLocationValue: any = {
state: null,
};

vi.mock('../../../components/UI/EmojiPicker/EmojiPicker', () => ({
default: ({ onEmojiSelect }: { onEmojiSelect: (emoji: any) => void }) => (
<div data-testid="emoji-container">
<button
data-testid="mock-emoji-picker"
onClick={() =>
onEmojiSelect({
native: '😃',
})
}
>
Mock Emoji Picker
</button>
</div>
),
}));

vi.mock('react-router-dom', async () => ({
...((await vi.importActual<any>('react-router-dom')) as {}),
useLocation: () => {
Expand Down Expand Up @@ -52,6 +69,11 @@ describe('Create', () => {
fireEvent.change(screen.getByPlaceholderText('Option 1'), { target: { value: 'Option 1' } });
fireEvent.change(screen.getByPlaceholderText('Option 2'), { target: { value: 'Option 2' } });

fireEvent.click(screen.getAllByTestId('emoji-picker')[0]);

expect(screen.getByTestId('emoji-container')).toBeInTheDocument();
fireEvent.click(screen.getByTestId('mock-emoji-picker'));

fireEvent.click(screen.getByTestId('add-btn'));

fireEvent.change(screen.getByPlaceholderText('Option 3'), { target: { value: 'Option 3' } });
Expand Down
6 changes: 1 addition & 5 deletions src/containers/WaGroups/WaPolls/WaPollsList/WaPollsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ const queries = {
const getLabel = (label: string) => <div className={styles.LabelText}>{label}</div>;

const getContent = (content: string) => {
return (
<div className={styles.ContentText}>
{content ? (content.length < 100 ? content : `${content.slice(0, 100)}...`) : ''}
</div>
);
return <div className={styles.ContentText}>{content.length < 100 ? content : `${content.slice(0, 100)}...`}</div>;
};
export const WaPollsList = () => {
const [deleteWaPollId, setDeleteWaPollId] = useState<string | null>(null);
Expand Down
26 changes: 20 additions & 6 deletions src/mocks/Groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,16 @@ export const waGroup = {
media: null,
messageNumber: 4,
status: 'sent',
type: 'TEXT',
poll: null,
pollContent: '{}',
type: 'POLL',
poll: {
__typename: 'WaPoll',
allowMultipleAnswer: false,
id: '4',
pollContent:
'{"text": "this is a poll", "options": [{ "votes": 1, "name": "option 1", "id": 0 },{ "votes": 1, "name": "option 2", "id": 1 },{ "votes": 0, "name": "okay option 4", "id": 2 }]}',
},
pollContent:
'{"text": "this is a poll", "options": [{ "votes": 1, "name": "option 1", "id": 0 },{ "votes": 1, "name": "option 2", "id": 1 },{ "votes": 0, "name": "okay option 4", "id": 2 }]}',
},
{
__typename: 'WaMessage',
Expand Down Expand Up @@ -130,9 +137,16 @@ const sampleMessage = {
media: null,
messageNumber: 1,
status: 'received',
type: 'TEXT',
poll: null,
pollContent: '{}',
type: 'POLL',
poll: {
__typename: 'WaPoll',
allowMultipleAnswer: false,
id: '4',
pollContent:
'{"text": "this is a poll", "options": [{ "votes": 1, "name": "option 1", "id": 0 },{ "votes": 1, "name": "option 2", "id": 1 },{ "votes": 0, "name": "okay option 4", "id": 2 }]}',
},
pollContent:
'{"text": "this is a poll", "options": [{ "votes": 1, "name": "option 1", "id": 0 },{ "votes": 1, "name": "option 2", "id": 1 },{ "votes": 0, "name": "okay option 4", "id": 2 }]}',
};

const sampleSearchQueryResult = [
Expand Down
8 changes: 7 additions & 1 deletion src/mocks/WaPolls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { GET_POLL, GET_POLLS, GET_POLLS_COUNT } from 'graphql/queries/WaPolls';
const createPoll = {
request: {
query: CREATE_POLL,
variables: {
input: {
label: 'Poll Title',
poll_content: '{"options":[{"id":0,"name":"Option 1😃"},{"name":"Option 3","id":2}],"text":"Poll Content"}',
allow_multiple_answer: true,
},
},
},
result: {
data: {
Expand All @@ -16,7 +23,6 @@ const createPoll = {
},
},
},
variableMatcher: () => true,
};

const getPoll = {
Expand Down

0 comments on commit c247dd1

Please sign in to comment.