steps.test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. import React from 'react';
  2. import { mount } from 'enzyme';
  3. import sinon from 'sinon';
  4. import { stepsClasses } from '@douyinfe/semi-foundation/steps/constants';
  5. import Steps from '../index';
  6. import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants';
  7. const Step = Steps.Step;
  8. describe('Steps', () => {
  9. it('current works', () => {
  10. const element = (
  11. <Steps current={0}>
  12. <Step>Step.1</Step>
  13. <Step>Step.1</Step>
  14. <Step>Step.1</Step>
  15. </Steps>
  16. );
  17. const wrapper = mount(element);
  18. expect(
  19. wrapper
  20. .find('Step')
  21. .at(0)
  22. .props().status
  23. ).toEqual('process');
  24. });
  25. it('parent status works', () => {
  26. const wait = (
  27. <Steps status="wait" current={0}>
  28. <Step>Step.1</Step>
  29. <Step>Step.1</Step>
  30. <Step>Step.1</Step>
  31. </Steps>
  32. );
  33. const waitWrapper = mount(wait);
  34. expect(
  35. waitWrapper.props().status
  36. ).toEqual('wait');
  37. waitWrapper.unmount();
  38. const error = (
  39. <Steps status="error" current={0}>
  40. <Step>Step.1</Step>
  41. <Step>Step.1</Step>
  42. <Step>Step.1</Step>
  43. </Steps>
  44. );
  45. const errorWrapper = mount(error);
  46. expect(
  47. errorWrapper.props().status
  48. ).toEqual('error');
  49. errorWrapper.unmount();
  50. const finish = (
  51. <Steps status="finish" current={0}>
  52. <Step>Step.1</Step>
  53. <Step>Step.1</Step>
  54. <Step>Step.1</Step>
  55. </Steps>
  56. );
  57. const finishWrapper = mount(finish);
  58. expect(
  59. finishWrapper.props().status
  60. ).toEqual('finish');
  61. finishWrapper.unmount();
  62. const process = (
  63. <Steps status="process" current={0}>
  64. <Step>Step.1</Step>
  65. <Step>Step.1</Step>
  66. <Step>Step.1</Step>
  67. </Steps>
  68. );
  69. const processWrapper = mount(process);
  70. expect(
  71. processWrapper.props().status
  72. ).toEqual('process');
  73. processWrapper.unmount();
  74. const warning = (
  75. <Steps status="warning" current={0}>
  76. <Step>Step.1</Step>
  77. <Step>Step.1</Step>
  78. <Step>Step.1</Step>
  79. </Steps>
  80. );
  81. const warningWrapper = mount(warning);
  82. expect(
  83. warningWrapper.props().status
  84. ).toEqual('warning');
  85. warningWrapper.unmount();
  86. });
  87. it('child status works', () => {
  88. const wait = (
  89. <Steps current={0}>
  90. <Step status="wait">Step.1</Step>
  91. <Step>Step.1</Step>
  92. <Step>Step.1</Step>
  93. </Steps>
  94. );
  95. const waitWrapper = mount(wait);
  96. expect(
  97. waitWrapper
  98. .find('Step')
  99. .at(0)
  100. .props().status
  101. ).toEqual('wait');
  102. waitWrapper.unmount();
  103. const error = (
  104. <Steps current={0}>
  105. <Step status="error">Step.1</Step>
  106. <Step>Step.1</Step>
  107. <Step>Step.1</Step>
  108. </Steps>
  109. );
  110. const errorWrapper = mount(error);
  111. expect(
  112. errorWrapper
  113. .find('Step')
  114. .at(0)
  115. .props().status
  116. ).toEqual('error');
  117. errorWrapper.unmount();
  118. const finish = (
  119. <Steps current={0}>
  120. <Step status="finish">Step.1</Step>
  121. <Step>Step.1</Step>
  122. <Step>Step.1</Step>
  123. </Steps>
  124. );
  125. const finishWrapper = mount(finish);
  126. expect(
  127. finishWrapper
  128. .find('Step')
  129. .at(0)
  130. .props().status
  131. ).toEqual('finish');
  132. finishWrapper.unmount();
  133. const process = (
  134. <Steps current={0}>
  135. <Step status="process">Step.1</Step>
  136. <Step>Step.1</Step>
  137. <Step>Step.1</Step>
  138. </Steps>
  139. );
  140. const processWrapper = mount(process);
  141. expect(
  142. processWrapper
  143. .find('Step')
  144. .at(0)
  145. .props().status
  146. ).toEqual('process');
  147. processWrapper.unmount();
  148. const warning = (
  149. <Steps current={0}>
  150. <Step status="warning">Step.1</Step>
  151. <Step>Step.1</Step>
  152. <Step>Step.1</Step>
  153. </Steps>
  154. );
  155. const warningWrapper = mount(warning);
  156. expect(
  157. warningWrapper
  158. .find('Step')
  159. .at(0)
  160. .props().status
  161. ).toEqual('warning');
  162. warningWrapper.unmount();
  163. });
  164. it('initial works', () => {
  165. const element = (
  166. <Steps status="warning" initial={1} current={1}>
  167. <Step>Step.1</Step>
  168. <Step>Step.1</Step>
  169. <Step>Step.1</Step>
  170. </Steps>
  171. );
  172. const wrapper = mount(element);
  173. expect(
  174. wrapper
  175. .find('Step')
  176. .at(0)
  177. .props().status
  178. ).toEqual('warning');
  179. });
  180. it('FillStep onClick works', () => {
  181. const spyOnClick = sinon.fake();
  182. const element = (
  183. <Steps status="warning" initial={1} current={1}>
  184. <Step onClick={spyOnClick}>Step.1</Step>
  185. <Step>Step.1</Step>
  186. <Step>Step.1</Step>
  187. </Steps>
  188. );
  189. const wrapper = mount(element);
  190. const fiestStepContainer = wrapper.find('Step').at(0).find(`.${stepsClasses.ITEM}`);
  191. fiestStepContainer.simulate('click');
  192. expect(spyOnClick.calledOnce).toEqual(true);
  193. });
  194. it('BasicStep onClick works', () => {
  195. const spyOnClick = sinon.fake();
  196. const element = (
  197. <Steps type='basic' status="warning" initial={1} current={1}>
  198. <Step onClick={spyOnClick}>Step.1</Step>
  199. <Step>Step.1</Step>
  200. <Step>Step.1</Step>
  201. </Steps>
  202. );
  203. const wrapper = mount(element);
  204. const fiestStepContainer = wrapper.find('Step').at(0).find(`.${stepsClasses.ITEM}`);
  205. fiestStepContainer.simulate('click');
  206. expect(spyOnClick.calledOnce).toEqual(true);
  207. });
  208. it('NavStep onClick works', () => {
  209. const spyOnClick = sinon.fake();
  210. const element = (
  211. <Steps type='nav' status="warning" initial={1} current={1}>
  212. <Step onClick={spyOnClick}>Step.1</Step>
  213. <Step>Step.1</Step>
  214. <Step>Step.1</Step>
  215. </Steps>
  216. );
  217. const wrapper = mount(element);
  218. const fiestStepContainer = wrapper.find('Step').at(0).find(`.${stepsClasses.ITEM}`);
  219. fiestStepContainer.simulate('click');
  220. expect(spyOnClick.calledOnce).toEqual(true);
  221. });
  222. it('Steps onChange works', () => {
  223. const spyOnChange = sinon.fake();
  224. const element = (
  225. <Steps status="warning" initial={1} onChange={spyOnChange} current={1}>
  226. <Step>Step.1</Step>
  227. <Step>Step.1</Step>
  228. <Step>Step.1</Step>
  229. </Steps>
  230. );
  231. const wrapper = mount(element);
  232. const fiestStepContainer = wrapper.find('Step').at(1).find(`.${stepsClasses.ITEM}`);
  233. fiestStepContainer.simulate('click');
  234. expect(spyOnChange.calledOnce).toEqual(false);
  235. const fiestStepContainer2 = wrapper.find('Step').at(0).find(`.${stepsClasses.ITEM}`);
  236. fiestStepContainer2.simulate('click');
  237. expect(spyOnChange.calledOnce).toEqual(true);
  238. });
  239. it('Steps type', () => {
  240. const nav = (
  241. <Steps type="nav" current={1}>
  242. <Step title="Finished" />
  243. <Step title="In Progress" />
  244. <Step title="Waiting" />
  245. </Steps>
  246. );
  247. const navWrapper = mount(nav);
  248. expect(navWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-nav`)).toEqual(true);
  249. navWrapper.unmount();
  250. const basic = (
  251. <Steps type="basic" current={1}>
  252. <Step title="Finished" />
  253. <Step title="In Progress" />
  254. <Step title="Waiting" />
  255. </Steps>
  256. );
  257. const basicWrapper = mount(basic);
  258. expect(basicWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-basic`)).toEqual(true);
  259. basicWrapper.unmount();
  260. const fill = (
  261. <Steps type="fill" current={1}>
  262. <Step title="Finished" />
  263. <Step title="In Progress" />
  264. <Step title="Waiting" />
  265. </Steps>
  266. );
  267. const fillWrapper = mount(fill);
  268. expect(fillWrapper.exists(`.${BASE_CLASS_PREFIX}-steps`)).toEqual(true);
  269. fillWrapper.unmount();
  270. });
  271. it('Steps with custom className & style', () => {
  272. const wrapper = mount(
  273. <Steps className='test' style={{ color: 'red' }}>
  274. <Step title="Finished" />
  275. <Step title="In Progress" />
  276. <Step title="Waiting" />
  277. </Steps>
  278. );
  279. expect(wrapper.exists('.test')).toEqual(true);
  280. expect(wrapper.find(`.${BASE_CLASS_PREFIX}-steps.test`)).toHaveStyle('color', 'red');
  281. });
  282. it('Step with custom className & style', () => {
  283. const wrapper = mount(
  284. <Steps >
  285. <Step className='test' style={{ color: 'blue' }} title="Finished" />
  286. <Step title="In Progress" />
  287. <Step title="Waiting" />
  288. </Steps>
  289. );
  290. const firstStep = wrapper.find('Step').at(0);
  291. expect(firstStep.exists('.test')).toEqual(true);
  292. expect(firstStep).toHaveStyle('color', 'blue');
  293. });
  294. it('Steps with size', () => {
  295. const wrapper = mount(
  296. <Steps type="basic" size='small'>
  297. <Step className='test' style={{ color: 'red' }} title="Finished" />
  298. <Step title="In Progress" />
  299. <Step title="Waiting" />
  300. </Steps>
  301. );
  302. expect(wrapper.exists(`.${BASE_CLASS_PREFIX}-steps-small`)).toEqual(true);
  303. });
  304. it('Steps with hasLine', () => {
  305. const hasLineWrapper = mount(
  306. <Steps type="basic" hasLine={true} current={1}>
  307. <Step title="Finished" description="This is a description" />
  308. <Step title="In Progress" description="This is a description" />
  309. <Step title="Waiting" description="This is a description" />
  310. </Steps>
  311. );
  312. expect(hasLineWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-hasline`)).toEqual(true);
  313. hasLineWrapper.unmount();
  314. const noLineWrapper = mount(
  315. <Steps type="basic" hasLine={false} current={1}>
  316. <Step title="Finished" description="This is a description" />
  317. <Step title="In Progress" description="This is a description" />
  318. <Step title="Waiting" description="This is a description" />
  319. </Steps>
  320. );
  321. expect(noLineWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-hasline`)).toEqual(false);
  322. noLineWrapper.unmount();
  323. });
  324. it('Steps with direction', () => {
  325. const verticalWrapper = mount(
  326. <Steps direction="vertical" type="basic" current={1}>
  327. <Steps.Step title="Finished" description="This is a description" />
  328. <Steps.Step title="In Progress" description="This is a description" />
  329. <Steps.Step title="Waiting" description="This is a description" />
  330. </Steps>
  331. );
  332. expect(verticalWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-vertical`)).toEqual(true);
  333. verticalWrapper.unmount();
  334. const horizontalWrapper = mount(
  335. <Steps direction="horizontal" type="basic" current={1}>
  336. <Steps.Step title="Finished" description="This is a description" />
  337. <Steps.Step title="In Progress" description="This is a description" />
  338. <Steps.Step title="Waiting" description="This is a description" />
  339. </Steps>
  340. );
  341. expect(horizontalWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-horizontal`)).toEqual(true);
  342. horizontalWrapper.unmount();
  343. });
  344. });