-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: show custom alert if user is already enrolled pre-emet in exec…
… ed course (#765)
- Loading branch information
1 parent
b73a1bf
commit 6f9afb1
Showing
6 changed files
with
177 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,13 @@ jest.mock('../../../executive-education-2u/UserEnrollmentForm', () => jest.fn(() | |
<div data-testid="user-enrollment-form" /> | ||
))); | ||
|
||
jest.mock('@edx/frontend-platform/config', () => ({ | ||
...jest.requireActual('@edx/frontend-platform/config'), | ||
getConfig: jest.fn(() => ({ | ||
GETSMARTER_LEARNER_DASHBOARD_URL: 'https://getsmarter.example.com/account', | ||
})), | ||
})); | ||
|
||
const baseCourseContextValue = { | ||
state: { | ||
courseEntitlementProductSku: 'test-sku', | ||
|
@@ -59,6 +66,7 @@ const baseAppContextValue = { | |
uuid: 'test-uuid', | ||
enableDataSharingConsent: true, | ||
adminUsers: ['[email protected]'], | ||
authOrgId: 'test-uuid', | ||
}, | ||
authenticatedUser: { id: 3 }, | ||
}; | ||
|
@@ -80,7 +88,9 @@ describe('ExternalCourseEnrollment', () => { | |
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
it('renders and handles checkout success', () => { | ||
renderWithRouter(<ExternalCourseEnrollmentWrapper />); | ||
expect(screen.getByText('Your registration(s)')).toBeInTheDocument(); | ||
|
@@ -153,4 +163,32 @@ describe('ExternalCourseEnrollment', () => { | |
|
||
expect(mockHistoryPush).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it.each([ | ||
{ hasDuplicateOrder: true }, | ||
{ hasDuplicateOrder: false }, | ||
])('shows duplicate order alert (%s)', async ({ hasDuplicateOrder }) => { | ||
const mockScrollIntoView = jest.fn(); | ||
global.HTMLElement.prototype.scrollIntoView = mockScrollIntoView; | ||
|
||
const courseContextValue = { | ||
...baseCourseContextValue, | ||
externalCourseFormSubmissionError: hasDuplicateOrder ? { message: 'duplicate order' } : undefined, | ||
}; | ||
renderWithRouter(<ExternalCourseEnrollmentWrapper courseContextValue={courseContextValue} />); | ||
if (hasDuplicateOrder) { | ||
expect(screen.getByText('Already Enrolled')).toBeInTheDocument(); | ||
const dashboardButton = screen.getByText('Go to dashboard'); | ||
expect(dashboardButton).toBeInTheDocument(); | ||
expect(dashboardButton).toHaveAttribute('href', 'https://getsmarter.example.com/account?org_id=test-uuid'); | ||
expect(mockScrollIntoView).toHaveBeenCalledTimes(1); | ||
expect(mockScrollIntoView).toHaveBeenCalledWith( | ||
expect.objectContaining({ behavior: 'smooth' }), | ||
); | ||
} else { | ||
expect(screen.queryByText('Already Enrolled')).not.toBeInTheDocument(); | ||
expect(screen.queryByText('Go to dashboard')).not.toBeInTheDocument(); | ||
expect(mockScrollIntoView).toHaveBeenCalledTimes(0); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters