toast-command-call.test.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Toast, Icon, Button } from '../../index';
  2. import { advanceBy, advanceTo, clear } from 'jest-date-mock';
  3. import sleep from '@douyinfe/semi-ui/_test_/utils/function/sleep';
  4. import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants';
  5. import { JSDOM } from 'jsdom';
  6. import { mount } from 'enzyme';
  7. describe('Toast - 2', () => {
  8. beforeEach(() => {
  9. // semi-animation会使用Date.now(),所以这里需要clear掉全局的advanceTo对Date的修改
  10. clear();
  11. const tw = document.querySelector(`.${BASE_CLASS_PREFIX}-toast-wrapper`);
  12. if (tw) {
  13. tw.innerHTML = '';
  14. }
  15. });
  16. afterEach(() => {});
  17. it('close via command call & duration = 0', async () => {
  18. let opts = {
  19. content: 'close by manual',
  20. duration: 0,
  21. motion:false
  22. };
  23. let id = Toast.info(opts);
  24. let toast = document.getElementsByClassName(`${BASE_CLASS_PREFIX}-toast-info`);
  25. expect(toast.length).toEqual(1);
  26. Toast.close(id);
  27. // wait, make sure react had update render content
  28. await sleep(400);
  29. expect(toast.length).toEqual(0);
  30. });
  31. it('different type toast', () => {
  32. Toast.info({ content: 'info' });
  33. Toast.success({ content: 'success' });
  34. Toast.warning({ content: 'warning' });
  35. Toast.error({ content: 'error' });
  36. expect(document.querySelector(`.${BASE_CLASS_PREFIX}-toast-info .${BASE_CLASS_PREFIX}-toast-content-text`).innerHTML).toEqual('info');
  37. expect(document.querySelector(`.${BASE_CLASS_PREFIX}-toast-success .${BASE_CLASS_PREFIX}-toast-content-text`).innerHTML).toEqual('success');
  38. expect(document.querySelector(`.${BASE_CLASS_PREFIX}-toast-warning .${BASE_CLASS_PREFIX}-toast-content-text`).innerHTML).toEqual('warning');
  39. expect(document.querySelector(`.${BASE_CLASS_PREFIX}-toast-error .${BASE_CLASS_PREFIX}-toast-content-text`).innerHTML).toEqual('error');
  40. });
  41. it('top/bottom/right/left', () => {
  42. let opts = {
  43. content: 'Hi, Bytedance dance dance',
  44. duration: 0,
  45. top: 500,
  46. left: 20,
  47. bottom: 30,
  48. right: 40,
  49. };
  50. Toast.info(opts);
  51. let toastWrapper = document.getElementsByClassName(`${BASE_CLASS_PREFIX}-toast-wrapper`)[0];
  52. let style = toastWrapper.style;
  53. expect(style.top).toEqual('500px');
  54. expect(style.left).toEqual('20px');
  55. expect(style.bottom).toEqual('30px');
  56. expect(style.right).toEqual('40px');
  57. });
  58. });