-
Notifications
You must be signed in to change notification settings - Fork 1
/
todd-test.js
87 lines (65 loc) · 3 KB
/
todd-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { test, equal } from "/test-helpers.js";
//**************test that user input appears as a string
test("user input type appears as a string", () => {
const userInput = document.querySelector('#input')
equal(typeof userInput.value, 'string')
})
//***************test that submit button sends content to bot
test("submit button sends content to bot", () => {
const userInput = document.createElement('input');
userInput.id = 'input';
document.body.appendChild(userInput);
// Variable to store the content sent to the bot
let sentContent = '';
// Fake send content to the bot
function sendContentToBot(content) {
sentContent = content;
}
// Attach the submit event listener
userInput.addEventListener('submit', (event) => {
const content = event.target.value;
sendContentToBot(content); // Function to send content to bot
});
// Simulate typing in the input field
userInput.value = 'Test input';
// Trigger the submit event
const submitEvent = new Event('submit');
userInput.dispatchEvent(submitEvent);
// Check if the content was sent to the bot as expected
equal(sentContent, 'Test input', "Content should be sent to bot when submit button is pressed");
});
//*********test enter key sends content to bot
test("enter key sends content to bot", () => {
const userInput = document.createElement('input');
userInput.id = 'input';
document.body.appendChild(userInput);
// Variable to store the content sent to the bot
let sentContent = '';
// Fake send content to the bot
function sendContentToBot(content) {
sentContent = content;
}
// Attach the keypress event listener to detect Enter key press
userInput.addEventListener('keypress', (event) => {
if (event.key === 'Enter') {
event.preventDefault(); // Prevent default form submission behavior
sendContentToBot(userInput.value); // Function to send content to bot
}
});
// Simulate typing in the input field
userInput.value = 'Test input';
// Trigger the keypress event with Enter key
const enterKeyEvent = new KeyboardEvent('keypress', { key: 'Enter' });
userInput.dispatchEvent(enterKeyEvent);
// Check if the content was sent to the bot as expected
equal(sentContent, 'Test input', "Content should be sent to bot when Enter key is pressed");
});
// //************ testing library ***************//
/* Ways we can test our bot that I have thought of:
- Check if response given is legible and useful (DONE)
- Check if we can get a sound reply which is directly related to what we say (Ping-Pong) (DONE)
- If the hardcode preventing it from giving out harmful or illegal information is working (DONE)
- Test the user interface
- See if the AI's response is longer than the amount of characters it is allowed to reply back with
- ChatGPT keys cannot give real-time info from Jan 2022 onwards
- Performance testing - How long does it take to reply (thinking time) */