Selaa lähdekoodia

test: turn meaningless Prompt test into something actually useful

Previously it did not even call the SUT, but just asserted that a value was written intoi a code it had itself generated.
rugk 1 kuukausi sitten
vanhempi
sitoutus
795df42b31
1 muutettua tiedostoa jossa 15 lisäystä ja 1 poistoa
  1. 15 1
      js/test/Prompt.js

+ 15 - 1
js/test/Prompt.js

@@ -21,9 +21,23 @@ describe('Prompt', function () {
                         'password"></div><button type="submit">Decrypt</button>' +
                         '</form></div></div></div></div>'
                     );
+
+                    // Initialize the Prompt module to set up event listeners
+                    PrivateBin.Prompt.init();
+                    PrivateBin.Prompt.requestPassword();
+
+                    // Simulate user input
                     const passwordInput = document.getElementById('passworddecrypt');
                     passwordInput.value = password;
-                    const result = passwordInput.value;
+
+                    // Simulate form submission to trigger password capture
+                    const passwordForm = document.getElementById('passwordform');
+                    /** {@type SubmitEvent} */
+                    const submitEvent = new Event('submit', { bubbles: true, cancelable: true });
+                    passwordForm.dispatchEvent(submitEvent);
+
+                    // Verify that getPassword returns the submitted password
+                    const result = PrivateBin.Prompt.getPassword();
                     clean();
                     return result === password;
                 }