Skip to content

Commit

Permalink
feat: added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zamanafzal committed Aug 3, 2023
1 parent 84f7b4d commit 02a333f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/components/learner-credit-management/BudgetCard.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import dayjs from 'dayjs';
import {
Card,
Button,
Expand Down Expand Up @@ -41,8 +41,8 @@ const BudgetCard = ({
const links = [
{ label: 'Budgets', url: `/${enterpriseSlug}/admin/${ROUTE_NAMES.learnerCredit}` },
];
const formattedStartDate = moment(start).format('MMMM D, YYYY');
const formattedExpirationDate = moment(end).format('MMMM D, YYYY');
const formattedStartDate = dayjs(start).format('MMMM D, YYYY');
const formattedExpirationDate = dayjs(end).format('MMMM D, YYYY');
const navigateToBudgetRedemptions = (budgetType) => {
setDetailPage(true);
links.push({ label: budgetType, url: `/${enterpriseSlug}/admin/learner-credit` });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import userEvent from '@testing-library/user-event';
import configureMockStore from 'redux-mock-store';
import moment from 'moment';
import dayjs from 'dayjs';
import {
screen,
render,
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('<BudgetCard />', () => {
expect(screen.getByText('Open Courses Marketplace'));
expect(screen.getByText('Executive Education'));
expect(screen.getByText(`$${mockOfferSummary.redeemedFunds.toLocaleString()}`));
const formattedString = `${moment(mockOffer.start).format('MMMM D, YYYY')} - ${moment(mockOffer.end).format('MMMM D, YYYY')}`;
const formattedString = `${dayjs(mockOffer.start).format('MMMM D, YYYY')} - ${dayjs(mockOffer.end).format('MMMM D, YYYY')}`;
const elementsWithTestId = screen.getAllByTestId('offer-date');
const firstElementWithTestId = elementsWithTestId[0];
expect(firstElementWithTestId).toHaveTextContent(formattedString);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable react/prop-types */
import React from 'react';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import configureMockStore from 'redux-mock-store';
import {
screen,
render,
} from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import { EnterpriseSubsidiesContext } from '../../EnterpriseSubsidiesContext';
import MultipleBudgetsPage from '../MultipleBudgetsPage';

const mockStore = configureMockStore([thunk]);
const getMockStore = store => mockStore(store);
const enterpriseId = 'test-enterprise';
const initialStore = {
portalConfiguration: {
enterpriseId,
},
};
const store = getMockStore({ ...initialStore });
const enterpriseUUID = '1234';

const defaultEnterpriseSubsidiesContextValue = {
offers: [],
};

const MultipleBudgetsPageWrapper = ({
enterpriseSubsidiesContextValue = defaultEnterpriseSubsidiesContextValue,
...rest
}) => (
<Provider store={store}>
<EnterpriseSubsidiesContext.Provider value={enterpriseSubsidiesContextValue}>
<MultipleBudgetsPage {...rest} />
</EnterpriseSubsidiesContext.Provider>
</Provider>
);

describe('<MultipleBudgetsPage />', () => {
it('No budgets for your organization', () => {
render(<MultipleBudgetsPageWrapper enterpriseUUID={enterpriseUUID} enterpriseSlug={enterpriseId} />);
expect(screen.getByText('No budgets for your organization'));
expect(screen.getByText('Contact support'));
});
});

0 comments on commit 02a333f

Please sign in to comment.