Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions src/components/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ function Result({ fields, onClickLink, title, url }) {
return (
<li className="result">
<div className="result__header">
{!url && (
<span
className="result__title"
dangerouslySetInnerHTML={{ __html: title }}
/>
)}
{url && (
<a
className="result__title"
dangerouslySetInnerHTML={{ __html: title }}
href={url}
onClick={onClickLink}
target="_blank"
/>
)}
{title &&
!url && (
<span
className="result__title"
dangerouslySetInnerHTML={{ __html: title }}
/>
)}
{title &&
url && (
<a
className="result__title"
dangerouslySetInnerHTML={{ __html: title }}
href={url}
onClick={onClickLink}
target="_blank"
/>
)}
</div>
<div className="result__body">
<ul className="result__details">
Expand All @@ -40,7 +42,7 @@ function Result({ fields, onClickLink, title, url }) {

Result.propTypes = {
fields: PropTypes.object.isRequired,
title: PropTypes.string.isRequired,
title: PropTypes.string,
url: PropTypes.string
};

Expand Down
17 changes: 14 additions & 3 deletions src/components/Result.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import Result from "./Result";
import { shallow } from "enzyme";

const requiredProps = {
fields: { field: "value" },
title: "Title"
fields: { field: "value" }
};

it("renders correctly when there is a URL", () => {
Expand All @@ -14,7 +13,19 @@ it("renders correctly when there is a URL", () => {
expect(wrapper).toMatchSnapshot();
});

it("renders correctly when there is not a URL", () => {
it("renders correctly when there is not a URL or title", () => {
const wrapper = shallow(<Result {...requiredProps} />);
expect(wrapper).toMatchSnapshot();
});

it("renders correctly when there is a title", () => {
const wrapper = shallow(<Result {...requiredProps} title="Title" />);
expect(wrapper).toMatchSnapshot();
});

it("renders correctly when there is a title and url", () => {
const wrapper = shallow(
<Result {...requiredProps} title="Title" url="http://www.example.com" />
);
expect(wrapper).toMatchSnapshot();
});
82 changes: 77 additions & 5 deletions src/components/__snapshots__/Result.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,50 @@ exports[`renders correctly when there is a URL 1`] = `
>
<div
className="result__header"
/>
<div
className="result__body"
>
<a
<ul
className="result__details"
>
<li
key="field"
>
<span
className="result__key"
>
field
</span>

<span
className="result__value"
dangerouslySetInnerHTML={
Object {
"__html": "value",
}
}
/>
</li>
</ul>
</div>
</li>
`;

exports[`renders correctly when there is a title 1`] = `
<li
className="result"
>
<div
className="result__header"
>
<span
className="result__title"
dangerouslySetInnerHTML={
Object {
"__html": "Title",
}
}
href="http://www.example.com"
target="_blank"
/>
</div>
<div
Expand Down Expand Up @@ -47,20 +81,22 @@ exports[`renders correctly when there is a URL 1`] = `
</li>
`;

exports[`renders correctly when there is not a URL 1`] = `
exports[`renders correctly when there is a title and url 1`] = `
<li
className="result"
>
<div
className="result__header"
>
<span
<a
className="result__title"
dangerouslySetInnerHTML={
Object {
"__html": "Title",
}
}
href="http://www.example.com"
target="_blank"
/>
</div>
<div
Expand Down Expand Up @@ -91,3 +127,39 @@ exports[`renders correctly when there is not a URL 1`] = `
</div>
</li>
`;

exports[`renders correctly when there is not a URL or title 1`] = `
<li
className="result"
>
<div
className="result__header"
/>
<div
className="result__body"
>
<ul
className="result__details"
>
<li
key="field"
>
<span
className="result__key"
>
field
</span>

<span
className="result__value"
dangerouslySetInnerHTML={
Object {
"__html": "value",
}
}
/>
</li>
</ul>
</div>
</li>
`;
6 changes: 1 addition & 5 deletions src/config/config-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ export function getUrlFieldTemplate() {
export function getResultTitle(result) {
const titleField = getTitleField();

return (
result.getSnippet(titleField) ||
result.getRaw(titleField) ||
result.getRaw("id") // As a last resort, just show ID if nothing else
);
return result.getSnippet(titleField);
}

export function getResultUrl(result) {
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Results.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function capitalizeFirstLetter(string) {
*/
function formatResultFields(result) {
return Object.keys(result.data).reduce((acc, n) => {
let value = result.getSnippet(n) || result.getRaw(n);
let value = result.getSnippet(n);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehehe.

value = Array.isArray(value) ? value.join(", ") : value;
acc[`${capitalizeFirstLetter(n)}`] = value;
return acc;
Expand Down