Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('failed call with unknown error to defaultClient should show download dir error and disabled input', async function () {
const vm = new Constructor().$mount()
const defaultClientDeferred = new Deferred()
const defaultClientStub = sandbox.stub(api.default, 'defaultClient', () => defaultClientDeferred.promise)
const consoleErrorStub = sandbox.stub(console, 'error')
await Vue.nextTick()
expect(vm.$refs.addTopicDialog).to.be.ok
expect(vm.$refs.downloadDirNotSupportedError).to.be.not.ok
expect(vm.$refs.downloadDirError).to.be.not.ok
const openPromise = vm.open()
const error = new Error('failed to get default client')
defaultClientDeferred.reject(error)
await openPromise
await Vue.nextTick()
expect(vm.additionalFields.downloadDir.support).to.be.equal(false)
it(`should display loading for download dir after open and hide on finish`, async function () {
const vm = new Constructor().$mount()
await Vue.nextTick()
expect(vm.$refs.addTopicDialog).to.be.ok
const defaultClientDeferred = new Deferred()
sandbox.stub(api.default, 'defaultClient', () => defaultClientDeferred.promise)
expect(vm.additionalFields.downloadDir.loading).to.be.false
const openPromise = vm.open()
await Vue.nextTick()
expect(vm.additionalFields.downloadDir.loading).to.be.true
expect(vm.$refs.downloadDirProgress.$el.style.opacity).to.equal('1')
defaultClientDeferred.resolve(defaultClientResult)
await openPromise
await Vue.nextTick()
expect(vm.additionalFields.downloadDir.loading).to.be.false
it(`should display loading for parse url after set topic.url and hide on finish`, async function () {
const vm = new Constructor().$mount()
await Vue.nextTick()
expect(vm.$refs.addTopicDialog).to.be.ok
createDefaultClientStub()
const parseUrlDeferred = new Deferred()
sandbox.stub(api.default, 'parseUrl', () => parseUrlDeferred.promise)
expect(vm.topic.loading).to.be.false
const url = 'https://lostfilm.tv/series/TV_Show/seasons'
vm.topic.url = url
await Vue.nextTick()
expect(vm.topic.loading).to.be.true
parseUrlDeferred.resolve(parseUrlResult)
await Vue.nextTick()
expect(vm.topic.loading).to.be.false
})
it(`checkTracker should be delegated to api.trackers.check`, async () => {
const checkDeferred = new Deferred()
const check = sandbox.stub(api.default.trackers, 'check', t => checkDeferred.promise)
store.actions.checkTracker(undefined, 'tracker1.com')
expect(check).have.been.calledOnce
expect(check).have.been.calledWith('tracker1.com')
})
})
it(`saveTracker() with exception should be rethrown`, async () => {
const saveDeferred = new Deferred()
const save = sandbox.stub(api.default.trackers, 'save', t => saveDeferred.promise)
const commit = sandbox.spy()
const model = {username: 'username1', password: 'password1'}
const savePromise = store.actions.saveTracker({ commit }, {tracker: 'tracker1.com', settings: model})
expect(commit).have.been.calledOnce
expect(commit).have.been.calledWith(types.SET_TRACKER_MODEL_SAVING, true)
expect(save).have.been.calledOnce
expect(save).have.been.calledWith('tracker1.com', model)
commit.reset()
const error = new Error(`Can't save`)
it(`'watchExecute' should works`, async () => {
const currentStub = sandbox.stub(api.default.execute, 'current')
const deferred = new Deferred()
currentStub.onCall(0).returns(Promise.resolve({is_running: false, logs: []}))
currentStub.onCall(1).returns(Promise.resolve({is_running: true, logs: []}))
currentStub.onCall(2).returns(Promise.resolve({is_running: true, logs: [{execute_id: 2345}]}))
currentStub.onCall(3).returns(Promise.resolve({is_running: false, logs: []}))
currentStub.onCall(4).returns(deferred.promise)
const dispatchStub = sandbox.stub()
const watchExecuteResult = store.actions.watchExecute({ dispatch: dispatchStub })
expect(dispatchStub).to.have.been.calledOnce
expect(dispatchStub).to.have.been.calledWith('executeCurrent')
dispatchStub.reset()
const executeCurrentPromise = store.actions.executeCurrent({ dispatch: dispatchStub })
it(`show loading on openEdit`, async function () {
const vm = new Constructor().$mount()
await Vue.nextTick()
const getTopicDefered = new Deferred()
const getTopicStub = sandbox.stub(api.default, 'getTopic', () => getTopicDefered.promise)
const defaultClientStub = createDefaultClientStub()
const openEditPromise = vm.openEdit(12)
await Vue.nextTick()
expect(vm.mode).to.be.equal('edit')
expect(vm.topic.id).to.be.equal(12)
expect(vm.topic.error).to.be.null
expect(vm.topic.url).to.be.null
expect(vm.topic.loading).to.be.true
expect(vm.$refs.topicProgress.$el.style.opacity).to.equal('1')
expect(vm.$refs.add).to.be.not.ok
expect(vm.$refs.save).to.be.ok
getTopicDefered.resolve(parseUrlResult)
it('failed call with unknow error to parseUrl should set error and print error to console', async function () {
const vm = new Constructor().$mount()
await Vue.nextTick()
expect(vm.$refs.addTopicDialog).to.be.ok
const parseUrlDeferred = new Deferred()
const parseUrlStub = sandbox.stub(api.default, 'parseUrl', () => parseUrlDeferred.promise)
const parseUrlSpy = sandbox.spy(vm, 'parseUrl')
const url = 'https://lostfilm.tv/series/TV_Show/seasons'
vm.topic.url = url
expect(parseUrlSpy).have.not.been.called
await Vue.nextTick()
expect(parseUrlSpy).have.been.calledOnce
const consoleErrorStub = sandbox.stub(console, 'error')
const error = new Error(`NetworkError`)
it(`saveTracker() should be called`, async () => {
const saveDeferred = new Deferred()
const save = sandbox.stub(api.default.trackers, 'save', t => saveDeferred.promise)
const commit = sandbox.spy()
const model = {username: 'username1', password: 'password1'}
const savePromise = store.actions.saveTracker({ commit }, {tracker: 'tracker1.com', settings: model})
expect(commit).have.been.calledOnce
expect(commit).have.been.calledWith(types.SET_TRACKER_MODEL_SAVING, true)
expect(save).have.been.calledOnce
expect(save).have.been.calledWith('tracker1.com', model)
commit.reset()
saveDeferred.resolve()
actions[key] = function ({ commit }, params) {
const result = results[key] = new Deferred()
result.commit = commit
result.params = params
return result.promise
}
sandbox.spy(actions, key)