diff --git a/.storybook/preview.js b/.storybook/preview.js index 8627357..180ba53 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -1,5 +1,29 @@ /** @type { import('@storybook/react').Preview } */ import "./style.css" +import { getMath, getComments } from "./utils"; + +// Needed at the very least for Graph component stories of UT-HAI client-deliberation. +import jquery from 'jquery'; +global.$ = jquery; +global.jQuery = jquery; + +// This is where we mock responses for PolisNet endpoints. +// TODO: Create a storybook plugin to do this dynamically. +function ajax_responses(responses) { + return function (params) { + const mockedPathname = new URL(params.url).pathname + const mockResponse = responses[mockedPathname] + var deferred = global.$.Deferred().resolve(mockResponse) + return deferred + }; +} + +global.$.ajax = ajax_responses({ + '/api/v3/math/pca2': getMath(), + '/api/v3/comments': [getComments()], + '/api/v3/votes': [], + '/api/v3/votes/famous': [], +}) const isGithubBuild = !!process.env["GITHUB_REPOSITORY"] const preview = { diff --git a/stories/UT-HAI/client-deliberation/VisualisationTutorial.stories.js b/stories/UT-HAI/client-deliberation/VisualisationTutorial.stories.js index 7635dd2..c69f0bd 100644 --- a/stories/UT-HAI/client-deliberation/VisualisationTutorial.stories.js +++ b/stories/UT-HAI/client-deliberation/VisualisationTutorial.stories.js @@ -8,7 +8,10 @@ export default { } // TODO: Need to mock PolisNet API calls. -const Template = (args) =>