1 import { fireEvent, render, waitFor } from '@testing-library/react';
3 import DailyEmailNotificationToggle from './DailyEmailNotificationToggle';
5 describe('DailyEmailNotificationToggle', () => {
6 describe('when annot enable', () => {
7 it('should have disabled attribute', () => {
8 const { container } = render(
9 <DailyEmailNotificationToggle
17 const input = container.querySelector('#test-toggle');
18 expect(input).toHaveAttribute('disabled', '');
22 describe('when can enable', () => {
23 it('should check checkbox if enabled', () => {
24 const { container } = render(
25 <DailyEmailNotificationToggle canEnable={true} isEnabled={true} onChange={jest.fn()} id="test-toggle" />
28 const input = container.querySelector('#test-toggle');
29 expect(input).not.toHaveAttribute('disabled');
30 expect(input).toHaveAttribute('checked', '');
33 it('should emit onChange on click', async () => {
34 const mockOnChange = jest.fn();
35 const { container } = render(
36 <DailyEmailNotificationToggle
39 onChange={mockOnChange}
44 const input = container.querySelector('#test-toggle');
45 fireEvent.click(input as HTMLElement);
47 await waitFor(() => expect(mockOnChange).toHaveBeenCalledTimes(1));