Skip to content

Commit

Permalink
Fix breadcrumb issues when opening book details from the list editor. (
Browse files Browse the repository at this point in the history
…#49)

* Fix breadcrumb issues when opening book details from the list editor.

* Update tests.

* Add test for falsy saved list name.
  • Loading branch information
ray-lee authored Oct 3, 2022
1 parent 16ce180 commit 820b17a
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/components/CustomListEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type CustomListEditorProps = {
library: LibraryData;
listId?: string;
properties?: CustomListEditorProperties;
savedName?: string;
searchParams?: CustomListEditorSearchParams;
searchResults?: CollectionData;
startingTitle?: string;
Expand Down Expand Up @@ -89,6 +90,7 @@ export default function CustomListEditor({
library,
listId,
properties,
savedName,
searchParams,
searchResults,
startingTitle,
Expand Down Expand Up @@ -122,6 +124,11 @@ export default function CustomListEditor({

const readOnly = !isOwner;

const opdsFeedUrl =
listId && savedName
? `${library?.short_name}/lists/${savedName}/crawlable`
: undefined;

return (
<div className="custom-list-editor">
<div className="custom-list-editor-header">
Expand Down Expand Up @@ -281,9 +288,7 @@ export default function CustomListEditor({
isFetchingSearchResults={isFetchingSearchResults}
isFetchingMoreSearchResults={isFetchingMoreSearchResults}
isFetchingMoreCustomListEntries={isFetchingMoreCustomListEntries}
opdsFeedUrl={`${library?.short_name}/${
name ? `lists/${name}/` : ""
}crawlable`}
opdsFeedUrl={opdsFeedUrl}
entryCount={entries.currentTotalCount}
listId={listId}
addEntry={addEntry}
Expand Down
4 changes: 2 additions & 2 deletions src/components/CustomListEntriesEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface CustomListEntriesEditorProps {
refreshResults?: () => void;
}

const renderCatalogLink = (book, opdsFeedUrl) => {
const renderCatalogLink = (book, opdsFeedUrl?) => {
const { title, url } = book;

if (!url) {
Expand Down Expand Up @@ -217,7 +217,7 @@ const CustomListEntriesEditor = ({
{getMediumSVG(getMedium(book))}

<div className="links">
{renderCatalogLink(book, opdsFeedUrl)}
{renderCatalogLink(book)}

{!readOnly && (
<Button
Expand Down
4 changes: 4 additions & 0 deletions src/components/CustomLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import CustomListsSidebar from "./CustomListsSidebar";

export interface CustomListsStateProps {
customListEditorProperties?: CustomListEditorProperties;
customListEditorSavedName?: string;
customListEditorSearchParams?: CustomListEditorSearchParams;
customListEditorEntries?: CustomListEditorEntriesData;
customListEditorIsLoaded?: boolean;
Expand Down Expand Up @@ -184,6 +185,7 @@ export class CustomLists extends React.Component<
collections: this.collectionsForLibrary(),
isAutoUpdateEnabled: this.props.customListEditorIsAutoUpdateEnabled,
properties: this.props.customListEditorProperties,
savedName: this.props.customListEditorSavedName,
searchParams: this.props.customListEditorSearchParams,
isLoaded: this.props.customListEditorIsLoaded,
isValid: this.props.customListEditorIsValid,
Expand Down Expand Up @@ -436,6 +438,8 @@ function mapStateToProps(state, ownProps) {
return {
customListEditorProperties:
state.editor.customListEditor.properties.current,
customListEditorSavedName:
state.editor.customListEditor.properties.baseline.name,
customListEditorSearchParams:
state.editor.customListEditor.searchParams.current,
customListEditorEntries: state.editor.customListEditor.entries,
Expand Down
43 changes: 43 additions & 0 deletions src/components/__tests__/CustomListEditor-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,49 @@ describe("CustomListEditor", () => {
);
});

it("sets the feed url in the entries editor to the url for the saved list name", () => {
wrapper.setProps({
savedName: "Books to Read Today",
});

const entriesEditor = wrapper.find(CustomListEntriesEditor);

expect(entriesEditor.props().opdsFeedUrl).to.equal(
"library/lists/Books to Read Today/crawlable"
);
});

it("sets the feed url in the entries editor to undefined when the list is new", () => {
wrapper.setProps({
listId: null, // new, unsaved lists have null listId
savedName: "Books to Read Today",
});

const entriesEditor = wrapper.find(CustomListEntriesEditor);

expect(entriesEditor.props().opdsFeedUrl).to.equal(undefined);
});

it("sets the feed url in the entries editor to undefined when the saved list name is falsy", () => {
wrapper.setProps({
savedName: "",
});

let entriesEditor;

entriesEditor = wrapper.find(CustomListEntriesEditor);

expect(entriesEditor.props().opdsFeedUrl).to.equal(undefined);

wrapper.setProps({
savedName: null,
});

entriesEditor = wrapper.find(CustomListEntriesEditor);

expect(entriesEditor.props().opdsFeedUrl).to.equal(undefined);
});

it("shows collections", () => {
const collectionsPanel = wrapper.find("#add-from-collections-panel");
const inputs = collectionsPanel.find(EditableInput);
Expand Down
58 changes: 58 additions & 0 deletions src/components/__tests__/CustomListEntriesEditor-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,37 @@ describe("CustomListEntriesEditor", () => {
);
});

it("does not include the opds feed url in links to view search results", () => {
const wrapper = mount(
<CustomListEntriesEditor
entries={entriesData}
isOwner={true}
opdsFeedUrl="opdsFeedUrl"
searchResults={searchResultsData}
loadMoreSearchResults={loadMoreSearchResults}
loadMoreEntries={loadMoreEntries}
isFetchingSearchResults={false}
isFetchingMoreSearchResults={false}
isFetchingMoreCustomListEntries={false}
/>,
{ context: fullContext, childContextTypes }
);

const results = wrapper.find(".custom-list-search-results Draggable");

expect(results.at(0).find("CatalogLink").prop("collectionUrl")).to.equal(
undefined
);

expect(results.at(1).find("CatalogLink").prop("collectionUrl")).to.equal(
undefined
);

expect(results.at(2).find("CatalogLink").prop("collectionUrl")).to.equal(
undefined
);
});

it("renders an SVG icon for each search result", () => {
const wrapper = mount(
<CustomListEntriesEditor
Expand Down Expand Up @@ -455,6 +486,33 @@ describe("CustomListEntriesEditor", () => {
);
});

it("includes the opds feed url in links to view entries", () => {
const wrapper = mount(
<CustomListEntriesEditor
entries={entriesData}
isOwner={true}
loadMoreSearchResults={loadMoreSearchResults}
loadMoreEntries={loadMoreEntries}
isFetchingSearchResults={false}
isFetchingMoreSearchResults={false}
isFetchingMoreCustomListEntries={false}
opdsFeedUrl="opdsFeedUrl"
entryCount={2}
/>,
{ context: fullContext, childContextTypes }
);

const entries = wrapper.find(".custom-list-entries Draggable");

expect(entries.at(0).find("CatalogLink").prop("collectionUrl")).to.equal(
"opdsFeedUrl"
);

expect(entries.at(1).find("CatalogLink").prop("collectionUrl")).to.equal(
"opdsFeedUrl"
);
});

it("renders an SVG icon for each entry", () => {
const wrapper = mount(
<CustomListEntriesEditor
Expand Down

0 comments on commit 820b17a

Please sign in to comment.