From 7bb8abff254848590e98927aa805de421d78e6da Mon Sep 17 00:00:00 2001 From: Roy Johnson Date: Tue, 16 Jul 2024 16:30:52 -0500 Subject: [PATCH] Use amazon_link for BuyBook --- src/app/content/components/BuyBook.spec.tsx | 15 +- src/app/content/components/BuyBook.tsx | 15 +- src/app/content/components/Content.tsx | 7 +- .../__snapshots__/BuyBook.spec.tsx.snap | 71 +--- .../__snapshots__/Content.spec.tsx.snap | 325 +++++++----------- 5 files changed, 159 insertions(+), 274 deletions(-) diff --git a/src/app/content/components/BuyBook.spec.tsx b/src/app/content/components/BuyBook.spec.tsx index 0525a809e3a..c98cfa7ad9b 100644 --- a/src/app/content/components/BuyBook.spec.tsx +++ b/src/app/content/components/BuyBook.spec.tsx @@ -3,27 +3,34 @@ import renderer from 'react-test-renderer'; import createTestStore from '../../../test/createTestStore'; import TestContainer from '../../../test/TestContainer'; import { Store } from '../../types'; +import { Book } from '../types'; import BuyBook from './BuyBook'; describe('BuyBook', () => { let store: Store; + const bookWithLink = { + amazon_link: 'https://amazon.com/some-book', + } as Book; + const bookWithoutLink = { + amazon_link: '', + } as Book; beforeEach(() => { store = createTestStore(); }); - it('renders', () => { + it('renders when book has amazon_link', () => { const component = renderer.create( - + ); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); - it('returns null', () => { + it('returns null when book lacks amazon_link', () => { const component = renderer.create( - + ); const tree = component.toJSON(); diff --git a/src/app/content/components/BuyBook.tsx b/src/app/content/components/BuyBook.tsx index 87c2ccc2192..4755022c6e9 100644 --- a/src/app/content/components/BuyBook.tsx +++ b/src/app/content/components/BuyBook.tsx @@ -5,6 +5,7 @@ import { textRegularSize } from '../../components/Typography'; import theme from '../../theme'; import { contentTextWidth } from './constants'; import { disablePrint } from './utils/disablePrint'; +import { Book, BookWithOSWebData } from '../types'; // tslint:disable-next-line:variable-name const BuyBookAlignment = styled.div` @@ -33,17 +34,17 @@ const BuyBookLink = styled.a` `; // tslint:disable-next-line: variable-name -const BuyBook = () => { - const config = { - url: '*** placeholder ***', - }; +const BuyBook = ({book}: {book: Book}) => { + const bookWithOSwebData = book as BookWithOSWebData; -return -
*** Book link needs updated ***
+ if (!bookWithOSwebData.amazon_link) { + return null; + } + return diff --git a/src/app/content/components/Content.tsx b/src/app/content/components/Content.tsx index 7df8ed4a22b..801f3862ff4 100644 --- a/src/app/content/components/Content.tsx +++ b/src/app/content/components/Content.tsx @@ -7,6 +7,7 @@ import ErrorBoundary from '../../errors/components/ErrorBoundary'; import Notifications from '../../notifications/components/Notifications'; import theme from '../../theme'; import { AppState } from '../../types'; +import { Book } from '../types'; import HighlightsPopUp from '../highlights/components/HighlightsPopUp'; import KeyboardShortcutsPopup from '../keyboardShortcuts/components/KeyboardShortcutsPopup'; import PracticeQuestionsPopup from '../practiceQuestions/components/PracticeQuestionsPopup'; @@ -33,6 +34,7 @@ import PrevNextBar from './PrevNextBar'; import Navigation from './Navigation'; import Topbar from './Topbar'; import Wrapper from './Wrapper'; +import { book } from '../selectors'; // tslint:disable-next-line:variable-name const Background = styled.div` @@ -69,7 +71,7 @@ const OuterWrapper = styled.div` `; // tslint:disable-next-line:variable-name -const Content = ({mobileExpanded}: {mobileExpanded: boolean}) => +const Content = ({mobileExpanded, book: bookInfo}: {mobileExpanded: boolean; book: Book; }) => - +