From 55dd7a84c6789508f4b7243063f0b8154ad2f3fb Mon Sep 17 00:00:00 2001 From: ilee2u Date: Thu, 16 Feb 2023 12:04:40 -0500 Subject: [PATCH] temp!: attempted broader Jest tests Attempted to create unit tests for the changes to SequenceLink.js, only to discover that doing so would require some broader end to end testing. That is to say, it would be unproductive to dig any deeper into testing. I am making this commit to at least document the work I did, for my own records. BREAKING CHANGE: Don't merge this commit. I will be making another commit that removes the breaking tests. --- package.json | 3 +- .../outline-tab/OutlineTab.test.jsx | 47 ++++++++++++++----- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 0c3c36b6..e5b79396 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "prepare": "husky install", "snapshot": "fedx-scripts jest --updateSnapshot", "start": "fedx-scripts webpack-dev-server --progress", - "test": "fedx-scripts jest --coverage --passWithNoTests" + "test": "fedx-scripts jest --coverage --passWithNoTests", + "testx": "fedx-scripts jest -t 'Outline Tab' --coverage --passWithNoTests" }, "author": "edX", "license": "AGPL-3.0", diff --git a/src/course-home/outline-tab/OutlineTab.test.jsx b/src/course-home/outline-tab/OutlineTab.test.jsx index 9e23f478..da4ac1e8 100644 --- a/src/course-home/outline-tab/OutlineTab.test.jsx +++ b/src/course-home/outline-tab/OutlineTab.test.jsx @@ -23,6 +23,8 @@ import { CERT_STATUS_TYPE } from './alerts/certificate-status-alert/CertificateS import OutlineTab from './OutlineTab'; import LoadedTabPage from '../../tab-page/LoadedTabPage'; +import SequenceLink from './SequenceLink'; + initializeMockApp(); jest.mock('@edx/frontend-platform/analytics'); @@ -155,29 +157,48 @@ describe('Outline Tab', () => { expect(sequenceLink.getAttribute('href')).toContain(`/course/${courseId}`); }); - // TODO: insert unit test for if due date is null or not, what the subtitle - // If due date set, make sure subtitle says description AND due date - it('exam subsection description and due date display correctly', async () => { - const { courseBlocks } = await buildMinimalCourseBlocks(courseId, 'Title', { resumeBlock: true }); + it('if exam due date set, exam description AND due date appear', async () => { + // Create a due date set a year into the future + const now = new Date(); + const dueDate = new Date(now.getFullYear() + 1, now.getMonth(), now.getDate()); + + // Build course blocks with a future due date set + const { courseBlocks } = await buildMinimalCourseBlocks(courseId, 'Title', { + sequenceBlocks: [ + , + ], + }); setTabData({ course_blocks: { blocks: courseBlocks.blocks }, }); await fetchAndRender(); + // Button renders as "Expand All" + const expandButton = screen.getByRole('button', { name: 'Expand all' }); + expect(expandButton).toBeInTheDocument(); + + // Click to expand section + userEvent.click(expandButton); + // Look for a substring that says "(exam type) Exam due (datetime)"" expect(screen.getByText(/Exam due/)).toBeInDocument(); }); // If due date is NOT set, ONLY display description - it('exam subsection description and due date display correctly', async () => { - const { courseBlocks } = await buildMinimalCourseBlocks(courseId, 'Title', { resumeBlock: true }); - setTabData({ - course_blocks: { blocks: courseBlocks.blocks }, - }); - await fetchAndRender(); - // Look for a substring that only says "(exam type) Exam" - expect(screen.getByText(/Exam$/)).toBeInDocument(); - }); }); describe('Suggested schedule alerts', () => {