Skip to content

Commit

Permalink
add travis-ci and coveralls to the project
Browse files Browse the repository at this point in the history
  • Loading branch information
asashay committed May 25, 2020
1 parent ff7efb4 commit 1a9da89
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 40 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: dHTA8fcwDsweJtCUlNkR37iq1AknfgKpK
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: node_js
node_js:
- 14
- 12
- 10
script:
- npm run test:coveralls
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"test": "run-s test:unit test:lint test:build",
"test:build": "run-s build",
"test:lint": "eslint .",
"test:unit": "cross-env CI=1 react-scripts test --env=jsdom",
"test:unit": "cross-env CI=1 react-scripts test --env=jsdom --coverage",
"test:watch": "react-scripts test --env=jsdom",
"test:coveralls": "cross-env CI=1 react-scripts test --env=jsdom --coverage && cat ./coverage/lcov.info | coveralls",
"predeploy": "cd example && yarn install && yarn run build",
"deploy": "gh-pages -d example/build"
},
Expand All @@ -34,6 +35,7 @@
"@typescript-eslint/eslint-plugin": "^2.26.0",
"@typescript-eslint/parser": "^2.26.0",
"babel-eslint": "^10.0.3",
"coveralls": "^3.1.0",
"cross-env": "^7.0.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.7.0",
Expand Down
80 changes: 73 additions & 7 deletions src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ describe('Test getLengthes', () => {
expect(bottom).toEqual(width)
})

it(`checks bars lenghtes when progressBar starts at
BottomLeft and is of TwoLines type (4 bars visible)`, () => {
const path = 450
const width = 300
const height = 200
const progressStart = 'BottomLeft'
const type = 'TwoLines'
const { top, right, bottom, left } = getLengthes({
path,
width,
height,
progressStart,
type
})
expect(left).toEqual(height)
expect(top).toEqual(path - height)
expect(right).toEqual(path - width)
expect(bottom).toEqual(width)
})

it(`checks bars lenghtes when progressBar starts at
TopLeft is of TwoLines type (2 bars visible)`, () => {
const path = 150
Expand All @@ -138,11 +158,11 @@ describe('Test getLengthes', () => {
})

it(`checks bars lenghtes when progressBar starts at
BottomLeft and is of TwoLines type (4 bars visible)`, () => {
const path = 450
TopRight is of TwoLines type (2 bars visible)`, () => {
const path = 150
const width = 300
const height = 200
const progressStart = 'BottomLeft'
const progressStart = 'TopRight'
const type = 'TwoLines'
const { top, right, bottom, left } = getLengthes({
path,
Expand All @@ -151,10 +171,30 @@ BottomLeft and is of TwoLines type (4 bars visible)`, () => {
progressStart,
type
})
expect(left).toEqual(height)
expect(top).toEqual(path - height)
expect(right).toEqual(path - width)
expect(bottom).toEqual(width)
expect(left).toEqual(0)
expect(top).toEqual(path)
expect(right).toEqual(path)
expect(bottom).toEqual(0)
})

it(`checks bars lenghtes when progressBar starts at
BottomRight is of TwoLines type (2 bars visible)`, () => {
const path = 150
const width = 300
const height = 200
const progressStart = 'BottomRight'
const type = 'TwoLines'
const { top, right, bottom, left } = getLengthes({
path,
width,
height,
progressStart,
type
})
expect(left).toEqual(0)
expect(top).toEqual(0)
expect(right).toEqual(path)
expect(bottom).toEqual(path)
})
})

Expand Down Expand Up @@ -184,4 +224,30 @@ describe('Test getBarsPositions', () => {
expect(bottomBar).toEqual({ left: 0, bottom: 0 })
expect(leftBar).toEqual({ left: 0, top: 0 })
})

it(`checks getBarsPositions to calculate bars
bars positions properly when progressBar starts at
TopRight is of TwoLines type`, () => {
const { topBar, rightBar, bottomBar, leftBar } = getBarsPositions(
'TopRight',
'TwoLines'
)
expect(topBar).toEqual({ right: 0, top: 0 })
expect(rightBar).toEqual({ right: 0, top: 0 })
expect(bottomBar).toEqual({ right: 0, bottom: 0 })
expect(leftBar).toEqual({ left: 0, top: 0 })
})

it(`checks getBarsPositions to calculate bars
bars positions properly when progressBar starts at
BottomRight is of TwoLines type`, () => {
const { topBar, rightBar, bottomBar, leftBar } = getBarsPositions(
'BottomRight',
'TwoLines'
)
expect(topBar).toEqual({ right: 0, top: 0 })
expect(rightBar).toEqual({ right: 0, bottom: 0 })
expect(bottomBar).toEqual({ right: 0, bottom: 0 })
expect(leftBar).toEqual({ left: 0, bottom: 0 })
})
})
32 changes: 1 addition & 31 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import * as React from 'react'
import { Ref, VideoProps, StartOptions, ProgressTypes } from './types'

// import styles from './styles.module.css'

enum StartOptions {
BottomLeft = 'BottomLeft',
TopLeft = 'TopLeft',
TopRight = 'TopRight',
BottomRight = 'BottomRight'
}

enum ProgressTypes {
OneLine = 'OneLine',
TwoLines = 'TwoLines'
}

export function getLengthes({
path,
width,
Expand Down Expand Up @@ -61,8 +50,6 @@ export function getLengthes({
right =
path > height * 2 + width * 2 ? height : path - width * 2 - height
break
default:
break
}
} else if (type === ProgressTypes.TwoLines) {
switch (progressStart) {
Expand Down Expand Up @@ -90,8 +77,6 @@ export function getLengthes({
top = path > height + width ? width : path - height
left = path > height + width ? height : path - width
break
default:
break
}
}

Expand Down Expand Up @@ -164,19 +149,6 @@ export function getBarsPositions(
}
}

interface VideoProps extends React.ComponentPropsWithoutRef<'video'> {
pathColor?: string
pathWidth?: string
progressStart?: StartOptions
type?: ProgressTypes
wrapperStyle?: React.CSSProperties
wrapperClassName?: string
onLoadedMetadata?(e: React.SyntheticEvent<HTMLVideoElement>): void
onTimeUpdate?(e: React.SyntheticEvent<HTMLVideoElement>): void
}

type Ref = HTMLVideoElement | null

export const VideoProgress = React.forwardRef<Ref, VideoProps>(
(
{
Expand Down Expand Up @@ -274,12 +246,10 @@ export const VideoProgress = React.forwardRef<Ref, VideoProps>(
<video
ref={ref}
onLoadedMetadata={(e: React.SyntheticEvent<HTMLVideoElement>) => {
console.log('onLoadedMetadata', e.currentTarget.duration)
setDuration(e.currentTarget.duration)
onLoadedMetadata(e)
}}
onTimeUpdate={(e: React.SyntheticEvent<HTMLVideoElement>) => {
console.log('onTimeUpdate', e.currentTarget.duration)
setCurrentTime(e.currentTarget.currentTime)
onTimeUpdate(e)
}}
Expand Down
24 changes: 24 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export enum StartOptions {
BottomLeft = 'BottomLeft',
TopLeft = 'TopLeft',
TopRight = 'TopRight',
BottomRight = 'BottomRight'
}

export enum ProgressTypes {
OneLine = 'OneLine',
TwoLines = 'TwoLines'
}

export interface VideoProps extends React.ComponentPropsWithoutRef<'video'> {
pathColor?: string
pathWidth?: string
progressStart?: StartOptions
type?: ProgressTypes
wrapperStyle?: React.CSSProperties
wrapperClassName?: string
onLoadedMetadata?(e: React.SyntheticEvent<HTMLVideoElement>): void
onTimeUpdate?(e: React.SyntheticEvent<HTMLVideoElement>): void
}

export type Ref = HTMLVideoElement | null
23 changes: 22 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3312,6 +3312,17 @@ cosmiconfig@^6.0.0:
path-type "^4.0.0"
yaml "^1.7.2"

coveralls@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/coveralls/-/coveralls-3.1.0.tgz#13c754d5e7a2dd8b44fe5269e21ca394fb4d615b"
integrity sha512-sHxOu2ELzW8/NC1UP5XVLbZDzO4S3VxfFye3XYCznopHy02YjNkHcj5bKaVw2O7hVaBdBjEdQGpie4II1mWhuQ==
dependencies:
js-yaml "^3.13.1"
lcov-parse "^1.0.0"
log-driver "^1.2.7"
minimist "^1.2.5"
request "^2.88.2"

create-ecdh@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.3.tgz#c9111b6f33045c4697f144787f9254cdc77c45ff"
Expand Down Expand Up @@ -6846,6 +6857,11 @@ lcid@^2.0.0:
dependencies:
invert-kv "^2.0.0"

lcov-parse@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lcov-parse/-/lcov-parse-1.0.0.tgz#eb0d46b54111ebc561acb4c408ef9363bdc8f7e0"
integrity sha1-6w1GtUER68VhrLTECO+TY73I9+A=

left-pad@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"
Expand Down Expand Up @@ -7000,6 +7016,11 @@ lodash.uniq@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==

log-driver@^1.2.7:
version "1.2.7"
resolved "https://registry.yarnpkg.com/log-driver/-/log-driver-1.2.7.tgz#63b95021f0702fedfa2c9bb0a24e7797d71871d8"
integrity sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg==

loglevel@^1.6.6:
version "1.6.8"
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.8.tgz#8a25fb75d092230ecd4457270d80b54e28011171"
Expand Down Expand Up @@ -9624,7 +9645,7 @@ request-promise-native@^1.0.5:
stealthy-require "^1.1.1"
tough-cookie "^2.3.3"

request@^2.87.0, request@^2.88.0:
request@^2.87.0, request@^2.88.0, request@^2.88.2:
version "2.88.2"
resolved "https://registry.yarnpkg.com/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3"
integrity sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==
Expand Down

0 comments on commit 1a9da89

Please sign in to comment.