Skip to content

Commit

Permalink
Test displaying the resume text nicobrenner#48
Browse files Browse the repository at this point in the history
also removed line strip
  • Loading branch information
AaryamanVyas committed Mar 18, 2024
1 parent bd85a97 commit 5a7f259
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ def draw_menu(self):
self.stdscr.addstr(y, x, item)
self.stdscr.attroff(curses.color_pair(1))
else:
if item =='📄 Create resume (just paste it here once)' and self.read_resume_from_file():
item='📄 Edit resume'
self.stdscr.addstr(y, x, item)
self.stdscr.refresh()

Expand Down Expand Up @@ -253,7 +255,7 @@ def display_text_with_scrolling(self, header, lines):
self.stdscr.attroff(curses.color_pair(2)) # Turn off color pair

for i, line in enumerate(lines[offset:offset+max_y-5]):
self.stdscr.addstr(i+3, 0, line.strip())
self.stdscr.addstr(i+3, 0, line)

key = self.stdscr.getch()
if key in [ord('q'), ord('Q')]:
Expand Down
36 changes: 36 additions & 0 deletions src/test_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,42 @@ def test_manage_resume(self, mock_getenv, mock_curses):
temp_test_db_path = DB_PATH
if os.path.exists(temp_test_db_path):
os.remove(temp_test_db_path)
@patch('menu.curses')
@patch('menu.os.getenv')
def test_displaying_resume(self, mock_getenv, mock_curses):
# Mock environment variables
mock_getenv.side_effect = lambda x: {'OPENAI_API_KEY': 'test_key', 'BASE_RESUME_PATH': 'temp_test_resume.txt', 'HN_START_URL': 'test_url', 'COMMANDJOBS_LISTINGS_PER_BATCH': '10', 'OPENAI_GPT_MODEL': 'gpt-3.5'}.get(x, None)

# Mock stdscr object
mock_stdscr = MagicMock()
mock_curses.initscr.return_value = mock_stdscr
mock_stdscr.getmaxyx.return_value = (100, 40) # Example values for a terminal size

# Use some test resume text
test_resume_text = "This is a test resume text."
# Save the test resume text to the temporary resume file
with open('temp_test_resume.txt', 'w') as file:
file.write(test_resume_text)

# Mock user input sequence for getch
mock_stdscr.getch.side_effect = [ord('q')] # Press 'q' to exit

# Initialize Menu with mocked stdscr and logger
logger = MagicMock()
with patch.object(MenuApp, 'run', return_value=None):
menu = MenuApp(mock_stdscr, logger)
# Assert that the displayed resume text matches the test resume text

captured_text = mock_stdscr.addstr.call_args_list[0][0][1] # Get the captured text from the first call to addstr
self.assertEqual(captured_text, test_resume_text)

# Remove the temporary resume file
if os.path.exists('temp_test_resume.txt'):
os.remove('temp_test_resume.txt')


# Call the method being tested
menu.manage_resume(mock_stdscr)

if __name__ == '__main__':
unittest.main()

0 comments on commit 5a7f259

Please sign in to comment.