Skip to content

Commit

Permalink
feat: add ability to obtain site name dynamically and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ihor-romaniuk committed Mar 2, 2023
1 parent ba7bd23 commit cf720d5
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 4 deletions.
52 changes: 52 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"prop-types": "15.7.2",
"react": "16.14.0",
"react-dom": "16.14.0",
"react-helmet": "^6.1.0",
"react-redux": "7.1.3",
"react-responsive": "8.1.0",
"react-router": "5.1.2",
Expand Down
21 changes: 21 additions & 0 deletions src/head/Head.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { Helmet } from 'react-helmet';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { getConfig } from '@edx/frontend-platform';

import messages from './messages';

const Head = ({ intl }) => (
<Helmet>
<title>
{intl.formatMessage(messages['course-authoring.page.title'], { siteName: getConfig().SITE_NAME })}
</title>
<link rel="shortcut icon" href={getConfig().FAVICON_URL} type="image/x-icon" />
</Helmet>
);

Head.propTypes = {
intl: intlShape.isRequired,
};

export default injectIntl(Head);
17 changes: 17 additions & 0 deletions src/head/Head.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import { Helmet } from 'react-helmet';
import { mount } from 'enzyme';
import { getConfig } from '@edx/frontend-platform';
import Head from './Head';

describe('Head', () => {
const props = {};
it('should match render title tag and favicon with the site configuration values', () => {
mount(<IntlProvider locale="en"><Head {...props} /></IntlProvider>);
const helmet = Helmet.peek();
expect(helmet.title).toEqual(`Course Authoring | ${getConfig().SITE_NAME}`);
expect(helmet.linkTags[0].rel).toEqual('shortcut icon');
expect(helmet.linkTags[0].href).toEqual(getConfig().FAVICON_URL);
});
});
11 changes: 11 additions & 0 deletions src/head/messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineMessages } from '@edx/frontend-platform/i18n';

const messages = defineMessages({
'course-authoring.page.title': {
id: 'course-authoring.page.title',
defaultMessage: 'Course Authoring | {siteName}',
description: 'Title tag',
},
});

export default messages;
2 changes: 2 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import appMessages from './i18n';
import initializeStore from './store';
import './index.scss';
import CourseAuthoringRoutes from './CourseAuthoringRoutes';
import Head from './head/Head';

subscribe(APP_READY, () => {
ReactDOM.render(
<AppProvider store={initializeStore()}>
<Head />
<Switch>
<Route
path="/course/:courseId"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ReactDOM from 'react-dom';
import {
getConfig, history, initializeMockApp, setConfig,
} from '@edx/frontend-platform';
Expand Down Expand Up @@ -42,6 +43,9 @@ let axiosMock;
let store;
let container;

// Modal creates a portal. Overriding ReactDOM.createPortal allows portals to be tested in jest.
ReactDOM.createPortal = jest.fn(node => node);

function renderComponent() {
const wrapper = render(
<AppProvider store={store}>
Expand Down
4 changes: 4 additions & 0 deletions src/pages-and-resources/live/BbbSettings.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
waitForElementToBeRemoved,
} from '@testing-library/react';

import ReactDOM from 'react-dom';
import { Switch } from 'react-router-dom';
import { initializeMockApp, history } from '@edx/frontend-platform';
import MockAdapter from 'axios-mock-adapter';
Expand Down Expand Up @@ -34,6 +35,9 @@ let container;
let store;
const liveSettingsUrl = `/course/${courseId}/pages-and-resources/live/settings`;

// Modal creates a portal. Overriding ReactDOM.createPortal allows portals to be tested in jest.
ReactDOM.createPortal = jest.fn(node => node);

const renderComponent = () => {
const wrapper = render(
<IntlProvider locale="en">
Expand Down
4 changes: 4 additions & 0 deletions src/pages-and-resources/live/Settings.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
waitForElementToBeRemoved,
} from '@testing-library/react';

import ReactDOM from 'react-dom';
import { Switch } from 'react-router-dom';
import { initializeMockApp, history } from '@edx/frontend-platform';
import MockAdapter from 'axios-mock-adapter';
Expand Down Expand Up @@ -37,6 +38,9 @@ let container;
let store;
const liveSettingsUrl = `/course/${courseId}/pages-and-resources/live/settings`;

// Modal creates a portal. Overriding ReactDOM.createPortal allows portals to be tested in jest.
ReactDOM.createPortal = jest.fn(node => node);

const renderComponent = () => {
const wrapper = render(
<IntlProvider locale="en">
Expand Down
4 changes: 4 additions & 0 deletions src/pages-and-resources/live/ZoomSettings.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
waitForElementToBeRemoved,
} from '@testing-library/react';

import ReactDOM from 'react-dom';
import { Switch } from 'react-router-dom';
import { initializeMockApp, history } from '@edx/frontend-platform';
import MockAdapter from 'axios-mock-adapter';
Expand Down Expand Up @@ -32,6 +33,9 @@ let container;
let store;
const liveSettingsUrl = `/course/${courseId}/pages-and-resources/live/settings`;

// Modal creates a portal. Overriding ReactDOM.createPortal allows portals to be tested in jest.
ReactDOM.createPortal = jest.fn(node => node);

const renderComponent = () => {
const wrapper = render(
<IntlProvider locale="en">
Expand Down
4 changes: 0 additions & 4 deletions src/setupTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'core-js/stable';
import 'regenerator-runtime/runtime';
import '@testing-library/jest-dom';
import '@testing-library/jest-dom/extend-expect';
import ReactDOM from 'react-dom';

/* eslint-disable import/no-extraneous-dependencies */
import Enzyme from 'enzyme';
Expand All @@ -29,9 +28,6 @@ Object.defineProperty(window, 'matchMedia', {
})),
});

// Modal creates a portal. Overriding ReactDOM.createPortal allows portals to be tested in jest.
ReactDOM.createPortal = node => node;

// Mock Intersection Observer which is unavailable in the context of a test.
global.IntersectionObserver = jest.fn(function mockIntersectionObserver() {
this.observe = jest.fn();
Expand Down

0 comments on commit cf720d5

Please sign in to comment.