Skip to content

Commit

Permalink
Merge pull request #1567 from vagnervjs/fix/configure
Browse files Browse the repository at this point in the history
Fix - Configure ignoring options when has source attribute
  • Loading branch information
leandromoreira committed Feb 9, 2018
2 parents 8916770 + d705c05 commit 64afb50
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/components/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,12 @@ export default class Core extends UIObject {
this.configureDomRecycler()
const sources = options.source || options.sources

if (sources) { this.load(sources, options.mimeType || this.options.mimeType) } else {
this.trigger(Events.CORE_OPTIONS_CHANGE)
if (sources) this.load(sources, options.mimeType || this.options.mimeType)

this.containers.forEach((container) => {
container.configure(this.options)
})
}
this.trigger(Events.CORE_OPTIONS_CHANGE)
this.containers.forEach((container) => {
container.configure(this.options)
})
}

appendToParent() {
Expand Down
44 changes: 44 additions & 0 deletions test/components/core_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Core from '../../src/components/core'
import Events from '../../src/base/events'

describe('Core', function() {
describe('When configure', function() {
beforeEach(function () {
this.core = new Core({})
this.core.load = sinon.spy()
})

it('should update option', function() {
const newOptions = {
autoPlay: true
}
this.core.configure(newOptions)

expect(this.core.options.autoPlay).to.equal(newOptions.autoPlay)
})

it('should update option and load source', function() {
const newOptions = {
source: 'some/path/to/media.mp4',
mute: true
}
this.core.configure(newOptions)

assert.ok(this.core.load.called)
expect(this.core.options.mute).to.equal(newOptions.mute)
})

it('shoud trigger options change event', function () {
let callback = sinon.spy()
this.core.on(Events.CORE_OPTIONS_CHANGE, callback)

const newOptions = {
autoPlay: false
}
this.core.configure(newOptions)

assert.ok(callback.called)
expect(this.core.options.autoPlay).to.equal(newOptions.autoPlay)
})
})
})

0 comments on commit 64afb50

Please sign in to comment.