jam-cloud/web/spec/javascripts/recording_source_spec.js.co...

60 lines
2.2 KiB
CoffeeScript
Raw Permalink Normal View History

describe "RecordingSource", ->
$('<link/>',
rel: 'stylesheet'
type: 'text/css'
href: '/assets/client/site_validator.css').appendTo 'head'
fixture.preload("recordingSource.html")
beforeEach ->
@server = sinon.fakeServer.create();
window.jamClient = sinon.stub()
@fixtures = fixture.load("recordingSource.html", true)
window.gon = {}
window.gon.isNativeClient = true
afterEach ->
@server.restore()
describe "youtube recording source", ->
beforeEach ->
@recSource = new JK.RecordingSourceValidator('rec_youtube')
sources = [{ url: 'https://www.youtube.com/watch?v=i_xFOmYxKYz', recording_id: 'i_xFOmYxKYz' }]
@recSource.init(sources)
@url = 'https://www.youtube.com/watch?v=i_xFOmYxKYz'
it "displays validator widget", ->
@recSource.data_input.val(@url)
@recSource.siteIsValid()
expect(@recSource.checkmark).toBeVisible()
it "initializes sources properly", ->
expect(@recSource.recording_sources.length).toEqual(1)
2015-02-18 06:33:06 +00:00
it "adds source entries properly", ->
@url = "https://www.youtube.com/watch?v=_wYtG7aQTHA"
@server.respondWith("GET", '/api/data_validation?sitetype=rec_youtube&data=' + encodeURIComponent(@url),
[200, { "content-type": "application/json" }, JSON.stringify({"message": "Valid Site", "data": @url, "recording_id" : "_wYtG7aQTHA"})])
sinon.spy()
@recSource.data_input.val(@url)
@recSource.add_btn.click()
@server.respond()
expect(@recSource.state().state()).toEqual('resolved')
2015-02-18 06:33:06 +00:00
expect(@recSource.containsRecordingUrl(@url)).toEqual(true)
it "rejects duplicate source entries", ->
rec_src_len = @recSource.recording_sources.length
@server.respondWith("GET", '/api/data_validation?sitetype=url&data=' + encodeURIComponent(@url),
[200, { "content-type": "application/json" }, JSON.stringify({"message": "Valid Site"})])
sinon.spy()
@recSource.data_input.val(@url)
@recSource.add_btn.click()
@server.respond()
expect(@recSource.state().state()).toEqual('pending')
expect(@recSource.recording_sources.length).toEqual(rec_src_len)
it "removes sources", ->
expect(@recSource.removeRecordingId('i_xFOmYxKYz')).toEqual(true)