Skip to content

Commit

Permalink
refactor(time_indicator): simplify default time logic
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopaulovieira committed May 22, 2021
1 parent c37d64c commit 0e791ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/components/time_indicator/time_indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import MediaControlComponentPlugin from '../../base/media_control_component/medi
import pluginStyle from './public/style.scss'
import templateHTML from './public/template.html'

export const DEFAULT_TIME = '00:00'

export default class TimeIndicatorPlugin extends MediaControlComponentPlugin {
get name() { return 'time_indicator' }

Expand All @@ -21,8 +23,6 @@ export default class TimeIndicatorPlugin extends MediaControlComponentPlugin {

get template() { return template(templateHTML) }

get defaultTime() { return '00:00' }

bindEvents() {
const coreEventListenerData = [
{ object: this.core, event: Events.CORE_ACTIVE_CONTAINER_CHANGED, callback: this.onContainerChanged },
Expand Down Expand Up @@ -67,8 +67,8 @@ export default class TimeIndicatorPlugin extends MediaControlComponentPlugin {
}

onContainerDestroyed() {
this.setPosition(this.defaultTime)
this.setDuration(this.defaultTime)
this.setPosition(DEFAULT_TIME)
this.setDuration(DEFAULT_TIME)
}

onStartDraggingSeekBar(data) {
Expand Down
18 changes: 5 additions & 13 deletions src/components/time_indicator/time_indicator.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Events, Core, Container, Playback } from '@clappr/core'
import TimeIndicatorPlugin from './time_indicator'
import TimeIndicatorPlugin, { DEFAULT_TIME } from './time_indicator'
import templateHTML from './public/template.html'
import MediaControlComponentPlugin from '../../base/media_control_component/media_control_component'

Expand Down Expand Up @@ -103,14 +103,6 @@ describe('TimeIndicatorPlugin', function() {
expect(this.plugin.template()).toEqual(templateHTML)
})

test('have a getter called defaultTime', () => {
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.plugin), 'defaultTime').get).toBeTruthy()
})

test('defaultTime getter returns the default string that will be added on the plugin DOM element', () => {
expect(this.plugin.template()).toEqual(templateHTML)
})

describe('bindEvents method', () => {
test('stops the current listeners before add new ones', () => {
jest.spyOn(this.plugin, 'stopListening')
Expand Down Expand Up @@ -277,17 +269,17 @@ describe('TimeIndicatorPlugin', function() {
})

describe('onContainerDestroyed method', () => {
test('calls setPosition method with defaultTime getter value', () => {
test('calls setPosition method with default time value', () => {
jest.spyOn(this.plugin, 'setPosition')
this.plugin.onContainerDestroyed()

expect(this.plugin.setPosition).toHaveBeenCalledWith(this.plugin.defaultTime)
expect(this.plugin.setPosition).toHaveBeenCalledWith(DEFAULT_TIME)
})
test('calls setDuration method with defaultTime getter value', () => {
test('calls setDuration method with default time value', () => {
jest.spyOn(this.plugin, 'setDuration')
this.plugin.onContainerDestroyed()

expect(this.plugin.setDuration).toHaveBeenCalledWith(this.plugin.defaultTime)
expect(this.plugin.setDuration).toHaveBeenCalledWith(DEFAULT_TIME)
})
})

Expand Down

0 comments on commit 0e791ac

Please sign in to comment.