Integration Guides

croissant-opt-in-input

Initialization

Test Case: Verify Initial Opt-In Status

Description: Confirm that the Croissant Opt-In Input initializes correctly based on the opt-in status stored in local storage.

Assertion:

  • Assert that the checkbox is checked if the local storage indicates the user is opted in.
  • Assert that the checkbox is not checked if the user is opted out or if there is no opt-in status in local storage.

User Interaction

Test Case: Change Opt-In Status

Description: Verify that interacting with the checkbox updates the opt-in status correctly, both in the component state and in local storage.

Assertion:

  • Trigger a change event on the checkbox input.
  • Assert that the isOptedIn state updates to reflect the new status.
  • Assert that local storage is updated with the new opt-in status.
  • Assert that the emitCroissantEvent function is called with the correct parameters.

Toast Notification

Test Case: Display Toast on Opt-In/Opt-Out

Description: Ensure that the toast notifications for opt-in and opt-out actions are displayed correctly when isToastEnabled is true.

Assertion:

  • Enable toast notifications by setting isToastEnabled to true.
  • Trigger opt-in and opt-out actions.
  • Assert that the appropriate toast notification (showOptedInToast or showOptedOutToast) is displayed upon opt-in and opt-out.

Test Case: No Toast When Disabled

Description: Confirm that no toast notifications are displayed when isToastEnabled is false.

Assertion:

  • Set isToastEnabled to false.
  • Trigger opt-in and opt-out actions.
  • Assert that no toast notifications are shown.

Accessibility

Test Case: Verify Accessibility Attributes

Description: Confirm that the checkbox input is properly labeled for accessibility, using the label prop if provided.

Assertion:

  • Assert that the checkbox has a properly set an aria-label.
  • If the aria-label is overwritten with a blank string or removed, assert that the labelis set.

Custom Styling

Test Case: Apply Custom Checkbox Class

Description: Verify that a custom class can be applied to the checkbox container.

Assertion:

  • Render the component with a customCheckboxClass.
  • Assert that the custom class is applied to the checkbox container.

Reactivity to External Changes

Test Case: Update Opt-In Status on External Changes

Description: Ensure that the component correctly reacts to external changes in opt-in status, such as those made by other instances or components.

Assertion:

  • Assert that the checkbox styling has sufficient contrast to be accessible check and unchecked.
  • Simulate an external change in opt-in status (e.g., through another component or directly in local storage).
  • Assert that the component updates its displayed opt-in status accordingly.