Skip to content
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

Add CoursewareSearchForm component #1214

Merged
merged 6 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/course-home/courseware-search/CoursewareSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { setShowSearch } from '../data/slice';
import { useElementBoundingBox, useLockScroll } from './hooks';
import messages from './messages';

import CoursewareSearchBar from './CoursewareSearchBar';

const CoursewareSearch = ({ intl, ...sectionProps }) => {
const dispatch = useDispatch();

Expand All @@ -32,6 +34,11 @@ const CoursewareSearch = ({ intl, ...sectionProps }) => {
<div className="courseware-search__outer-content">
<div className="courseware-search__content" style={{ height: '999px' }}>
<h2>{intl.formatMessage(messages.searchModuleTitle)}</h2>
<CoursewareSearchBar
onChange={() => {}}
onSubmit={() => {}}
placeholder={intl.formatMessage(messages.searchBarPlaceholderText)}
/>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis semper rutrum odio quis congue.
Duis sodales nibh et sapien elementum fermentum. Quisque magna urna, gravida at gravida et,
Expand Down
32 changes: 32 additions & 0 deletions src/course-home/courseware-search/CoursewareSearchBar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { SearchField } from '@edx/paragon';
import PropTypes from 'prop-types';

const CoursewareSearchBar = ({
davidnuon marked this conversation as resolved.
Show resolved Hide resolved
onSubmit,
onChange,
placeholder,
}) => (
<SearchField.Advanced
onSubmit={onSubmit}
onChange={onChange}
submitButtonLocation="external"
className="courseware-search-bar"
data-testid="courseware-search-bar"
>
<div className="pgn__searchfield_wrapper">
<SearchField.Label />
<SearchField.Input placeholder={placeholder} />
<SearchField.ClearButton />
</div>
<SearchField.SubmitButton submitButtonLocation="external" />
</SearchField.Advanced>
);

CoursewareSearchBar.propTypes = {
onSubmit: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
placeholder: PropTypes.string.isRequired,
};

export default CoursewareSearchBar;
31 changes: 31 additions & 0 deletions src/course-home/courseware-search/CoursewareSearchBarTest.jsx
davidnuon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import {
act,
initializeMockApp,
render,
screen,
waitFor,
} from '../../setupTest';
import CoursewareSearchBar from './CoursewareSearchBar';

function renderComponent() {
const { container } = render(<CoursewareSearchBar />);
return container;
}

describe('CoursewareSearchToggle', () => {
beforeAll(async () => {
initializeMockApp();
});

it('should render', async () => {
await act(async () => renderComponent());
await waitFor(() => {
expect(screen.queryByTestId('courseware-search-bar')).toBeInTheDocument();
});
});

afterEach(() => {
jest.clearAllMocks();
});
});
5 changes: 5 additions & 0 deletions src/course-home/courseware-search/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const messages = defineMessages({
defaultMessage: 'Search this course',
description: 'Title for the Courseware Search module.',
},
searchBarPlaceholderText: {
id: 'learn.coursewareSerch.searchBarPlaceholderText',
defaultMessage: 'Search',
description: 'Placeholder text courseware for the search bar.',
davidnuon marked this conversation as resolved.
Show resolved Hide resolved
},
});

export default messages;