overleaf/services/web/frontend/stories/word-count-modal.stories.js
Alf Eaton c8f139cced Merge pull request #3707 from overleaf/ae-refactor-word-count-modal
Refactor "Word Count" modal

GitOrigin-RevId: 00561b5b3f8f161238321c440ecde67cd42ece1c
2021-03-06 03:04:42 +00:00

76 lines
1.7 KiB
JavaScript

import React from 'react'
import fetchMock from 'fetch-mock'
import PropTypes from 'prop-types'
import WordCountModal from '../js/features/word-count-modal/components/word-count-modal'
export const Interactive = ({
mockResponse = 200,
mockResponseDelay = 500,
...args
}) => {
fetchMock.restore().get(
'express:/project/:projectId/wordcount',
() => {
switch (mockResponse) {
case 400:
return { status: 400, body: 'The project id is not valid' }
case 200:
return {
texcount: {
headers: 4,
mathDisplay: 40,
mathInline: 400,
textWords: 4000
}
}
default:
return mockResponse
}
},
{ delay: mockResponseDelay }
)
return <WordCountModal {...args} />
}
Interactive.propTypes = {
mockResponse: PropTypes.number,
mockResponseDelay: PropTypes.number
}
export default {
title: 'Word Count Modal',
component: WordCountModal,
args: {
clsiServerId: 'server-id',
projectId: 'project-id',
show: true
},
argTypes: {
handleHide: { action: 'handleHide' },
mockResponse: {
name: 'Mock Response Status',
type: { name: 'number', required: false },
description: 'The status code that should be returned by the mock server',
defaultValue: 200,
control: {
type: 'radio',
options: [200, 500, 400]
}
},
mockResponseDelay: {
name: 'Mock Response Delay',
type: { name: 'number', required: false },
description: 'The delay before returning a response from the mock server',
defaultValue: 500,
control: {
type: 'range',
min: 0,
max: 2500,
step: 250
}
}
}
}