debian-mirror-gitlab/spec/frontend/ide/components/commit_sidebar/radio_group_spec.js

135 lines
3 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import Vue from 'vue';
2020-05-24 23:13:21 +05:30
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
2020-01-01 13:55:28 +05:30
import radioGroup from '~/ide/components/commit_sidebar/radio_group.vue';
2021-03-11 19:13:27 +05:30
import { createStore } from '~/ide/stores';
2018-05-09 12:01:36 +05:30
describe('IDE commit sidebar radio group', () => {
let vm;
2020-10-24 23:57:45 +05:30
let store;
2018-05-09 12:01:36 +05:30
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
2020-10-24 23:57:45 +05:30
store = createStore();
2018-05-09 12:01:36 +05:30
const Component = Vue.extend(radioGroup);
store.state.commit.commitAction = '2';
vm = createComponentWithStore(Component, store, {
value: '1',
label: 'test',
checked: true,
});
vm.$mount();
Vue.nextTick(done);
});
afterEach(() => {
vm.$destroy();
});
it('uses label if present', () => {
expect(vm.$el.textContent).toContain('test');
});
2021-03-08 18:12:59 +05:30
it('uses slot if label is not present', (done) => {
2018-05-09 12:01:36 +05:30
vm.$destroy();
vm = new Vue({
components: {
radioGroup,
},
store,
2021-03-08 18:12:59 +05:30
render: (createElement) =>
2020-05-24 23:13:21 +05:30
createElement('radio-group', { props: { value: '1' } }, 'Testing slot'),
2018-05-09 12:01:36 +05:30
});
vm.$mount();
Vue.nextTick(() => {
expect(vm.$el.textContent).toContain('Testing slot');
done();
});
});
2021-03-08 18:12:59 +05:30
it('updates store when changing radio button', (done) => {
2018-05-09 12:01:36 +05:30
vm.$el.querySelector('input').dispatchEvent(new Event('change'));
Vue.nextTick(() => {
expect(store.state.commit.commitAction).toBe('1');
done();
});
});
describe('with input', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
2018-05-09 12:01:36 +05:30
vm.$destroy();
const Component = Vue.extend(radioGroup);
store.state.commit.commitAction = '1';
2019-07-07 11:18:12 +05:30
store.state.commit.newBranchName = 'test-123';
2018-05-09 12:01:36 +05:30
vm = createComponentWithStore(Component, store, {
value: '1',
label: 'test',
checked: true,
showInput: true,
});
vm.$mount();
Vue.nextTick(done);
});
it('renders input box when commitAction matches value', () => {
expect(vm.$el.querySelector('.form-control')).not.toBeNull();
});
2021-03-08 18:12:59 +05:30
it('hides input when commitAction doesnt match value', (done) => {
2018-05-09 12:01:36 +05:30
store.state.commit.commitAction = '2';
Vue.nextTick(() => {
expect(vm.$el.querySelector('.form-control')).toBeNull();
done();
});
});
2021-03-08 18:12:59 +05:30
it('updates branch name in store on input', (done) => {
2018-05-09 12:01:36 +05:30
const input = vm.$el.querySelector('.form-control');
input.value = 'testing-123';
input.dispatchEvent(new Event('input'));
Vue.nextTick(() => {
expect(store.state.commit.newBranchName).toBe('testing-123');
done();
});
});
2019-07-07 11:18:12 +05:30
it('renders newBranchName if present', () => {
const input = vm.$el.querySelector('.form-control');
expect(input.value).toBe('test-123');
});
2018-05-09 12:01:36 +05:30
});
2018-11-08 19:23:39 +05:30
describe('tooltipTitle', () => {
it('returns title when disabled', () => {
vm.title = 'test title';
vm.disabled = true;
expect(vm.tooltipTitle).toBe('test title');
});
it('returns blank when not disabled', () => {
vm.title = 'test title';
expect(vm.tooltipTitle).not.toBe('test title');
});
});
2018-05-09 12:01:36 +05:30
});