2017-05-02 07:03:58 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import eventHub from '~/deploy_keys/eventhub';
|
|
|
|
import actionBtn from '~/deploy_keys/components/action_btn.vue';
|
|
|
|
|
|
|
|
describe('Deploy keys action btn', () => {
|
|
|
|
const data = getJSONFixture('deploy_keys/keys.json');
|
|
|
|
const deployKey = data.enabled_keys[0];
|
|
|
|
let vm;
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
beforeEach(done => {
|
|
|
|
const ActionBtnComponent = Vue.extend({
|
|
|
|
components: {
|
|
|
|
actionBtn,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
deployKey,
|
|
|
|
};
|
2017-05-02 07:03:58 -04:00
|
|
|
},
|
2018-05-07 14:21:34 -04:00
|
|
|
template: `
|
|
|
|
<action-btn
|
|
|
|
:deploy-key="deployKey"
|
|
|
|
type="enable">
|
|
|
|
Enable
|
|
|
|
</action-btn>`,
|
|
|
|
});
|
|
|
|
|
|
|
|
vm = new ActionBtnComponent().$mount();
|
2017-05-02 07:03:58 -04:00
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-05-02 07:03:58 -04:00
|
|
|
});
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
it('renders the default slot', () => {
|
|
|
|
expect(vm.$el.textContent.trim()).toBe('Enable');
|
2017-05-02 07:03:58 -04:00
|
|
|
});
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
it('sends eventHub event with btn type', done => {
|
2017-05-02 07:03:58 -04:00
|
|
|
spyOn(eventHub, '$emit');
|
|
|
|
|
|
|
|
vm.$el.click();
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('enable.key', deployKey, jasmine.anything());
|
2017-05-02 07:03:58 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
it('shows loading spinner after click', done => {
|
2017-05-02 07:03:58 -04:00
|
|
|
vm.$el.click();
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.fa')).toBeDefined();
|
2017-05-02 07:03:58 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
it('disables button after click', done => {
|
2017-05-02 07:03:58 -04:00
|
|
|
vm.$el.click();
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.$el.classList.contains('disabled')).toBeTruthy();
|
2017-05-02 07:03:58 -04:00
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
expect(vm.$el.getAttribute('disabled')).toBe('disabled');
|
2017-05-02 07:03:58 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|