Files
frontend-app-learning/src/generic/course-sock/CourseSock.test.jsx
Dillon Dumesnil 50e649daa3 AA-491: Update MFE with analytics event (#351)
These already exist in the legacy view. This is just porting them
over into the MFEs
2021-02-02 05:39:27 -08:00

45 lines
1.4 KiB
JavaScript

import React from 'react';
import {
render, screen, fireEvent, initializeMockApp,
} from '../../setupTest';
import CourseSock from './CourseSock';
jest.mock('@edx/frontend-platform/analytics');
describe('Course Sock', () => {
const mockData = {
verifiedMode: {
upgradeUrl: 'test-url',
price: 1234,
currency: 'dollars',
currencySymbol: '$',
},
pageLocation: 'Course Content Page',
};
beforeAll(async () => {
// We need to mock AuthService to implicitly use `getAuthenticatedUser` within `AppContext.Provider`.
await initializeMockApp();
});
it('hides upsell information on load', () => {
render(<CourseSock {...mockData} />);
expect(screen.getByRole('button', { name: 'Learn About Verified Certificates' })).toBeInTheDocument();
expect(screen.queryByText('edX Verified Certificate')).not.toBeInTheDocument();
});
it('handles click', () => {
render(<CourseSock {...mockData} />);
const upsellButton = screen.getByRole('button', { name: 'Learn About Verified Certificates' });
fireEvent.click(upsellButton);
expect(screen.getByText('edX Verified Certificate')).toBeInTheDocument();
const { currencySymbol, price } = mockData.verifiedMode;
expect(screen.getByText(`Upgrade (${currencySymbol}${price})`)).toBeInTheDocument();
fireEvent.click(upsellButton);
expect(screen.queryByText('edX Verified Certificate')).not.toBeInTheDocument();
});
});