split-test-badge.stories.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import type { Meta, StoryObj } from '@storybook/react-webpack5'
  2. import SplitTestBadge from '../../js/shared/components/split-test-badge'
  3. import { SplitTestContext } from '../../js/shared/context/split-test-context'
  4. type Story = StoryObj<typeof SplitTestBadge>
  5. const splitTestContextValue = {
  6. splitTestVariants: {} as Record<string, string>,
  7. splitTestInfo: {} as Record<string, any>,
  8. }
  9. export const Alpha: Story = {
  10. render: args => {
  11. splitTestContextValue.splitTestVariants = {
  12. 'storybook-test': 'active',
  13. }
  14. splitTestContextValue.splitTestInfo = {
  15. 'storybook-test': {
  16. phase: 'alpha',
  17. badgeInfo: {
  18. url: '/alpha/participate',
  19. tooltipText: 'This is an alpha feature',
  20. },
  21. },
  22. }
  23. return <SplitTestBadge {...args} />
  24. },
  25. }
  26. export const AlphaNotDisplayed: Story = {
  27. render: args => {
  28. splitTestContextValue.splitTestVariants = {
  29. 'storybook-test': 'default',
  30. }
  31. splitTestContextValue.splitTestInfo = {
  32. 'storybook-test': {
  33. phase: 'alpha',
  34. badgeInfo: {
  35. url: '/alpha/participate',
  36. tooltipText: 'This is an alpha feature',
  37. },
  38. },
  39. }
  40. return <SplitTestBadge {...args} />
  41. },
  42. }
  43. export const Beta: Story = {
  44. render: args => {
  45. splitTestContextValue.splitTestVariants = {
  46. 'storybook-test': 'active',
  47. }
  48. splitTestContextValue.splitTestInfo = {
  49. 'storybook-test': {
  50. phase: 'beta',
  51. badgeInfo: {
  52. url: '/beta/participate',
  53. tooltipText: 'This is a beta feature',
  54. },
  55. },
  56. }
  57. return <SplitTestBadge {...args} />
  58. },
  59. }
  60. export const BetaNotDisplayed: Story = {
  61. render: args => {
  62. splitTestContextValue.splitTestVariants = {
  63. 'storybook-test': 'default',
  64. }
  65. splitTestContextValue.splitTestInfo = {
  66. 'storybook-test': {
  67. phase: 'beta',
  68. badgeInfo: {
  69. url: '/beta/participate',
  70. tooltipText: 'This is a beta feature',
  71. },
  72. },
  73. }
  74. return <SplitTestBadge {...args} />
  75. },
  76. }
  77. export const Release: Story = {
  78. render: args => {
  79. splitTestContextValue.splitTestVariants = {
  80. 'storybook-test': 'active',
  81. }
  82. splitTestContextValue.splitTestInfo = {
  83. 'storybook-test': {
  84. phase: 'release',
  85. badgeInfo: {
  86. url: '/feedback/form',
  87. tooltipText: 'This is a new feature',
  88. },
  89. },
  90. }
  91. return <SplitTestBadge {...args} />
  92. },
  93. }
  94. export const ReleaseNotDisplayed: Story = {
  95. render: args => {
  96. splitTestContextValue.splitTestVariants = {
  97. 'storybook-test': 'default',
  98. }
  99. splitTestContextValue.splitTestInfo = {
  100. 'storybook-test': {
  101. phase: 'release',
  102. badgeInfo: {
  103. url: '/feedback/form',
  104. tooltipText: 'This is a new feature',
  105. },
  106. },
  107. }
  108. return <SplitTestBadge {...args} />
  109. },
  110. }
  111. const meta: Meta<typeof SplitTestBadge> = {
  112. title: 'Shared / Components / Split Test Badge',
  113. component: SplitTestBadge,
  114. parameters: {
  115. controls: {
  116. include: ['splitTestName', 'tooltip'],
  117. },
  118. },
  119. argTypes: {
  120. splitTestName: { control: 'text' },
  121. tooltip: { control: 'text' },
  122. },
  123. args: {
  124. splitTestName: 'storybook-test',
  125. displayOnVariants: ['active'],
  126. },
  127. decorators: [
  128. Story => (
  129. <SplitTestContext.Provider value={splitTestContextValue}>
  130. <Story />
  131. </SplitTestContext.Provider>
  132. ),
  133. ],
  134. }
  135. export default meta