Keyboard Dialogue Box Input Component Testing - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

This document outlines the testing strategy and objectives for the KeyboardDialogueBoxInputComponent class in the com.csse3200.game.ui.dialoguebox package. The aim is to ensure that the component correctly processes keyboard inputs and interacts properly with the DialogueBoxService and its overlay (left and right arrow). This has 100% coverage for the keyboard input handling for the Dialogue Box.

Test Cases

1. Setup

  • Objective: Initialise the necessary components and mock services.
  • Method: setUp()
  • Actions:
    • Instantiate KeyboardDialogueBoxInputComponent.
    • Create a mock instance of DialogueBoxService.
    • Create a mock instance of DialogueBox.
    • Configure mocks to return expected values when queried.
    • Register the mock DialogueBoxService with ServiceLocator.

2. Test Key Down Right Arrow

  • Objective: Verify that pressing the right arrow key triggers the correct overlay method.
  • Method: testKeyDownRightArrow()
  • Actions:
    • Simulate key press for the right arrow key.
    • Verify that getCurrentOverlay() is called on dialogueBoxService.
    • Verify that handleForwardButtonClick() is called on the mock overlay.

3. Test Key Down Left Arrow

  • Objective: Verify that pressing the left arrow key triggers the correct overlay method.
  • Method: testKeyDownLeftArrow()
  • Actions:
    • Simulate key press for the left arrow key.
    • Verify that getCurrentOverlay() is called on dialogueBoxService.
    • Verify that handleBackwardButtonClick() is called on the mock overlay.

4. Test Key Up

  • Objective: Ensure that releasing a key is processed correctly.
  • Method: testKeyUp()
  • Actions:
    • Simulate key press for the right arrow key.
    • Simulate key release for the right arrow key.
    • Assert that the result is true, indicating successful processing of the key release.

5. Test Key Down When Disabled

  • Objective: Validate that input is not processed when the component is disabled.
  • Method: testKeyDownWhenDisabled()
  • Actions:
    • Disable the KeyboardDialogueBoxInputComponent.
    • Simulate key press for the right arrow key.
    • Assert that the result is false, indicating that input processing is correctly prevented.