Skip to main content

useProjectForm Hook

Overview

This test suite covers the functionality of the useProjectForm hook, which is responsible for handling the logic behind project forms.

Test cases

Test: Initialize form with initial values

  • Description: Verifies that a form is created with the initial values provided.
  • Setup: Mock the useProjectForm hook to return a mock form object with the initial values.
  • Expectation: The hook creates a new form with the initial values using the useForm function.

Test: Handle Custom Images

  • Description: Verifies that a form's image is changed successfully when there is a custom file input.
  • Setup: Mock the useProjectForm hook to return a mock form object with no initial values.
  • Expectation: The form's image and defaultImage value change to the File input and false respectively.

Test: Handle Default Images

  • Description: Verifies that a form's image is changed successfully when there is a default image input.
  • Setup: Mock the useProjectForm hook to return a mock form object with no initial values.
  • Expectation: The form's image and defaultImage value change to the path of the selected default image and true respectively.

Test: Clear Image

  • Description: Verifies that a form's image can be cleared successfully.
  • Setup: Mock the useProjectForm hook to return a mock form object with no initial values.
  • Expectation: The form's image and defaultImage value change to the path of the first selected default image and true respectively.

Test: Reset Form

  • Description: Verifies that the form's value is cleared.
  • Setup: Mock the useProjectForm hook to return a mock form object with no initial values.
  • Expectation: The reset function of useForm and the modals.closeAll function is called.

Test: Submit Form ( Create ) successfully

  • Description: Verifies that the form's submit function for creating form is called successfully.
  • Setup: Mock the useProjectForm hook with no initial values and addProjectMutation function.
  • Expectation: The addProjectMutation function is called successfully.

Test: Submit Form ( Edit ) successfully

  • Description: Verifies that the form's submit function for editing form is called successfully.
  • Setup: Mock the useProjectForm hook with initial values and editProjectMutation function.
  • Expectation: The editProjectMutation function is called successfully.