diff --git a/app/search/templates/document.html b/app/search/templates/document.html index 0e74826..597c6ef 100644 --- a/app/search/templates/document.html +++ b/app/search/templates/document.html @@ -17,7 +17,7 @@
-
+
{{ result.type }}

{{ result.title }}

diff --git a/app/search/templates/intro.html b/app/search/templates/intro.html index d47906f..9257bf9 100644 --- a/app/search/templates/intro.html +++ b/app/search/templates/intro.html @@ -1,6 +1,8 @@
-
+

{{service_name_long}}

+
+

From: Department for Business and Trade

diff --git a/front_end/stylesheets/helpers.scss b/front_end/stylesheets/helpers.scss index bfbaf02..370b7dc 100644 --- a/front_end/stylesheets/helpers.scss +++ b/front_end/stylesheets/helpers.scss @@ -59,8 +59,8 @@ } -.fbr-max-height-250 { - max-height: 250px; +.fbr-max-height-350 { + max-height: 350px; } .fbr-flex { @@ -88,3 +88,17 @@ font-weight: bold; background-color: inherit; } + +.fbr-clickable-tag { + border: none; + background: govuk-colour("light-grey"); + padding: 2px 4px; + font: inherit; + cursor: pointer; + outline: inherit; + + &:active, &:focus { + outline: 3px solid #ffdd00; + box-shadow: inset 0 0 0 4px #0b0c0c; + } +} diff --git a/react_front_end/src/App.js b/react_front_end/src/App.js index 16a14a2..8b2ca93 100644 --- a/react_front_end/src/App.js +++ b/react_front_end/src/App.js @@ -114,6 +114,14 @@ function App() { fetchDataWithLoading(filterParams) }, [searchInput, docTypeQuery, publisherQuery, sortQuery, setPageQuery]) + const handlePublisherClick = (publisherKey) => { + if (publisherQuery.includes(publisherKey)) return false + + const updatedPublisherQuery = [...publisherQuery, publisherKey] + setPublisherQuery(updatedPublisherQuery) + setPublisherCheckedState(generateCheckedState(publishers, updatedPublisherQuery)) + } + useEffect(() => { if (isSearchSubmitted) { setIsSearchSubmitted(false) @@ -243,7 +251,13 @@ function App() { {data.results_total_count === 0 && !isLoading ? ( ) : ( - + )} diff --git a/react_front_end/src/components/Results.js b/react_front_end/src/components/Results.js index 520a0c9..c1c0bb5 100644 --- a/react_front_end/src/components/Results.js +++ b/react_front_end/src/components/Results.js @@ -1,7 +1,7 @@ import { SkeletonResults } from "./SkeletonResults" import { formatDateToGovukStyle } from "../utils/date" -function Results({ results, isLoading, searchQuery = "" }) { +function Results({ results, isLoading, searchQuery = "", publishers, onPublisherClick }) { if (isLoading) { return } @@ -50,6 +50,7 @@ function Results({ results, isLoading, searchQuery = "" }) { {results.map((result) => { const { id, type, title, description, publisher, date_modified, date_valid, regulatory_topics } = result + const publisherName = publishers.find((publisherName) => publisherName.label === publisher).name // const highlightedTitle = title ? : "" const highlightedDescription = description ? truncateAndHighlightDescription(description) : "" @@ -66,7 +67,17 @@ function Results({ results, isLoading, searchQuery = "" }) {

{highlightedDescription}

-

Published by: {publisher}

+

+ Published by:{" "} + +

Last updated: {govukDate}

{regulatory_topics && regulatory_topics.length > 0 ? (
    {renderRegulatoryTopics(regulatory_topics, searchQuery)}
diff --git a/react_front_end/src/components/__tests__/Results.test.js b/react_front_end/src/components/__tests__/Results.test.js index 2107855..e0d812d 100644 --- a/react_front_end/src/components/__tests__/Results.test.js +++ b/react_front_end/src/components/__tests__/Results.test.js @@ -1,5 +1,5 @@ import React from "react" -import { render, screen } from "@testing-library/react" +import { render, screen, fireEvent } from "@testing-library/react" import "@testing-library/jest-dom" import { Results } from "../Results" import { SkeletonResults } from "../SkeletonResults" @@ -32,35 +32,82 @@ describe("Results", () => { }, ] + const mockPublishers = [ + { name: "test-publisher", label: "Test Publisher" }, + { name: "another-publisher", label: "Another Publisher" }, + ] + + const mockOnPublisherClick = jest.fn() + test("renders SkeletonResults when isLoading is true", () => { - render() + render( + , + ) expect(screen.getByTestId("skeleton-results")).toBeInTheDocument() }) test("renders results when isLoading is false", () => { - render() + render( + , + ) expect(screen.getByText("Test Document 1")).toBeInTheDocument() expect(screen.getByText("Test Document 2")).toBeInTheDocument() }) - // test("highlights search query in title and description", () => { - // render() - // expect(screen.getByText("Test Document 1")).toBeInTheDocument() - // expect(screen.getByText("Test Document 2")).toBeInTheDocument() - // expect(screen.getByText("This is a test document description.")).toBeInTheDocument() - // expect(screen.getByText("Another test document description.")).toBeInTheDocument() - // }) - test("renders regulatory topics", () => { - render() + render( + , + ) expect(screen.getByText("Topic 1")).toBeInTheDocument() expect(screen.getByText("Topic 2")).toBeInTheDocument() expect(screen.getByText("Topic 3")).toBeInTheDocument() }) test("formats date to GOV.UK style", () => { - render() + render( + , + ) expect(screen.getByText("Last updated: 1 January 2023")).toBeInTheDocument() expect(screen.getByText("Last updated: 1 February 2023")).toBeInTheDocument() }) + + test("calls onPublisherClick with the correct publisher key", () => { + render( + , + ) + fireEvent.click(screen.getByText("Test Publisher")) + expect(mockOnPublisherClick).toHaveBeenCalledWith("test-publisher") + fireEvent.click(screen.getByText("Another Publisher")) + expect(mockOnPublisherClick).toHaveBeenCalledWith("another-publisher") + }) })