Skip to content

Commit

Permalink
Use mock in StoryBook
Browse files Browse the repository at this point in the history
  • Loading branch information
fallaciousreasoning committed Oct 7, 2022
1 parent 98baf7f commit e51a105
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion components/brave_new_tab_ui/api/brave_news/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export default function getBraveNewsController () {
// doesn't try to connect, or pages which use exported types
// but ultimately don't fetch any data.
if (!braveNewsControllerInstance) {
braveNewsControllerInstance = BraveNews.BraveNewsController.getRemote()
// In Storybook, we have a mocked BraveNewsController because none of the
// mojo apis are available.
// @ts-expect-error
braveNewsControllerInstance = window.storybookBraveNewsController || BraveNews.BraveNewsController.getRemote()
}
return braveNewsControllerInstance
}
2 changes: 1 addition & 1 deletion components/brave_new_tab_ui/components/braveNews/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function BraveNewsModal () {
if (dialogRef.current?.open && !page) { dialogRef.current?.close?.() }
if (!dialogRef.current?.open && page) { dialogRef.current?.showModal?.() }
}, [page])
return <Dialog ref={dialogRef as any}>
return page && <Dialog ref={dialogRef as any}>
<Configure />
</Dialog>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { boolean } from '@storybook/addon-knobs'
import { BraveTodayState } from '../../../reducers/today'
import { feed, publishers } from './braveNewsController'
import { feed, publishers } from './mockBraveNewsController'

export default function getTodayState (): BraveTodayState {
const hasDataError = boolean('Today data fetch error?', false)
Expand Down
3 changes: 3 additions & 0 deletions components/brave_new_tab_ui/stories/regular.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

// Import BraveNewsControllerMock first.
import './default/data/mockBraveNewsController'

import * as React from 'react'
import { Dispatch } from 'redux'
import { Provider as ReduxProvider } from 'react-redux'
Expand Down

0 comments on commit e51a105

Please sign in to comment.