2017-03-13 20:58:26 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import actionsComp from '~/environments/components/environment_actions';
|
2016-11-10 13:58:35 -05:00
|
|
|
|
|
|
|
describe('Actions Component', () => {
|
2017-03-13 20:58:26 -04:00
|
|
|
let ActionsComponent;
|
|
|
|
let actionsMock;
|
|
|
|
let spy;
|
|
|
|
let component;
|
2016-11-10 13:58:35 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-03-13 20:58:26 -04:00
|
|
|
ActionsComponent = Vue.extend(actionsComp);
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2017-03-13 20:58:26 -04:00
|
|
|
actionsMock = [
|
2016-11-10 13:58:35 -05:00
|
|
|
{
|
|
|
|
name: 'bar',
|
2016-11-18 14:40:47 -05:00
|
|
|
play_path: 'https://gitlab.com/play',
|
2016-11-10 13:58:35 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'foo',
|
2016-11-18 14:40:47 -05:00
|
|
|
play_path: '#',
|
2016-11-10 13:58:35 -05:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2017-03-13 20:58:26 -04:00
|
|
|
spy = jasmine.createSpy('spy').and.returnValue(Promise.resolve());
|
|
|
|
component = new ActionsComponent({
|
2016-11-10 13:58:35 -05:00
|
|
|
propsData: {
|
|
|
|
actions: actionsMock,
|
2017-03-13 20:58:26 -04:00
|
|
|
service: {
|
|
|
|
postAction: spy,
|
|
|
|
},
|
2016-11-10 13:58:35 -05:00
|
|
|
},
|
2017-03-13 20:58:26 -04:00
|
|
|
}).$mount();
|
|
|
|
});
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2017-03-13 20:58:26 -04:00
|
|
|
it('should render a dropdown with the provided actions', () => {
|
2016-11-10 13:58:35 -05:00
|
|
|
expect(
|
2016-11-14 17:37:13 -05:00
|
|
|
component.$el.querySelectorAll('.dropdown-menu li').length,
|
2016-11-10 13:58:35 -05:00
|
|
|
).toEqual(actionsMock.length);
|
2017-03-13 20:58:26 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call the service when an action is clicked', () => {
|
|
|
|
component.$el.querySelector('.dropdown').click();
|
|
|
|
component.$el.querySelector('.js-manual-action-link').click();
|
|
|
|
|
|
|
|
expect(spy).toHaveBeenCalledWith(actionsMock[0].play_path);
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
});
|