From 8105b8fffd29f4c42d4b5156e30fd4adf170856b Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 16:38:23 +0100 Subject: [PATCH] test_SignUpGUI button actions --- src/main/java/SignUpGUI.java | 26 ++++++++++++++++++++++++ src/test/java/LoginGUITest.java | 12 ++++++----- src/test/java/SignUpGUITest.java | 35 ++++++++++++++++++++++++++++++++ user.json | 9 ++++++++ 4 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 src/test/java/SignUpGUITest.java diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java index 2f31890..51a3e47 100644 --- a/src/main/java/SignUpGUI.java +++ b/src/main/java/SignUpGUI.java @@ -7,6 +7,32 @@ import java.util.UUID; public class SignUpGUI extends JFrame implements ActionListener { private JTextField usernameField, passwordField, confirmPasswordField, birthdayField, firstNameField, surnameField; private JButton signUpButton; + + public JTextField getUsernameField() { + return usernameField; + } + + public JTextField getPasswordField() { + return passwordField; + } + + + public JTextField getConfirmPasswordField() { + return confirmPasswordField; + } + + public JTextField getBirthdayField() { + return birthdayField; + } + public JTextField getFirstNameField() { + return firstNameField; + } + public JTextField getSurnameField() { + return surnameField; + } + public JButton getSignUpButton() { + return signUpButton; + } public SignUpGUI() { setTitle("Sign Up"); diff --git a/src/test/java/LoginGUITest.java b/src/test/java/LoginGUITest.java index 2fceb23..b2b6184 100644 --- a/src/test/java/LoginGUITest.java +++ b/src/test/java/LoginGUITest.java @@ -37,14 +37,16 @@ class LoginGUITest { @Test public void testStayLoggedInCheckbox() { - // Initially, checkbox should be unchecked - assertFalse(loginGUI.getStayLoggedInCheckbox().isSelected()); + // Initially, checkbox should be unchecked + assertFalse(loginGUI.getStayLoggedInCheckbox().isSelected()); - // Simulate checking the checkbox - loginGUI.getStayLoggedInCheckbox().doClick(); + // Simulate checking the checkbox + loginGUI.getStayLoggedInCheckbox().doClick(); - assertTrue(loginGUI.getStayLoggedInCheckbox().isSelected()); + assertTrue(loginGUI.getStayLoggedInCheckbox().isSelected()); } + + } diff --git a/src/test/java/SignUpGUITest.java b/src/test/java/SignUpGUITest.java new file mode 100644 index 0000000..083e042 --- /dev/null +++ b/src/test/java/SignUpGUITest.java @@ -0,0 +1,35 @@ +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; + + + class SignUpGUITest { + private SignUpGUI signUpGUI; + + @BeforeEach + void setUp() { + signUpGUI = new SignUpGUI(); + signUpGUI.setVisible(true); + } + + @AfterEach + void tearDown() { + signUpGUI.dispose(); + } + + @Test + void testSignUpButtonActionPerformed() { + signUpGUI.getUsernameField().setText("testuser"); + signUpGUI.getPasswordField().setText("password"); + signUpGUI.getConfirmPasswordField().setText("password"); + signUpGUI.getBirthdayField().setText("2000-01-01"); + signUpGUI.getFirstNameField().setText("John"); + signUpGUI.getSurnameField().setText("Doe"); + + signUpGUI.getSignUpButton().doClick(); + + assertFalse(signUpGUI.isVisible()); + } + +} diff --git a/user.json b/user.json index 29df4e8..35bdc9d 100644 --- a/user.json +++ b/user.json @@ -16,5 +16,14 @@ "firstName": "", "surname": "", "stayLoggedIn": false + }, + { + "id": "ccfcc294-48ad-49db-996f-d7c99a93bac9", + "userName": "testuser", + "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", + "birthday": "2000-01-01", + "firstName": "John", + "surname": "Doe", + "stayLoggedIn": false } ] \ No newline at end of file