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

test: Add unit tests for processChatDisabled function #254

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
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
65 changes: 65 additions & 0 deletions __tests__/services/BlockService/ChatDisabledProcessor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { processChatDisabled } from '../../../src/services/BlockService/ChatDisabledProcessor';
import { Block } from '../../../src/types/Block';
import { Params } from '../../../src/types/Params';

describe('processChatDisabled', () => {
let mockSetTextAreaDisabled: jest.Mock;
let params: Params;

beforeEach(() => {
mockSetTextAreaDisabled = jest.fn();
params = {} as Params;
});

afterEach(() => {
jest.clearAllMocks();
});

it('should not change textarea state if chatDisabled is null', async () => {
const block= { chatDisabled: null } as unknown as Block;

await processChatDisabled(block, mockSetTextAreaDisabled, params);

expect(mockSetTextAreaDisabled).not.toHaveBeenCalled();
});

it('should not change textarea state if chatDisabled is undefined', async () => {
const block: Block = { chatDisabled: undefined };

await processChatDisabled(block, mockSetTextAreaDisabled, params);

expect(mockSetTextAreaDisabled).not.toHaveBeenCalled();
});

it('should set textarea disabled state to true if chatDisabled is true', async () => {
const block: Block = { chatDisabled: true };

await processChatDisabled(block, mockSetTextAreaDisabled, params);

expect(mockSetTextAreaDisabled).toHaveBeenCalledWith(true);
});

it('should set textarea disabled state to false if chatDisabled is false', async () => {
const block: Block = { chatDisabled: false };

await processChatDisabled(block, mockSetTextAreaDisabled, params);

expect(mockSetTextAreaDisabled).toHaveBeenCalledWith(false);
});

it('should call chatDisabled function and set textarea state accordingly', async () => {
const block: Block = { chatDisabled: jest.fn(() => false) };

await processChatDisabled(block, mockSetTextAreaDisabled, params);

expect(mockSetTextAreaDisabled).toHaveBeenCalledWith(false);
});

it('should handle async chatDisabled function correctly', async () => {
const block: Block = { chatDisabled: jest.fn(async () => true) };

await processChatDisabled(block, mockSetTextAreaDisabled, params);

expect(mockSetTextAreaDisabled).toHaveBeenCalledWith(true);
});
});