-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from TogetherCrew/feat/announcements-mvp-change
Feat/announcements mvp changes
- Loading branch information
Showing
5 changed files
with
62 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 39 additions & 68 deletions
107
src/components/announcements/create/publicMessageContainer/TcPublicMessageContainer.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,60 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { render, screen } from '@testing-library/react'; | ||
import TcPublicMessageContainer from './TcPublicMessageContainer'; | ||
import { ChannelContext } from '../../../../context/ChannelContext'; | ||
import { TokenContext } from '../../../../context/TokenContext'; | ||
|
||
const mockChannels = [ | ||
{ channelId: '1131241242', title: 'Channel 1', subChannels: [] }, | ||
{ channelId: '1242512553', title: 'Channel 2', subChannels: [] }, | ||
]; | ||
const mockToken = { | ||
accessToken: 'mockAccessToken', | ||
refreshToken: 'mockRefreshToken', | ||
}; | ||
|
||
const mockSelectedSubChannels = { | ||
channel1: { '1131241242': true }, | ||
channel2: { '1242512553': true }, | ||
const mockCommunity = { | ||
name: 'Test Community', | ||
platforms: [], | ||
id: 'mockCommunityId', | ||
users: [], | ||
avatarURL: 'mockAvatarURL', | ||
}; | ||
|
||
const mockChannelContext = { | ||
channels: mockChannels, | ||
selectedSubChannels: mockSelectedSubChannels, | ||
loading: false, | ||
refreshData: jest.fn(), | ||
handleSubChannelChange: jest.fn(), | ||
handleSelectAll: jest.fn(), | ||
updateSelectedSubChannels: jest.fn(), | ||
const mockTokenContextValue = { | ||
token: mockToken, | ||
community: mockCommunity, | ||
updateToken: jest.fn(), | ||
updateCommunity: jest.fn(), | ||
deleteCommunity: jest.fn(), | ||
clearToken: jest.fn(), | ||
}; | ||
|
||
describe('TcPublicMessageContainer Tests', () => { | ||
// Helper function to render the component with the necessary context | ||
const renderComponent = (handlePublicAnnouncements = jest.fn()) => | ||
describe('TcPublicMessageContainer', () => { | ||
beforeEach(() => { | ||
render( | ||
<ChannelContext.Provider value={mockChannelContext}> | ||
<TcPublicMessageContainer | ||
handlePublicAnnouncements={handlePublicAnnouncements} | ||
/> | ||
</ChannelContext.Provider> | ||
<TokenContext.Provider value={mockTokenContextValue}> | ||
<TcPublicMessageContainer handlePublicAnnouncements={jest.fn()} /> | ||
</TokenContext.Provider> | ||
); | ||
|
||
test('renders the component without crashing', () => { | ||
renderComponent(); | ||
expect(screen.getByText('Public Message')).toBeInTheDocument(); | ||
}); | ||
|
||
test('initial state is set correctly', () => { | ||
renderComponent(); | ||
expect(screen.getByPlaceholderText('Write your message here')).toHaveValue( | ||
'' | ||
); | ||
it('renders the "Public Message" text', () => { | ||
expect(screen.getByText(/Public Message/i)).toBeInTheDocument(); | ||
}); | ||
|
||
test('allows the user to enter a message', () => { | ||
renderComponent(); | ||
const messageInput = screen.getByPlaceholderText( | ||
'Write your message here' | ||
) as HTMLInputElement; | ||
fireEvent.change(messageInput, { target: { value: 'Test Message' } }); | ||
expect(messageInput.value).toBe('Test Message'); | ||
it('renders the "Send message to:" text', () => { | ||
expect(screen.getByText(/Send message to:/i)).toBeInTheDocument(); | ||
}); | ||
|
||
test('select channels dropdown is rendered', () => { | ||
renderComponent(); | ||
expect(screen.getByLabelText('Select Channels')).toBeInTheDocument(); | ||
it('renders the message about bot delivery', () => { | ||
const message = | ||
/Our bot will deliver the announcement across chosen channels with the necessary access to share the specified message\./i; | ||
expect(screen.getByText(message)).toBeInTheDocument(); | ||
}); | ||
|
||
test('handlePublicAnnouncements is called with correct data', () => { | ||
const handlePublicAnnouncementsMock = jest.fn(); | ||
renderComponent(handlePublicAnnouncementsMock); | ||
|
||
// Assuming there is a way to select channels in your UI, simulate that | ||
// For example, if there's a button to confirm channel selection: | ||
// fireEvent.click(screen.getByText('Confirm Channels')); | ||
|
||
// Simulate entering a message | ||
const messageInput = screen.getByPlaceholderText( | ||
'Write your message here' | ||
) as HTMLInputElement; | ||
fireEvent.change(messageInput, { target: { value: 'Test Message' } }); | ||
|
||
// Assuming the function is called on some action, like a form submission or button click | ||
// fireEvent.click(screen.getByText('Submit')); | ||
it('renders the "Write message here:" text', () => { | ||
expect(screen.getByText(/Write message here:/i)).toBeInTheDocument(); | ||
}); | ||
|
||
// Check if handlePublicAnnouncementsMock was called correctly | ||
// Expect the mock to have been called with expected message and channels data | ||
// This will depend on how your component calls the handlePublicAnnouncements function | ||
expect(handlePublicAnnouncementsMock).toHaveBeenCalledWith({ | ||
message: 'Test Message', | ||
selectedChannels: expect.anything(), // Replace with specific expectation | ||
}); | ||
it('renders the auto-generated safety message prompt', () => { | ||
const message = | ||
/If you don’t write a custom message then this auto-generated safety message wlll be sent out/i; | ||
expect(screen.getByText(message)).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters