-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from BKWLD/video-control
Video control
- Loading branch information
Showing
15 changed files
with
227 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ jobs: | |
matrix: | ||
dir: | ||
- packages/next | ||
- packages/react | ||
- packages/sanity-next | ||
|
||
steps: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineConfig } from "cypress"; | ||
|
||
export default defineConfig({ | ||
viewportWidth: 500, | ||
viewportHeight: 500, | ||
component: { | ||
specPattern: "cypress/component/**/*.cy.{js,jsx,ts,tsx}", | ||
devServer: { | ||
framework: "next", | ||
bundler: "webpack", | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useState } from 'react' | ||
import { LazyVideo } from '../../src' | ||
|
||
// Make an instance of LazyVideo that can be controlled | ||
const Player = function({ autoplay }: any) { | ||
|
||
const [playing, setPlaying] = useState(autoplay) | ||
|
||
return (<> | ||
<LazyVideo | ||
src='https://placehold.co/300x200.mp4' | ||
alt='' | ||
playing={ playing }/> | ||
<div style={{ position: 'relative' }}> | ||
<button onClick={() => setPlaying(true)}>Play</button> | ||
<button onClick={() => setPlaying(false)}>Pause</button> | ||
</div> | ||
</>) | ||
} | ||
|
||
|
||
describe('playback', () => { | ||
|
||
it('can be paused and then restarted', () => { | ||
cy.mount(<Player autoplay={true} />) | ||
cy.get('video').isPlaying() | ||
cy.get('button').contains('Pause').click() | ||
cy.get('video').isPaused() | ||
cy.get('button').contains('Play').click() | ||
cy.get('video').isPlaying() | ||
}) | ||
|
||
it('can be started and then paused', () => { | ||
cy.mount(<Player autoplay={false} />) | ||
cy.get('video').isPaused() | ||
cy.get('button').contains('Play').click() | ||
cy.get('video').isPlaying() | ||
cy.get('button').contains('Pause').click() | ||
cy.get('video').isPaused() | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// <reference types="cypress" /> | ||
|
||
// Check that a video is playing | ||
// https://glebbahmutov.com/blog/test-video-play/ | ||
Cypress.Commands.add('isPlaying', | ||
{ prevSubject: true }, | ||
(subject) => { | ||
cy.wrap(subject).should('have.prop', 'paused', false) | ||
}) | ||
|
||
// Check that a video is playing | ||
// https://glebbahmutov.com/blog/test-video-play/ | ||
Cypress.Commands.add('isPaused', | ||
{ prevSubject: true }, | ||
(subject) => { | ||
cy.wrap(subject).should('have.prop', 'paused', true) | ||
}) | ||
|
||
// Add Typescript support for custom commaands | ||
// https://docs.cypress.io/guides/tooling/typescript-support#Types-for-Custom-Commands | ||
export {}; | ||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
|
||
hasDimensions( | ||
width: number, | ||
height: number | ||
): Chainable<JQueryWithSelector> | ||
|
||
isPlaying(): Chainable<void> | ||
isPaused(): Chainable<void> | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<title>Components App</title> | ||
<!-- Used by Next.js to inject CSS. --> | ||
<div id="__next_css__DO_NOT_USE__"></div> | ||
<style> | ||
html, body { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div data-cy-root></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') | ||
|
||
import { mount } from 'cypress/react18' | ||
|
||
// Augment the Cypress namespace to include type definitions for | ||
// your custom command. | ||
// Alternatively, can be defined in cypress/support/component.d.ts | ||
// with a <reference path="./component" /> at the top of your spec. | ||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
mount: typeof mount | ||
} | ||
} | ||
} | ||
|
||
Cypress.Commands.add('mount', mount) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"jsx": "preserve", | ||
"lib": [ | ||
"es5", | ||
"dom" | ||
], | ||
"types": [ | ||
"cypress", | ||
"node" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
"**/*.tsx" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { CSSProperties } from 'react' | ||
|
||
export type LazyVideoProps = { | ||
|
||
// Source props | ||
src: HTMLVideoElement['src'] | ||
alt: string | ||
|
||
// Don't lazy load | ||
priority?: boolean | ||
|
||
// Use a transparent gif poster image | ||
noPoster?: boolean | ||
|
||
// Controls autoplaying and current playing state | ||
playing?: boolean | ||
|
||
// Display props | ||
fit?: CSSProperties['objectFit'] | ||
position?: CSSProperties['objectPosition'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters