@wix/design-system
Version:
@wix/design-system
1,222 lines (1,220 loc) • 51.4 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["media"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/MediaOverlay/test/MediaOverlay.spec.jsx",
_this = this;
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React, { act } from 'react';
import userEvent from '@testing-library/user-event';
import { createRendererWithUniDriver, cleanup } from '../../utils/test-utils/unit';
import MediaOverlay from '../MediaOverlay';
import { Skin, Visible } from '../constants';
import { mediaOverlayPrivateDriverFactory } from './MediaOverlay.private.uni.driver';
var mediaUrl = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
var createMediaOverlay = function createMediaOverlay() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$media = _ref.media,
media = _ref$media === void 0 ? mediaUrl : _ref$media,
rest = _objectWithoutProperties(_ref, _excluded);
return /*#__PURE__*/React.createElement(MediaOverlay, _extends({
media: media
}, rest, {
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 14,
columnNumber: 3
}
}));
};
var createMediaOverlayContent = function createMediaOverlayContent(props) {
return /*#__PURE__*/React.createElement(MediaOverlay.Content, _extends({}, props, {
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 16,
columnNumber: 44
}
}));
};
afterEach(function () {
cleanup();
});
describe('MediaOverlay', function () {
var render = createRendererWithUniDriver(mediaOverlayPrivateDriverFactory);
it('should render', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var _render, driver;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_render = render(createMediaOverlay()), driver = _render.driver;
_context.t0 = expect;
_context.next = 4;
return driver.exists();
case 4:
_context.t1 = _context.sent;
(0, _context.t0)(_context.t1).toBe(true);
case 6:
case "end":
return _context.stop();
}
}, _callee);
})));
describe('media prop', function () {
it('should set string value as background image', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
var _render2, driver;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
_render2 = render(createMediaOverlay()), driver = _render2.driver;
_context2.t0 = expect;
_context2.next = 4;
return driver.getMediaUrl();
case 4:
_context2.t1 = _context2.sent;
(0, _context2.t0)(_context2.t1).toBe(mediaUrl);
_context2.t2 = expect;
_context2.next = 9;
return driver.getMediaNode();
case 9:
_context2.t3 = _context2.sent;
(0, _context2.t2)(_context2.t3).toBe(null);
case 11:
case "end":
return _context2.stop();
}
}, _callee2);
})));
it('should render custom node elements', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
var id, _render3, driver, mediaNode;
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
id = 'test';
_render3 = render(createMediaOverlay({
media: /*#__PURE__*/React.createElement("div", {
id: id,
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 39,
columnNumber: 61
}
})
})), driver = _render3.driver;
_context3.t0 = expect;
_context3.next = 5;
return driver.getMediaUrl();
case 5:
_context3.t1 = _context3.sent;
(0, _context3.t0)(_context3.t1).toBe(null);
_context3.next = 9;
return driver.getMediaNode();
case 9:
mediaNode = _context3.sent;
expect(mediaNode).not.toBe(null);
expect(mediaNode.getAttribute('id')).toBe(id);
case 12:
case "end":
return _context3.stop();
}
}, _callee3);
})));
});
describe('onClick prop', function () {
it('should handle click', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
var onClick, _render4, driver;
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
onClick = vi.fn();
_render4 = render(createMediaOverlay({
onClick: onClick
})), driver = _render4.driver;
_context4.next = 4;
return driver.click();
case 4:
expect(onClick).toHaveBeenCalledTimes(1);
case 5:
case "end":
return _context4.stop();
}
}, _callee4);
})));
});
describe('skin prop', function () {
it("should have default value \"".concat(Skin.None, "\""), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
var _render5, driver;
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
_render5 = render(createMediaOverlay()), driver = _render5.driver;
_context5.t0 = expect;
_context5.next = 4;
return driver.getSkin();
case 4:
_context5.t1 = _context5.sent;
(0, _context5.t0)(_context5.t1).toBe(Skin.None);
case 6:
case "end":
return _context5.stop();
}
}, _callee5);
})));
it("should set value to \"".concat(Skin.Gradient, "\""), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
var _render6, driver;
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
_render6 = render(createMediaOverlay({
skin: Skin.Gradient
})), driver = _render6.driver;
_context6.t0 = expect;
_context6.next = 4;
return driver.getSkin();
case 4:
_context6.t1 = _context6.sent;
(0, _context6.t0)(_context6.t1).toBe(Skin.Gradient);
case 6:
case "end":
return _context6.stop();
}
}, _callee6);
})));
it("should set value to \"".concat(Skin.Dark, "\""), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
var _render7, driver;
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
_render7 = render(createMediaOverlay({
skin: Skin.Dark
})), driver = _render7.driver;
_context7.t0 = expect;
_context7.next = 4;
return driver.getSkin();
case 4:
_context7.t1 = _context7.sent;
(0, _context7.t0)(_context7.t1).toBe(Skin.Dark);
case 6:
case "end":
return _context7.stop();
}
}, _callee7);
})));
});
describe('hoverSkin prop', function () {
it("should have default value equal to skin prop", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
var _render8, driver;
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
case 0:
_render8 = render(createMediaOverlay({
skin: Skin.Gradient
})), driver = _render8.driver;
_context8.t0 = expect;
_context8.next = 4;
return driver.getHoverSkin();
case 4:
_context8.t1 = _context8.sent;
(0, _context8.t0)(_context8.t1).toBe(Skin.Gradient);
case 6:
case "end":
return _context8.stop();
}
}, _callee8);
})));
it("should set value to \"".concat(Skin.Gradient, "\""), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
var _render9, driver;
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:
_render9 = render(createMediaOverlay({
hoverSkin: Skin.Gradient
})), driver = _render9.driver;
_context9.t0 = expect;
_context9.next = 4;
return driver.getHoverSkin();
case 4:
_context9.t1 = _context9.sent;
(0, _context9.t0)(_context9.t1).toBe(Skin.Gradient);
case 6:
case "end":
return _context9.stop();
}
}, _callee9);
})));
it("should set value to \"".concat(Skin.Dark, "\""), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0() {
var _render0, driver;
return _regeneratorRuntime.wrap(function _callee0$(_context0) {
while (1) switch (_context0.prev = _context0.next) {
case 0:
_render0 = render(createMediaOverlay({
hoverSkin: Skin.Dark
})), driver = _render0.driver;
_context0.t0 = expect;
_context0.next = 4;
return driver.getHoverSkin();
case 4:
_context0.t1 = _context0.sent;
(0, _context0.t0)(_context0.t1).toBe(Skin.Dark);
case 6:
case "end":
return _context0.stop();
}
}, _callee0);
})));
});
describe('hovered prop', function () {
it('should not trigger hover state on mouse enter when value is "false"', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1() {
var _render1, driver;
return _regeneratorRuntime.wrap(function _callee1$(_context1) {
while (1) switch (_context1.prev = _context1.next) {
case 0:
_render1 = render(createMediaOverlay({
hovered: false,
children: createMediaOverlayContent({
visible: Visible.Hover,
children: /*#__PURE__*/React.createElement("div", {
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 100,
columnNumber: 23
}
})
})
})), driver = _render1.driver;
_context1.t0 = expect;
_context1.next = 4;
return driver.getIsVisible();
case 4:
_context1.t1 = _context1.sent;
(0, _context1.t0)(_context1.t1).toBe(false);
_context1.next = 8;
return driver.hover();
case 8:
_context1.t2 = expect;
_context1.next = 11;
return driver.getIsVisible();
case 11:
_context1.t3 = _context1.sent;
(0, _context1.t2)(_context1.t3).toBe(false);
case 13:
case "end":
return _context1.stop();
}
}, _callee1);
})));
it('should always trigger hover state when value is "true"', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
var id, _render10, driver, contentChildren;
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
id = 'test-content';
_render10 = render(createMediaOverlay({
hovered: true,
children: createMediaOverlayContent({
visible: Visible.Hover,
children: /*#__PURE__*/React.createElement("div", {
id: id,
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 117,
columnNumber: 23
}
})
})
})), driver = _render10.driver;
_context10.t0 = expect;
_context10.next = 5;
return driver.getIsVisible();
case 5:
_context10.t1 = _context10.sent;
(0, _context10.t0)(_context10.t1).toBe(true);
_context10.next = 9;
return driver.getContentChildren();
case 9:
contentChildren = _context10.sent;
_context10.t2 = expect;
_context10.next = 13;
return contentChildren.count();
case 13:
_context10.t3 = _context10.sent;
(0, _context10.t2)(_context10.t3).toBe(1);
_context10.t4 = expect;
_context10.next = 18;
return contentChildren.get(0).attr('id');
case 18:
_context10.t5 = _context10.sent;
(0, _context10.t4)(_context10.t5).toBe(id);
_context10.next = 22;
return driver.hover();
case 22:
_context10.t6 = expect;
_context10.next = 25;
return driver.getIsVisible();
case 25:
_context10.t7 = _context10.sent;
(0, _context10.t6)(_context10.t7).toBe(true);
case 27:
case "end":
return _context10.stop();
}
}, _callee10);
})));
});
describe('Content', function () {
it('should ignore direct child elements not wrapped in Content', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
var _render11, driver, contentChildren;
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
case 0:
_render11 = render(createMediaOverlay({
children: /*#__PURE__*/React.createElement("div", {
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 133,
columnNumber: 64
}
})
})), driver = _render11.driver;
_context11.next = 3;
return driver.getContentChildren();
case 3:
contentChildren = _context11.sent;
_context11.t0 = expect;
_context11.next = 7;
return contentChildren.count();
case 7:
_context11.t1 = _context11.sent;
(0, _context11.t0)(_context11.t1).toBe(0);
case 9:
case "end":
return _context11.stop();
}
}, _callee11);
})));
it('should render single Content item', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
var id, _render12, driver, contentChildren;
return _regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) switch (_context12.prev = _context12.next) {
case 0:
id = 'test-content';
_render12 = render(createMediaOverlay({
children: createMediaOverlayContent({
children: /*#__PURE__*/React.createElement("div", {
id: id,
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 142,
columnNumber: 59
}
})
})
})), driver = _render12.driver;
_context12.next = 4;
return driver.getContentChildren();
case 4:
contentChildren = _context12.sent;
_context12.t0 = expect;
_context12.next = 8;
return contentChildren.count();
case 8:
_context12.t1 = _context12.sent;
(0, _context12.t0)(_context12.t1).toBe(1);
_context12.t2 = expect;
_context12.next = 13;
return contentChildren.get(0).attr('id');
case 13:
_context12.t3 = _context12.sent;
(0, _context12.t2)(_context12.t3).toBe(id);
case 15:
case "end":
return _context12.stop();
}
}, _callee12);
})));
it('should render multiple Content items', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
var id1, id2, _render13, driver, contentChildren;
return _regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) switch (_context13.prev = _context13.next) {
case 0:
id1 = 'test-content-1';
id2 = 'test-content-2';
_render13 = render(createMediaOverlay({
children: [createMediaOverlayContent({
key: 1,
children: /*#__PURE__*/React.createElement("div", {
id: id1,
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 157,
columnNumber: 59
}
})
}), createMediaOverlayContent({
key: 2,
children: /*#__PURE__*/React.createElement("div", {
id: id2,
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 158,
columnNumber: 59
}
})
})]
})), driver = _render13.driver;
_context13.next = 5;
return driver.getContentChildren();
case 5:
contentChildren = _context13.sent;
_context13.t0 = expect;
_context13.next = 9;
return contentChildren.count();
case 9:
_context13.t1 = _context13.sent;
(0, _context13.t0)(_context13.t1).toBe(2);
_context13.t2 = expect;
_context13.next = 14;
return contentChildren.get(0).attr('id');
case 14:
_context13.t3 = _context13.sent;
(0, _context13.t2)(_context13.t3).toBe(id1);
_context13.t4 = expect;
_context13.next = 19;
return contentChildren.get(1).attr('id');
case 19:
_context13.t5 = _context13.sent;
(0, _context13.t4)(_context13.t5).toBe(id2);
case 21:
case "end":
return _context13.stop();
}
}, _callee13);
})));
it("should render visible=\"".concat(Visible.Hover, "\" Content items only on hover"), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
var id, _render14, driver, contentChildren;
return _regeneratorRuntime.wrap(function _callee14$(_context14) {
while (1) switch (_context14.prev = _context14.next) {
case 0:
id = 'test-content';
_render14 = render(createMediaOverlay({
children: createMediaOverlayContent({
visible: Visible.Hover,
children: /*#__PURE__*/React.createElement("div", {
id: id,
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 175,
columnNumber: 23
}
})
})
})), driver = _render14.driver;
_context14.t0 = expect;
_context14.next = 5;
return driver.getIsVisible();
case 5:
_context14.t1 = _context14.sent;
(0, _context14.t0)(_context14.t1).toBe(false);
_context14.next = 9;
return driver.getContentChildren();
case 9:
contentChildren = _context14.sent;
_context14.t2 = expect;
_context14.next = 13;
return contentChildren.count();
case 13:
_context14.t3 = _context14.sent;
(0, _context14.t2)(_context14.t3).toBe(1);
_context14.next = 17;
return driver.hover();
case 17:
_context14.t4 = expect;
_context14.next = 20;
return driver.getIsVisible();
case 20:
_context14.t5 = _context14.sent;
(0, _context14.t4)(_context14.t5).toBe(true);
_context14.t6 = expect;
_context14.next = 25;
return contentChildren.get(0).attr('id');
case 25:
_context14.t7 = _context14.sent;
(0, _context14.t6)(_context14.t7).toBe(id);
case 27:
case "end":
return _context14.stop();
}
}, _callee14);
})));
});
describe('data-isvisible attribute', function () {
it('should be true when hovered', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
var _render15, driver;
return _regeneratorRuntime.wrap(function _callee15$(_context15) {
while (1) switch (_context15.prev = _context15.next) {
case 0:
_render15 = render(createMediaOverlay()), driver = _render15.driver;
_context15.t0 = expect;
_context15.next = 4;
return driver.getIsVisible();
case 4:
_context15.t1 = _context15.sent;
(0, _context15.t0)(_context15.t1).toBe(false);
_context15.next = 8;
return driver.hover();
case 8:
_context15.t2 = expect;
_context15.next = 11;
return driver.getIsVisible();
case 11:
_context15.t3 = _context15.sent;
(0, _context15.t2)(_context15.t3).toBe(true);
case 13:
case "end":
return _context15.stop();
}
}, _callee15);
})));
it('should be true when focused', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
var _render16, driver;
return _regeneratorRuntime.wrap(function _callee16$(_context16) {
while (1) switch (_context16.prev = _context16.next) {
case 0:
_render16 = render(createMediaOverlay({
children: [createMediaOverlayContent({
key: 1,
children: /*#__PURE__*/React.createElement("button", {
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 202,
columnNumber: 59
}
})
})]
})), driver = _render16.driver;
_context16.t0 = expect;
_context16.next = 4;
return driver.getIsVisible();
case 4:
_context16.t1 = _context16.sent;
(0, _context16.t0)(_context16.t1).toBe(false);
_context16.next = 8;
return userEvent.tab();
case 8:
_context16.t2 = expect;
_context16.next = 11;
return driver.getIsVisible();
case 11:
_context16.t3 = _context16.sent;
(0, _context16.t2)(_context16.t3).toBe(true);
case 13:
case "end":
return _context16.stop();
}
}, _callee16);
})));
});
describe('Video mode', function () {
var videoSrc = 'https://www.w3schools.com/html/mov_bbb.mp4';
describe('isVideo prop', function () {
it('should not render video element when isVideo is false', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee17() {
var _render17, driver;
return _regeneratorRuntime.wrap(function _callee17$(_context17) {
while (1) switch (_context17.prev = _context17.next) {
case 0:
_render17 = render(createMediaOverlay({
isVideo: false,
videoSrc: videoSrc
})), driver = _render17.driver;
_context17.t0 = expect;
_context17.next = 4;
return driver.hasVideo();
case 4:
_context17.t1 = _context17.sent;
(0, _context17.t0)(_context17.t1).toBe(false);
case 6:
case "end":
return _context17.stop();
}
}, _callee17);
})));
it('should render video element when isVideo is true', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee19() {
var _render18, driver;
return _regeneratorRuntime.wrap(function _callee19$(_context19) {
while (1) switch (_context19.prev = _context19.next) {
case 0:
_render18 = render(createMediaOverlay({
isVideo: true,
videoSrc: videoSrc
})), driver = _render18.driver; // Wait for Suspense to resolve
_context19.next = 3;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee18() {
return _regeneratorRuntime.wrap(function _callee18$(_context18) {
while (1) switch (_context18.prev = _context18.next) {
case 0:
_context18.next = 2;
return new Promise(function (resolve) {
return setTimeout(resolve, 0);
});
case 2:
case "end":
return _context18.stop();
}
}, _callee18);
})));
case 3:
_context19.t0 = expect;
_context19.next = 6;
return driver.hasVideo();
case 6:
_context19.t1 = _context19.sent;
(0, _context19.t0)(_context19.t1).toBe(true);
_context19.t2 = expect;
_context19.next = 11;
return driver.getVideoSrc();
case 11:
_context19.t3 = _context19.sent;
(0, _context19.t2)(_context19.t3).toBe(videoSrc);
case 13:
case "end":
return _context19.stop();
}
}, _callee19);
})));
});
describe('videoProps prop', function () {
it('should pass additional props to video element', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee20() {
var _render19, driver;
return _regeneratorRuntime.wrap(function _callee20$(_context20) {
while (1) switch (_context20.prev = _context20.next) {
case 0:
_render19 = render(createMediaOverlay({
isVideo: true,
videoSrc: videoSrc,
videoProps: {
loop: true,
muted: true
}
})), driver = _render19.driver;
_context20.t0 = expect;
_context20.next = 4;
return driver.isVideoLooped();
case 4:
_context20.t1 = _context20.sent;
(0, _context20.t0)(_context20.t1).toBe(true);
_context20.t2 = expect;
_context20.next = 9;
return driver.isVideoMuted();
case 9:
_context20.t3 = _context20.sent;
(0, _context20.t2)(_context20.t3).toBe(true);
case 11:
case "end":
return _context20.stop();
}
}, _callee20);
})));
});
describe('Play button', function () {
it('should render play button by default', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee21() {
var _render20, driver;
return _regeneratorRuntime.wrap(function _callee21$(_context21) {
while (1) switch (_context21.prev = _context21.next) {
case 0:
_render20 = render(createMediaOverlay({
isVideo: true,
videoSrc: videoSrc
})), driver = _render20.driver;
_context21.t0 = expect;
_context21.next = 4;
return driver.hasPlayButton();
case 4:
_context21.t1 = _context21.sent;
(0, _context21.t0)(_context21.t1).toBe(true);
case 6:
case "end":
return _context21.stop();
}
}, _callee21);
})));
it('should not render play button when showPlayButton is false', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee23() {
var _render21, driver;
return _regeneratorRuntime.wrap(function _callee23$(_context23) {
while (1) switch (_context23.prev = _context23.next) {
case 0:
_render21 = render(createMediaOverlay({
isVideo: true,
videoSrc: videoSrc,
showPlayButton: false
})), driver = _render21.driver;
_context23.next = 3;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee22() {
return _regeneratorRuntime.wrap(function _callee22$(_context22) {
while (1) switch (_context22.prev = _context22.next) {
case 0:
_context22.next = 2;
return new Promise(function (resolve) {
return setTimeout(resolve, 100);
});
case 2:
case "end":
return _context22.stop();
}
}, _callee22);
})));
case 3:
_context23.t0 = expect;
_context23.next = 6;
return driver.hasPlayButton();
case 6:
_context23.t1 = _context23.sent;
(0, _context23.t0)(_context23.t1).toBe(false);
case 8:
case "end":
return _context23.stop();
}
}, _callee23);
})));
it('should toggle video playback when clicking play button', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee26() {
var _render22, driver, videoElement;
return _regeneratorRuntime.wrap(function _callee26$(_context26) {
while (1) switch (_context26.prev = _context26.next) {
case 0:
_render22 = render(createMediaOverlay({
isVideo: true,
videoSrc: videoSrc
})), driver = _render22.driver;
_context26.next = 3;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee24() {
return _regeneratorRuntime.wrap(function _callee24$(_context24) {
while (1) switch (_context24.prev = _context24.next) {
case 0:
_context24.next = 2;
return new Promise(function (resolve) {
return setTimeout(resolve, 100);
});
case 2:
case "end":
return _context24.stop();
}
}, _callee24);
})));
case 3:
_context26.next = 5;
return driver.getVideoElement();
case 5:
videoElement = _context26.sent;
videoElement.play = vi.fn(function () {
return Promise.resolve();
});
videoElement.pause = vi.fn();
// Click play button
_context26.next = 10;
return driver.clickPlayButton();
case 10:
expect(videoElement.play).toHaveBeenCalledTimes(1);
// Simulate play event
_context26.next = 13;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee25() {
return _regeneratorRuntime.wrap(function _callee25$(_context25) {
while (1) switch (_context25.prev = _context25.next) {
case 0:
videoElement.dispatchEvent(new Event('play'));
case 1:
case "end":
return _context25.stop();
}
}, _callee25);
})));
case 13:
_context26.next = 15;
return driver.clickPlayButton();
case 15:
expect(videoElement.pause).toHaveBeenCalledTimes(1);
case 16:
case "end":
return _context26.stop();
}
}, _callee26);
})));
});
describe('Video state management', function () {
it('should update isVideoPlaying state when video plays', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee29() {
var _render23, driver, videoElement;
return _regeneratorRuntime.wrap(function _callee29$(_context29) {
while (1) switch (_context29.prev = _context29.next) {
case 0:
_render23 = render(createMediaOverlay({
isVideo: true,
videoSrc: videoSrc
})), driver = _render23.driver; // Wait for controls to load
_context29.next = 3;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee27() {
return _regeneratorRuntime.wrap(function _callee27$(_context27) {
while (1) switch (_context27.prev = _context27.next) {
case 0:
_context27.next = 2;
return new Promise(function (resolve) {
return setTimeout(resolve, 100);
});
case 2:
case "end":
return _context27.stop();
}
}, _callee27);
})));
case 3:
_context29.next = 5;
return driver.getVideoElement();
case 5:
videoElement = _context29.sent;
_context29.t0 = expect;
_context29.next = 9;
return driver.isVideoPaused();
case 9:
_context29.t1 = _context29.sent;
(0, _context29.t0)(_context29.t1).toBe(true);
_context29.next = 13;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee28() {
return _regeneratorRuntime.wrap(function _callee28$(_context28) {
while (1) switch (_context28.prev = _context28.next) {
case 0:
// Set paused to false to simulate playing state
Object.defineProperty(videoElement, 'paused', {
value: false,
writable: true
});
videoElement.dispatchEvent(new Event('play'));
case 2:
case "end":
return _context28.stop();
}
}, _callee28);
})));
case 13:
_context29.t2 = expect;
_context29.next = 16;
return driver.isVideoPaused();
case 16:
_context29.t3 = _context29.sent;
(0, _context29.t2)(_context29.t3).toBe(false);
case 18:
case "end":
return _context29.stop();
}
}, _callee29);
})));
it('should update isVideoPlaying state when video pauses', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee33() {
var _render24, driver, videoElement;
return _regeneratorRuntime.wrap(function _callee33$(_context33) {
while (1) switch (_context33.prev = _context33.next) {
case 0:
_render24 = render(createMediaOverlay({
isVideo: true,
videoSrc: videoSrc
})), driver = _render24.driver;
_context33.next = 3;
return driver.getVideoElement();
case 3:
videoElement = _context33.sent;
_context33.next = 6;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee30() {
return _regeneratorRuntime.wrap(function _callee30$(_context30) {
while (1) switch (_context30.prev = _context30.next) {
case 0:
videoElement.dispatchEvent(new Event('play'));
case 1:
case "end":
return _context30.stop();
}
}, _callee30);
})));
case 6:
_context33.next = 8;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee31() {
return _regeneratorRuntime.wrap(function _callee31$(_context31) {
while (1) switch (_context31.prev = _context31.next) {
case 0:
videoElement.dispatchEvent(new Event('pause'));
case 1:
case "end":
return _context31.stop();
}
}, _callee31);
})));
case 8:
_context33.next = 10;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee32() {
return _regeneratorRuntime.wrap(function _callee32$(_context32) {
while (1) switch (_context32.prev = _context32.next) {
case 0:
_context32.next = 2;
return new Promise(function (resolve) {
return setTimeout(resolve, 100);
});
case 2:
case "end":
return _context32.stop();
}
}, _callee32);
})));
case 10:
_context33.t0 = expect;
_context33.next = 13;
return driver.isVideoPaused();
case 13:
_context33.t1 = _context33.sent;
(0, _context33.t0)(_context33.t1).toBe(true);
case 15:
case "end":
return _context33.stop();
}
}, _callee33);
})));
it('should reset isVideoPlaying state when video ends', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee36() {
var _render25, driver, videoElement;
return _regeneratorRuntime.wrap(function _callee36$(_context36) {
while (1) switch (_context36.prev = _context36.next) {
case 0:
_render25 = render(createMediaOverlay({
isVideo: true,
videoSrc: videoSrc
})), driver = _render25.driver;
_context36.next = 3;
return driver.getVideoElement();
case 3:
videoElement = _context36.sent;
_context36.next = 6;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee34() {
return _regeneratorRuntime.wrap(function _callee34$(_context34) {
while (1) switch (_context34.prev = _context34.next) {
case 0:
videoElement.dispatchEvent(new Event('play'));
videoElement.dispatchEvent(new Event('ended'));
case 2:
case "end":
return _context34.stop();
}
}, _callee34);
})));
case 6:
_context36.next = 8;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee35() {
return _regeneratorRuntime.wrap(function _callee35$(_context35) {
while (1) switch (_context35.prev = _context35.next) {
case 0:
_context35.next = 2;
return new Promise(function (resolve) {
return setTimeout(resolve, 100);
});
case 2:
case "end":
return _context35.stop();
}
}, _callee35);
})));
case 8:
_context36.t0 = expect;
_context36.next = 11;
return driver.isVideoPaused();
case 11:
_context36.t1 = _context36.sent;
(0, _context36.t0)(_context36.t1).toBe(true);
case 13:
case "end":
return _context36.stop();
}
}, _callee36);
})));
});
describe('Integration with overlay content', function () {
it('should render video with overlay content', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee37() {
var testId, _render26, driver, contentChildren;
return _regeneratorRuntime.wrap(function _callee37$(_context37) {
while (1) switch (_context37.prev = _context37.next) {
case 0:
testId = 'overlay-content';
_render26 = render(createMediaOverlay({
isVideo: true,
videoSrc: videoSrc,
children: createMediaOverlayContent({
visible: Visible.Always,
children: /*#__PURE__*/React.createElement("div", {
id: testId,
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 390,
columnNumber: 25
}
})
})
})), driver = _render26.driver;
_context37.t0 = expect;
_context37.next = 5;
return driver.hasVideo();
case 5:
_context37.t1 = _context37.sent;
(0, _context37.t0)(_context37.t1).toBe(true);
_context37.next = 9;
return driver.getContentChildren();
case 9:
contentChildren = _context37.sent;
_context37.t2 = expect;
_context37.next = 13;
return contentChildren.count();
case 13:
_context37.t3 = _context37.sent;
(0, _context37.t2)(_context37.t3).toBe(1);
_context37.t4 = expect;
_context37.next = 18;
return contentChildren.get(0).attr('id');
case 18:
_context37.t5 = _context37.sent;
(0, _context37.t4)(_context37.t5).toBe(testId);
case 20:
case "end":
return _context37.stop();
}
}, _callee37);
})));
it('should work with different skin props', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee38() {
var _render27, driver;
return _regeneratorRuntime.wrap(function _callee38$(_context38) {
while (1) switch (_context38.prev = _context38.next) {
case 0:
_render27 = render(createMediaOverlay({
isVideo: true,
videoSrc: videoSrc,
skin: Skin.Gradient,
hoverSkin: Skin.Dark
})), driver = _render27.driver;
_context38.t0 = expect;
_context38.next = 4;
return driver.hasVideo();
case 4:
_context38.t1 = _context38.sent;
(0, _context38.t0)(_context38.t1).toBe(true);
_context38.t2 = expect;
_context38.next = 9;
return driver.getSkin();
case 9:
_context38.t3 = _context38.sent;
(0, _context38.t2)(_context38.t3).toBe(Skin.Gradient);
_context38.t4 = expect;
_context38.next = 14;
return driver.getHoverSkin();
case 14:
_context38.t5 = _context38.sent;
(0, _context38.t4)(_context38.t5).toBe(Skin.Dark);
case 16:
case "end":
return _context38.stop();
}
}, _callee38);
})));
});
describe('Lazy loading VideoControls', function () {
it('should load VideoControls on mount when isVideo is true', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee40() {
var _render28, driver;
return _regeneratorRuntime.wrap(function _callee40$(_context40) {
while (1) switch (_context40.prev = _context40.next) {
case 0:
_render28 = render(createMediaOverlay({
isVideo: true,
videoSrc: videoSrc
})), driver = _render28.driver; // VideoControls should be loaded after component mounts
_context40.next = 3;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee39() {
return _regeneratorRuntime.wrap(function _callee39$(_context39) {
while (1) switch (_context39.prev = _context39.next) {
case 0:
_context39.next = 2;
return new Promise(function (resolve) {
return setTimeout(resolve, 100);
});
case 2:
case "end":
return _context39.stop();
}
}, _callee39);
})));
case 3:
_context40.t0 = expect;
_context40.next = 6;
return driver.hasPlayButton();
case 6:
_context40.t1 = _context40.sent;
(0, _context40.t0)(_context40.t1).toBe(true);
case 8:
case "end":
return _context40.stop();
}
}, _callee40);
})));
it('should not load VideoControls when isVideo is false', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee42() {
var _render29, driver;
return _regeneratorRuntime.wrap(function _callee42$(_context42) {
while (1) switch (_context42.prev = _context42.next) {
case 0:
_render29 = render(createMediaOverlay({
isVideo: false,
videoSrc: videoSrc
})), driver = _render29.driver;
_context42.next = 3;
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee41() {
return _regeneratorRuntime.wrap(function _callee41$(_context41) {
while (1) switch (_context41.prev = _context41.next) {
case 0:
_context41.next = 2;
return new Promise(function (resolve) {
return setTimeout(resolve, 100);
});
case 2:
case "end":
return _context41.stop();
}
}, _callee41);
})));
case 3:
_context42.t0 = expect;
_context42.next = 6;
return driver.hasPlayButton();
case 6:
_context42.t1 = _context42.sent;
(0, _context42.t0)(_context42.t1).toBe(false);
case 8:
case "end":
return _context42.stop();
}
}, _callee42);
})));
it('should load VideoControls when isVideo changes from false to true', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee44() {
var _render30, driver, rerender;
return _regeneratorRuntime.wrap(function _callee44$(_context44) {
while (1) switch (_context44.prev = _context44.next) {
case 0:
_render30 = render(createMediaOverlay({
isVideo: false,
videoSrc: videoSrc
})), driver = _render30.driver, rerender = _render30.rerender;
_context44.t0 = expect;
_context44.next = 4;
return driver.hasVideo();
case 4:
_context44.t1 = _context44.sent;
(0, _context44.t0)(_context44.t1).toBe(false);
// Update prop to enable video
rerender(createMediaOverlay({
isVideo: true,
vid