Dialogue Box Service Testing - UQcsse3200/2024-studio-2 GitHub Wiki
Both the Dialogue Box and Dialogue Box Service are tested in parallel. This makes sense as in the design process the Dialogue Box Service was made to be the only interface between some method / class and the Dialogue Box.
DialogueBoxServiceTest
This class contains unit tests for the DialogueBoxService
class, which manages the display and functionality of dialogue boxes in the game. It ensures that various features of the DialogueBoxService
are working as expected.
Class-level Annotations:
@ExtendWith(GameExtension.class)
: Integrates with the game's extension to set up the necessary environment for testing.
Fields:
private DialogueBoxService entityChatService;
: Instance of theDialogueBoxService
to be tested.private static final Skin SKIN;
: Skin used for rendering UI elements.Stage stage;
: Mock stage used for rendering and UI interactions.
Setup:
@BeforeEach
: Initialises the necessary services and mocks before each test.
Test Methods
-
hideChatBox
: Verifies that hiding the dialogue box works as intended.- Checks:
- The dialogue box is initially visible.
- The dialogue box becomes hidden when
hideCurrentOverlay()
is called.
- Checks:
-
shouldCreateEntityChat
: Ensures that the dialogue box is created and updated correctly with the provided text.- Checks:
- The dialogue box is created successfully.
- The hints array matches the input text.
- Checks:
-
testButtonPresses
: Tests the functionality of the forward and backward buttons in the dialogue box.- Checks:
- The forward button cycles through the hints in the correct order.
- The backward button cycles through the hints in reverse order.
- Checks:
-
testOptionButtonPresses
: Tests the functionality of the option buttons in the dialogue box.- Checks:
- Tests if the clicking on the options changes the dialogue box's text into the appropriate ones.
- Checks:
-
shouldRemoveEntityChat
: Validates that the dialogue box can be properly disposed of.- Checks:
- The dialogue box is removed when
disposeCurrentOverlay()
is called. - The
currentOverlay
becomesnull
.
- The dialogue box is removed when
- Checks:
-
illegalDispose
: Tests the behavior of disposing the dialogue box when it has already been disposed.- Checks:
- Ensures that calling
disposeCurrentOverlay()
on an already disposed dialogue box does not cause errors and results innull
currentOverlay
.
- Ensures that calling
- Checks:
-
shouldUpdateEntityChat
: Confirms that updating the dialogue box with new text works correctly.- Checks:
- The dialogue box displays the updated text.
- The hints array reflects the updated text correctly.
- Checks:
-
buttonsExist
: Checks that the forward and backward buttons exist and are properly initialised.- Checks:
- The forward and backward buttons are not
null
when the dialogue box is updated with new text.
- The forward and backward buttons are not
- Checks:
Related to this there is the left and right arrow control of the dialogue box hints as well. These tests are included in this documentation as it relates specifically to the dialogue box testing. These have been tested in the KeyboardDialogueBoxInputComponentTest file. Specific testing for this includes:
testKeyDownRightArrow()
: Simulates pressing the RIGHT arrow key.
- Checks:
- Calls
dialogueBoxService.getCurrentOverlay()
. - Triggers
dialogueBox.handleForwardButtonClick()
.
- Calls
testKeyDownLeftArrow()
: Simulates pressing the LEFT arrow key.
- Checks:
- Calls
dialogueBoxService.getCurrentOverlay()
. - Triggers
dialogueBox.handleBackwardButtonClick()
.
- Calls
testKeyUp()
: Simulates releasing the RIGHT arrow key.
- Checks:
- Returns
true
, indicating the key release was processed.
- Returns
testKeyDownWhenDisabled()
: Simulates pressing the RIGHT arrow key when the component is disabled.
- Checks:
- Returns
false
, indicating input is ignored.
- Returns
Furthermore, entities that are interacting with the player will have an outline. The following tests check for the correct implementation and functionality.
shouldReturnCorrectVisibilityBoolean()
:
- Checks:
- Returns false when overlay is not visible and true when it is.
shouldHighlightEntitySprite()
:
- Checks:
- The current NPC has the correct animator "selected" which has the outline.
- The hints are updated correctly
shouldUnhighlightEntitySprite()
:
- Checks:
- The current NPC has the correct animator "float" which does not have the outline as it is no longer interacting with the player.
shouldNotStartFloatAnimationIfNoPreviousEntity()
:
- Checks:
- The current NPC remains selected and outlined as the text is updated.
shouldUnhighlightEntitySpriteAndHighlightNewEntity()
:
- Checks:
- The interaction when a player stops interacting with one NPC and interacts with another.
- This ensures that the old NPC is unselected and the new NPC is selected.
shouldStartAnimationWhenAnimatorIsNotNull()
:
- Checks:
- The NPC is highlighted when interacting with player.
Additionally, testing UI and resizing of elements present a large challenge hence the resizing methods inside the DialogueBoxService and DialogueBox were visually tested. Such methods include: DialogueBoxService::resizeElements and DialogueBox::resizeElements. To see this please see the video below: