imagePreview.test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { Image, ImagePreview } from '../../index';
  2. import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants';
  3. function getImagePreview(imageProps) {
  4. const props = imageProps ? imageProps : {};
  5. const srcList = [
  6. "https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/abstract.jpg",
  7. "https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/sky.jpg",
  8. "https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/greenleaf.jpg",
  9. "https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/colorful.jpg",
  10. ];
  11. return (
  12. <ImagePreview {...props}>
  13. {srcList.map((src, index) => {
  14. return (
  15. <Image
  16. key={index}
  17. src={src}
  18. width={200}
  19. alt={`lamp${index + 1}`}
  20. style={{ marginRight: 5 }}
  21. />
  22. );
  23. })}
  24. </ImagePreview>
  25. )
  26. }
  27. describe('ImagePreview', () => {
  28. it('visible', function () {
  29. const imageComponent = getImagePreview();
  30. const image = mount(imageComponent, { attachTo: document.getElementById('container') });
  31. expect(image.exists(`div.${BASE_CLASS_PREFIX}-image-preview`)).toEqual(false);
  32. image.setProps({ visible: true })
  33. image.update();
  34. expect(image.exists(`div.${BASE_CLASS_PREFIX}-image-preview`)).toEqual(true);
  35. expect(document.body.style.overflow).toEqual('hidden');
  36. image.setProps({ visible: false })
  37. image.update();
  38. expect(document.body.style.overflow).not.toEqual('hidden');
  39. expect(document.querySelector(`div.${BASE_CLASS_PREFIX}-image-preview`)).toEqual(null);
  40. });
  41. })