Skip to content

Commit

Permalink
added testcases for BotStatesContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Suvrat1629 committed Oct 21, 2024
1 parent 7ac4ac6 commit 103e95b
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions __tests__/components/context/BotStatesContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,69 @@ import '@testing-library/jest-dom';


const TestComponent = () => {
const {
isBotTyping,
setIsBotTyping,
isChatWindowOpen,
setIsChatWindowOpen,
} = useBotStatesContext();
const {
isBotTyping,
setIsBotTyping,
isChatWindowOpen,
setIsChatWindowOpen,
} = useBotStatesContext();

return (
<div>
<p>Bot Typing: {isBotTyping ? 'Yes' : 'No'}</p>
<button onClick={() => setIsBotTyping(!isBotTyping)}>
Toggle Bot Typing
</button>
<p>Chat Window Open: {isChatWindowOpen ? 'Yes' : 'No'}</p>
<button onClick={() => setIsChatWindowOpen(!isChatWindowOpen)}>
Toggle Chat Window
</button>
</div>
);
return (
<div>
<p>Bot Typing: {isBotTyping ? 'Yes' : 'No'}</p>
<button onClick={() => setIsBotTyping(!isBotTyping)}>
Toggle Bot Typing
</button>
<p>Chat Window Open: {isChatWindowOpen ? 'Yes' : 'No'}</p>
<button onClick={() => setIsChatWindowOpen(!isChatWindowOpen)}>
Toggle Chat Window
</button>
</div>
);
};

describe('BotStatesProvider', () => {
const renderWithProvider = (children: React.ReactNode, settings = {}) => {
return render(
<BotStatesProvider settings={settings}>
{children}
</BotStatesProvider>
);
};
const renderWithProvider = (children: React.ReactNode, settings = {}) => {
return render(
<BotStatesProvider settings={settings}>
{children}
</BotStatesProvider>
);
};

it('should initialize with default values', () => {
renderWithProvider(<TestComponent />);
it('should initialize with default values', () => {
renderWithProvider(<TestComponent />);

expect(screen.getByText(/Bot Typing: No/i)).toBeInTheDocument();
expect(screen.getByText(/Chat Window Open: No/i)).toBeInTheDocument();
});
expect(screen.getByText(/Bot Typing: No/i)).toBeInTheDocument();
expect(screen.getByText(/Chat Window Open: No/i)).toBeInTheDocument();
});

it('should toggle bot typing state', () => {
renderWithProvider(<TestComponent />);
it('should toggle bot typing state', () => {
renderWithProvider(<TestComponent />);

const toggleButton = screen.getByRole('button', { name: /Toggle Bot Typing/i });
fireEvent.click(toggleButton);
const toggleButton = screen.getByRole('button', { name: /Toggle Bot Typing/i });
fireEvent.click(toggleButton);

expect(screen.getByText(/Bot Typing: Yes/i)).toBeInTheDocument();
});
expect(screen.getByText(/Bot Typing: Yes/i)).toBeInTheDocument();
});

it('should toggle chat window state', () => {
renderWithProvider(<TestComponent />);
it('should toggle chat window state', () => {
renderWithProvider(<TestComponent />);

const toggleButton = screen.getByRole('button', { name: /Toggle Chat Window/i });
fireEvent.click(toggleButton);
const toggleButton = screen.getByRole('button', { name: /Toggle Chat Window/i });
fireEvent.click(toggleButton);

expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument();
});
expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument();
});

it('should respect initial settings', () => {
const settings = {
chatWindow: { defaultOpen: true },
audio: { defaultToggledOn: true },
};
it('should respect initial settings', () => {
const settings = {
chatWindow: { defaultOpen: true },
audio: { defaultToggledOn: true },
};

renderWithProvider(<TestComponent />, settings);
renderWithProvider(<TestComponent />, settings);

expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument();
});
expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument();
});
});

0 comments on commit 103e95b

Please sign in to comment.