-
Notifications
You must be signed in to change notification settings - Fork 6
ENT-11639: Add testimonials to all plans - updated AcademicSelection component #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gshivajibiradar
wants to merge
3
commits into
main
Choose a base branch
from
feature/ENT-11639-testimonials-all-plans
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
158 changes: 158 additions & 0 deletions
158
src/components/app/data/hooks/tests/useTestimonials.test.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import { getAuthenticatedHttpClient, getAuthenticatedUser } from '@edx/frontend-platform/auth'; | ||
| import { getConfig } from '@edx/frontend-platform/config'; | ||
| import axios from 'axios'; | ||
|
|
||
| import { | ||
| fetchTestimonials, | ||
| pickNextTestimonial, | ||
| SEEDED_ACTIVE_TESTIMONIALS, | ||
| } from '../useTestimonials'; | ||
|
|
||
| jest.mock('@edx/frontend-platform/auth', () => ({ | ||
| getAuthenticatedHttpClient: jest.fn(), | ||
| getAuthenticatedUser: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('@edx/frontend-platform/config', () => ({ | ||
| getConfig: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('axios'); | ||
|
|
||
| describe('fetchTestimonials', () => { | ||
| const mockHttpGet = jest.fn(); | ||
| const baseUrl = 'https://enterprise-access.example.com'; | ||
| const endpoint = `${baseUrl}/api/v1/testimonials/`; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| (getConfig as jest.Mock).mockReturnValue({ | ||
| ENTERPRISE_ACCESS_BASE_URL: baseUrl, | ||
| }); | ||
| (getAuthenticatedHttpClient as jest.Mock).mockReturnValue({ | ||
| get: mockHttpGet, | ||
| }); | ||
| }); | ||
|
|
||
| it('uses authenticated client for logged-in users and returns only active testimonials', async () => { | ||
| (getAuthenticatedUser as jest.Mock).mockReturnValue({ username: 'test-user' }); | ||
| mockHttpGet.mockResolvedValue({ | ||
| data: { | ||
| results: [ | ||
| { | ||
| uuid: '1', | ||
| quote_text: 'Active quote', | ||
| attribution_name: 'Alex', | ||
| attribution_title: 'Director', | ||
| is_active: true, | ||
| }, | ||
| { | ||
| uuid: '2', | ||
| quote_text: 'Inactive quote', | ||
| attribution_name: 'Pat', | ||
| attribution_title: 'Manager', | ||
| is_active: false, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| const result = await fetchTestimonials(); | ||
|
|
||
| expect(mockHttpGet).toHaveBeenCalledWith(endpoint); | ||
| expect((axios.get as jest.Mock)).not.toHaveBeenCalled(); | ||
| expect(result).toEqual([ | ||
| { | ||
| uuid: '1', | ||
| quote_text: 'Active quote', | ||
| attribution_name: 'Alex', | ||
| attribution_title: 'Director', | ||
| is_active: true, | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('uses axios for logged-out users', async () => { | ||
| (getAuthenticatedUser as jest.Mock).mockReturnValue(null); | ||
| (axios.get as jest.Mock).mockResolvedValue({ | ||
| data: { | ||
| results: [ | ||
| { | ||
| uuid: '3', | ||
| quote_text: 'Public quote', | ||
| attribution_name: 'Jordan', | ||
| attribution_title: 'Lead', | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| const result = await fetchTestimonials(); | ||
|
|
||
| expect(axios.get).toHaveBeenCalledWith(endpoint); | ||
| expect(mockHttpGet).not.toHaveBeenCalled(); | ||
| expect(result).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('returns seeded active testimonials when API results are missing or malformed', async () => { | ||
| (getAuthenticatedUser as jest.Mock).mockReturnValue(null); | ||
| (axios.get as jest.Mock).mockResolvedValue({ data: { results: null } }); | ||
|
|
||
| const result = await fetchTestimonials(); | ||
|
|
||
| expect(result).toEqual(SEEDED_ACTIVE_TESTIMONIALS); | ||
| }); | ||
|
|
||
| it('returns seeded active testimonials when request fails', async () => { | ||
| (getAuthenticatedUser as jest.Mock).mockReturnValue(null); | ||
| (axios.get as jest.Mock).mockRejectedValue(new Error('network')); | ||
|
|
||
| const result = await fetchTestimonials(); | ||
|
|
||
| expect(result).toEqual(SEEDED_ACTIVE_TESTIMONIALS); | ||
| }); | ||
| }); | ||
|
|
||
| describe('pickNextTestimonial', () => { | ||
| const testimonials = [ | ||
| { | ||
| uuid: 'a', | ||
| quote_text: 'Quote A', | ||
| attribution_name: 'A', | ||
| attribution_title: 'Role A', | ||
| }, | ||
| { | ||
| uuid: 'b', | ||
| quote_text: 'Quote B', | ||
| attribution_name: 'B', | ||
| attribution_title: 'Role B', | ||
| }, | ||
| { | ||
| uuid: 'c', | ||
| quote_text: 'Quote C', | ||
| attribution_name: 'C', | ||
| attribution_title: 'Role C', | ||
| }, | ||
| ]; | ||
|
|
||
| it('does not repeat testimonials until all have been shown', () => { | ||
| const shown = new Set<string>(); | ||
|
|
||
| const first = pickNextTestimonial(testimonials, shown); | ||
| const second = pickNextTestimonial(testimonials, shown); | ||
| const third = pickNextTestimonial(testimonials, shown); | ||
|
|
||
| const uuids = [first?.uuid, second?.uuid, third?.uuid].filter(Boolean); | ||
| expect(new Set(uuids).size).toBe(3); | ||
| expect(shown.size).toBe(3); | ||
| }); | ||
|
|
||
| it('resets shown set after pool exhaustion and continues rotation', () => { | ||
| const shown = new Set<string>(['a', 'b', 'c']); | ||
| const next = pickNextTestimonial(testimonials, shown); | ||
|
|
||
| expect(next).not.toBeNull(); | ||
| expect(shown.size).toBe(1); | ||
| expect(shown.has(next?.uuid || '')).toBe(true); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.