From 3f1058f9b60543681a0686690935439542ec3fa8 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Fri, 17 Jan 2025 17:03:22 -0800 Subject: [PATCH] jest testing --- tests/javascripts/activityChart.test.js | 61 ++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/javascripts/activityChart.test.js b/tests/javascripts/activityChart.test.js index 8e3d406ea..427c93ac2 100644 --- a/tests/javascripts/activityChart.test.js +++ b/tests/javascripts/activityChart.test.js @@ -21,7 +21,7 @@ Object.defineProperty(HTMLElement.prototype, 'clientWidth', { beforeAll(done => { // Set up the DOM with the D3 script included document.body.innerHTML = ` -
+
+ + + + `; + + window.currentUserName = "Test User"; + + jest.spyOn(window, 'fetchData').mockImplementation(() => {}); + + const selectElement = document.getElementById('options'); + selectElement.value = 'individual'; + const event = { target: selectElement }; + + window.handleDropdownChange(event); + + expect(document.getElementById('table-heading').textContent).toBe('My activity'); + expect(document.getElementById('caption').textContent).toContain('Test User'); + + document.querySelectorAll('.sender-column').forEach(col => { + expect(col.style.display).toBe('none'); + }); + + const rows = Array.from(document.querySelectorAll('#activity-table tbody tr')); + const visibleRows = rows.filter(row => row.style.display !== 'none'); + expect(visibleRows.length).toBeLessThanOrEqual(5); + visibleRows.forEach(row => { + const sender = row.querySelector('.sender-column').textContent.trim(); + expect(sender).toBe('Test User'); + }); + + window.fetchData.mockRestore(); +});