Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
43 changes: 2 additions & 41 deletions src/components/CustomListEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import * as React from "react";
import { Button, Panel } from "library-simplified-reusable-components";
import { CollectionData } from "@thepalaceproject/web-opds-client/lib/interfaces";

import {
AdvancedSearchQuery,
LanguagesData,
LibraryData,
CollectionData as AdminCollectionData,
} from "../interfaces";
import { AdvancedSearchQuery, LanguagesData, LibraryData } from "../interfaces";

import {
CustomListEditorProperties,
Expand All @@ -24,7 +19,6 @@ import ShareIcon from "./icons/ShareIcon";

export type CustomListEditorProps = {
autoUpdateStatus?: string;
collections?: AdminCollectionData[];
entries?: CustomListEditorEntriesData;
entryPoints?: string[];
isAutoUpdateEnabled?: boolean;
Expand Down Expand Up @@ -56,7 +50,6 @@ export type CustomListEditorProps = {
save: () => void;
search: () => void;
share?: () => Promise<void>;
toggleCollection?: (id: number) => void;
updateProperty?: (name: string, value) => void;
updateSearchParam?: (name: string, value) => void;
addAdvSearchQuery?: (builderName: string, query: AdvancedSearchQuery) => void;
Expand All @@ -77,7 +70,6 @@ export type CustomListEditorProps = {

export default function CustomListEditor({
autoUpdateStatus,
collections,
entries,
entryPoints,
isAutoUpdateEnabled,
Expand Down Expand Up @@ -109,7 +101,6 @@ export default function CustomListEditor({
save,
search,
share,
toggleCollection,
updateProperty,
updateSearchParam,
addAdvSearchQuery,
Expand All @@ -119,7 +110,7 @@ export default function CustomListEditor({
removeAdvSearchQuery,
selectAdvSearchQuery,
}: CustomListEditorProps) {
const { collections: listCollections, name } = properties;
const { name } = properties;

// Automatically execute the search when the list being edited changes, or finishes loading
// (which means a stored query may have been loaded).
Expand Down Expand Up @@ -234,36 +225,6 @@ export default function CustomListEditor({
/>
)}

{collections?.length > 0 && (
<div className="custom-list-filters">
<Panel
headerText="Add from collections"
id="add-from-collections"
content={
<div className="collections">
<div>
Automatically add new books from these collections to this
list:
</div>

{collections.map(({ id, name }) => (
<EditableInput
disabled={readOnly}
key={id}
type="checkbox"
name="collection"
checked={listCollections.includes(id)}
label={name}
value={id}
onChange={(id) => toggleCollection?.(parseInt(id))}
/>
))}
</div>
}
/>
</div>
)}

<CustomListSearch
autoUpdate={properties.autoUpdate}
isOwner={isOwner}
Expand Down
84 changes: 9 additions & 75 deletions src/components/__tests__/CustomListEditor-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe("CustomListEditor", () => {
let save;
let search;
let share;
let toggleCollection;
let loadMoreSearchResults;
let loadMoreEntries;
let updateProperty;
Expand All @@ -35,27 +34,6 @@ describe("CustomListEditor", () => {
navigationLinks: [],
};

const collections = [
{
id: 1,
name: "collection 1",
protocol: "protocol",
libraries: [{ short_name: "library" }],
},
{
id: 2,
name: "collection 2",
protocol: "protocol",
libraries: [{ short_name: "library" }],
},
{
id: 3,
name: "collection 3",
protocol: "protocol",
libraries: [{ short_name: "library" }],
},
];

const entries = {
baseline: [],
baselineTotalCount: 0,
Expand Down Expand Up @@ -118,7 +96,6 @@ describe("CustomListEditor", () => {

search = stub();
share = stub();
toggleCollection = stub();
updateProperty = stub();
updateSearchParam = stub();

Expand Down Expand Up @@ -146,7 +123,6 @@ describe("CustomListEditor", () => {

wrapper = mount(
<CustomListEditor
collections={collections}
entries={entries}
entryPoints={entryPoints}
isFetchingMoreCustomListEntries={false}
Expand All @@ -168,7 +144,6 @@ describe("CustomListEditor", () => {
save={save}
search={search}
share={share}
toggleCollection={toggleCollection}
updateProperty={updateProperty}
updateSearchParam={updateSearchParam}
/>,
Expand Down Expand Up @@ -269,38 +244,6 @@ describe("CustomListEditor", () => {
expect(entriesEditor.props().opdsFeedUrl).to.equal(undefined);
});

it("shows collections", () => {
const collectionsPanel = wrapper.find("#add-from-collections-panel");
const inputs = collectionsPanel.find(EditableInput);

expect(inputs.length).to.equal(3);

expect(inputs.at(0).props().label).to.equal("collection 1");
expect(inputs.at(0).props().value).to.equal(1);
expect(inputs.at(0).props().checked).to.equal(false);

expect(inputs.at(1).props().label).to.equal("collection 2");
expect(inputs.at(1).props().value).to.equal(2);
expect(inputs.at(1).props().checked).to.equal(true);

expect(inputs.at(2).props().label).to.equal("collection 3");
expect(inputs.at(2).props().value).to.equal(3);
expect(inputs.at(2).props().checked).to.equal(false);
});

it("disables collection inputs when isOwner is false", () => {
wrapper.setProps({
isOwner: false,
});

const collectionsPanel = wrapper.find("#add-from-collections-panel");
const inputs = collectionsPanel.find(EditableInput);

expect(inputs.at(0).prop("disabled")).to.equal(true);
expect(inputs.at(1).prop("disabled")).to.equal(true);
expect(inputs.at(2).prop("disabled")).to.equal(true);
});

it("disables entry point options when isOwner is false", () => {
wrapper.setProps({
isOwner: false,
Expand All @@ -316,17 +259,17 @@ describe("CustomListEditor", () => {
it("shows entry point options", () => {
const inputs = wrapper.find(EditableInput);

expect(inputs.at(3).props().label).to.equal("All");
expect(inputs.at(3).props().value).to.equal("All");
expect(inputs.at(3).props().checked).to.equal(true);
expect(inputs.at(0).props().label).to.equal("All");
expect(inputs.at(0).props().value).to.equal("All");
expect(inputs.at(0).props().checked).to.equal(true);

expect(inputs.at(4).props().label).to.equal("Book");
expect(inputs.at(4).props().value).to.equal("Book");
expect(inputs.at(4).props().checked).to.equal(false);
expect(inputs.at(1).props().label).to.equal("Book");
expect(inputs.at(1).props().value).to.equal("Book");
expect(inputs.at(1).props().checked).to.equal(false);

expect(inputs.at(5).props().label).to.equal("Audio");
expect(inputs.at(5).props().value).to.equal("Audio");
expect(inputs.at(5).props().checked).to.equal(false);
expect(inputs.at(2).props().label).to.equal("Audio");
expect(inputs.at(2).props().value).to.equal("Audio");
expect(inputs.at(2).props().checked).to.equal(false);
});

it("enables the save button when the list has changes and is valid", () => {
Expand Down Expand Up @@ -398,15 +341,6 @@ describe("CustomListEditor", () => {
expect(buttonContainer.length).to.equal(0);
});

it("calls toggleCollection when a collection checkbox is changed", () => {
const inputs = wrapper.find(".collections input");

inputs.at(1).simulate("change");

expect(toggleCollection.callCount).to.equal(1);
expect(toggleCollection.args[0]).to.deep.equal([2]);
});

it("renders a CustomListSearch component", () => {
wrapper.setProps({ startingTitle: "Begin the Begin" });

Expand Down