From b20eb50699d4fcd1a0f795b574edf391c2b67346 Mon Sep 17 00:00:00 2001 From: Ghassan Maslamani Date: Thu, 1 Jun 2023 19:50:13 +0300 Subject: [PATCH] test: course url when public path is set The commit add two tests for the following componenets: 1. BackToInstructor 2. BulkEmailPendingTasksAlert Which tests course url when public path is set to something other than '/' and also when it is '/'. --- .../test/BulkEmailPendingTasksAlert.test.jsx | 33 +++++++++++++++++++ .../navigation-tabs/BackToInstructor.test.jsx | 33 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/components/bulk-email-tool/bulk-email-task-manager/test/BulkEmailPendingTasksAlert.test.jsx create mode 100644 src/components/navigation-tabs/BackToInstructor.test.jsx diff --git a/src/components/bulk-email-tool/bulk-email-task-manager/test/BulkEmailPendingTasksAlert.test.jsx b/src/components/bulk-email-tool/bulk-email-task-manager/test/BulkEmailPendingTasksAlert.test.jsx new file mode 100644 index 0000000..50af805 --- /dev/null +++ b/src/components/bulk-email-tool/bulk-email-task-manager/test/BulkEmailPendingTasksAlert.test.jsx @@ -0,0 +1,33 @@ +import React from 'react'; + +import BulkEmailPendingTasksAlert from '../BulkEmailPendingTasksAlert'; +import { + initializeMockApp, render, screen, +} from '../../../../setupTest'; + +describe('Testing BulkEmailPendingTasksAlert Component', () => { + beforeAll(async () => { + await initializeMockApp(); + }); + + test('Render without Public path', async () => { + render(); + + const linkEl = await screen.findByText('Course Info'); + expect(linkEl.href).toEqual('http://localhost:18000/courses/test-course-id/instructor#view-course-info'); + }); + + test('Render with Public path', async () => { + Object.defineProperty(window, 'location', { + get() { + return { pathname: '/communications/courses/test-course-id/bulk-email' }; + }, + }); + + render(); + + const linkEl = await screen.findByText('Course Info'); + expect(linkEl.href).toEqual('http://localhost:18000/courses/test-course-id/instructor#view-course-info'); + expect(window.location.pathname).toEqual('/communications/courses/test-course-id/bulk-email'); + }); +}); diff --git a/src/components/navigation-tabs/BackToInstructor.test.jsx b/src/components/navigation-tabs/BackToInstructor.test.jsx new file mode 100644 index 0000000..ab439bb --- /dev/null +++ b/src/components/navigation-tabs/BackToInstructor.test.jsx @@ -0,0 +1,33 @@ +import React from 'react'; + +import BackToInstructor from './BackToInstructor'; +import { + initializeMockApp, render, screen, +} from '../../setupTest'; + +describe('Testing BackToInstructor Component', () => { + beforeAll(async () => { + await initializeMockApp(); + }); + + test('Render without Public path', async () => { + render(); + + const linkEl = await screen.findByText('Back to Instructor Dashboard'); + expect(linkEl.href).toEqual('http://localhost:18000/courses/test-course-id/instructor#view-course-info'); + }); + + test('Render with Public path', async () => { + Object.defineProperty(window, 'location', { + get() { + return { pathname: '/communications/courses/test-course-id/bulk-email' }; + }, + }); + + render(); + + const linkEl = await screen.findByText('Back to Instructor Dashboard'); + expect(linkEl.href).toEqual('http://localhost:18000/courses/test-course-id/instructor#view-course-info'); + expect(window.location.pathname).toEqual('/communications/courses/test-course-id/bulk-email'); + }); +});