Skip to content

Commit

Permalink
feat(app): Hide download button when download agreement has not been …
Browse files Browse the repository at this point in the history
…accepted
  • Loading branch information
nellh committed Nov 27, 2023
1 parent 37cd217 commit 1ab00f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react"
import { DatasetToolButton } from "./DatasetToolButton"
import styled, { StyledComponent } from "@emotion/styled"
import { useAgreement } from "../../components/agreement.tsx"

interface DatasetToolStyleProps {}

Expand Down Expand Up @@ -32,6 +33,7 @@ export const DatasetTools = ({
isDatasetAdmin,
hasDerivatives,
}: DatasetToolsProps) => {
const [agree] = useAgreement()
const isSnapshot = snapshotId
return (
<DatasetToolStyle>
Expand Down Expand Up @@ -96,14 +98,16 @@ export const DatasetTools = ({
label="Admin"
/>
)}
<DatasetToolButton
tooltip="How to Download"
path={snapshotId
? `/datasets/${datasetId}/versions/${snapshotId}/download`
: `/datasets/${datasetId}/download`}
icon="fa-download"
label="Download"
/>
{agree && (
<DatasetToolButton
tooltip="How to Download"
path={snapshotId
? `/datasets/${datasetId}/versions/${snapshotId}/download`
: `/datasets/${datasetId}/download`}
icon="fa-download"
label="Download"
/>
)}
{hasDerivatives && (
<DatasetToolButton
tooltip="Available Derivatives"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import React from "react"
import { render, screen } from "@testing-library/react"
import { MemoryRouter } from "react-router-dom"
import { DatasetTools } from "../DatasetTools"
import { LocalStorageProvider } from "../../../utils/local-storage"

const wrapper = ({ children }) => (
<MemoryRouter>
<LocalStorageProvider defaultValue={{ agreement: true }}>
{children}
</LocalStorageProvider>
</MemoryRouter>
)

describe("DatasetTools component", () => {
it("provides expected tools for a draft (admin)", () => {
Expand All @@ -14,7 +23,7 @@ describe("DatasetTools component", () => {
hasSnapshot={true}
isDatasetAdmin={true}
/>,
{ wrapper: MemoryRouter },
{ wrapper },
)
expect(screen.queryByLabelText("Files")).toBeInTheDocument()
expect(screen.queryByLabelText("Share")).toBeInTheDocument()
Expand All @@ -36,7 +45,7 @@ describe("DatasetTools component", () => {
hasSnapshot={true}
isDatasetAdmin={true}
/>,
{ wrapper: MemoryRouter },
{ wrapper },
)
expect(screen.queryByLabelText("Files")).toBeInTheDocument()
expect(screen.queryByLabelText("View Draft")).toBeInTheDocument()
Expand All @@ -55,7 +64,7 @@ describe("DatasetTools component", () => {
hasSnapshot={true}
isDatasetAdmin={false}
/>,
{ wrapper: MemoryRouter },
{ wrapper },
)
expect(screen.queryByLabelText("Files")).toBeInTheDocument()
expect(screen.queryByLabelText("View Draft")).not.toBeInTheDocument()
Expand All @@ -75,7 +84,7 @@ describe("DatasetTools component", () => {
hasSnapshot={true}
isDatasetAdmin={false}
/>,
{ wrapper: MemoryRouter },
{ wrapper },
)
expect(screen.queryByLabelText("Files")).toBeInTheDocument()
expect(screen.queryByLabelText("View Draft")).not.toBeInTheDocument()
Expand All @@ -94,7 +103,7 @@ describe("DatasetTools component", () => {
hasSnapshot={true}
isDatasetAdmin={false}
/>,
{ wrapper: MemoryRouter },
{ wrapper },
)
expect(screen.queryByLabelText("Download")).toBeInTheDocument()
expect(screen.queryByRole("link", { name: "Download" })).toHaveAttribute(
Expand All @@ -113,7 +122,7 @@ describe("DatasetTools component", () => {
hasSnapshot={true}
isDatasetAdmin={false}
/>,
{ wrapper: MemoryRouter },
{ wrapper },
)
expect(screen.queryByLabelText("Download")).toBeInTheDocument()
expect(screen.queryByRole("link", { name: "Download" })).toHaveAttribute(
Expand Down

0 comments on commit 1ab00f7

Please sign in to comment.