Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zuies committed Feb 23, 2024
1 parent 127ea53 commit f2f11ff
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface ITcConfirmSchaduledAnnouncementsDialogProps {
selectedChannels: { id: string; label: string }[];
selectedRoles?: IRoles[];
selectedUsernames?: IUser[];
selectedEngagementCategories?: string[];
schaduledDate: string;
isDisabled: boolean;
handleCreateAnnouncements: (isDrafted: boolean) => void;
Expand All @@ -35,6 +36,7 @@ function TcConfirmSchaduledAnnouncementsDialog({
buttonLabel,
schaduledDate,
selectedRoles,
selectedEngagementCategories,
selectedUsernames,
selectedChannels,
isDisabled = true,
Expand Down Expand Up @@ -155,6 +157,32 @@ function TcConfirmSchaduledAnnouncementsDialog({
) : (
''
)}
{selectedEngagementCategories &&
selectedEngagementCategories.length > 0 ? (
<div className='flex flex-col'>
<div className='flex items-center justify-between'>
<TcText
text='Engagement Categories:'
fontWeight={500}
variant='subtitle2'
className='text-left text-gray-400'
/>
<TcText
text={
schaduledDate
? formatDateToLocalTimezone(schaduledDate)
: ''
}
variant='subtitle2'
/>
</div>
{selectedEngagementCategories
.join(', ')
.replaceAll('_', ' ')}
</div>
) : (
''
)}
</div>
<div className='w-full py-6'>
<TcButton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { render, screen } from '@testing-library/react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import React from 'react';

import TcPublicMessageContainer from './TcPublicMessageContainer';
import { TokenContext } from '../../../../context/TokenContext';
import {
ChannelContext,
initialChannelContextData,
} from '../../../../context/ChannelContext';

const mockToken = {
accessToken: 'mockAccessToken',
Expand All @@ -27,25 +31,26 @@ const mockTokenContextValue = {
};

describe('TcPublicMessageContainer', () => {
beforeEach(() => {
const setup = () =>
render(
<TokenContext.Provider value={mockTokenContextValue}>
<TcPublicMessageContainer handlePublicAnnouncements={jest.fn()} />
<ChannelContext.Provider value={initialChannelContextData}>
<TcPublicMessageContainer handlePublicAnnouncements={jest.fn()} />
</ChannelContext.Provider>
</TokenContext.Provider>
);
});

it('renders the "Public Message" text', () => {
expect(screen.getByText(/Public Message/i)).toBeInTheDocument();
});
it('should toggle public message state and render related UI elements', async () => {
setup();

it('renders the message about bot distribute', () => {
const message =
/Our bot will distribute the announcement through selected channels with the required access to share the designated message./i;
expect(screen.getByText(message)).toBeInTheDocument();
});
const switchElement = screen.getByRole('checkbox');
fireEvent.click(switchElement);

it('renders the "Write message here:" text', () => {
expect(screen.getByText(/Write message here:/i)).toBeInTheDocument();
expect(
screen.getByText(
/Our bot will distribute the announcement through selected channels with the required access to share the designated message./i
)
).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion src/context/ChannelContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const initialChannels: Channel[] = [];

const initialSelectedSubChannels: SelectedSubChannels = {};

const initialChannelContextData: ChannelContextProps = {
export const initialChannelContextData: ChannelContextProps = {
channels: initialChannels,
loading: false,
selectedSubChannels: initialSelectedSubChannels,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/announcements/edit-announcements/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ function Index() {
data.push(...privateAnnouncements);
}

const announcementsPayload = {
communityId: community.id,
const announcementPayload = {
draft: isDrafted,
scheduledAt: scheduledAt,
data: data,
Expand All @@ -168,7 +167,7 @@ function Index() {

const data = await patchExistingAnnouncement({
id,
announcementsPayload,
announcementPayload,
});

if (data) {
Expand Down Expand Up @@ -325,6 +324,7 @@ function Index() {
selectedChannels={channels}
selectedRoles={roles}
selectedUsernames={users}
selectedEngagementCategories={engagementCategories}
schaduledDate={scheduledAt || ''}
isDisabled={
!scheduledAt ||
Expand Down

0 comments on commit f2f11ff

Please sign in to comment.