diff options
author | Eric Eastwood <contact@ericeastwood.com> | 2017-06-06 15:46:31 -0500 |
---|---|---|
committer | Eric Eastwood <contact@ericeastwood.com> | 2017-06-23 02:12:45 -0500 |
commit | 6cb575d612cd2470ee4224159fa16458f5426f73 (patch) | |
tree | da44a611e31d2f694ed8f3e55b1e45aac3703cae /spec | |
parent | bf0b3d835211077cb10ee3aec9ee6e0bca2304b6 (diff) | |
download | gitlab-ce-6cb575d612cd2470ee4224159fa16458f5426f73.tar.gz |
Add support for multiple tooltips in the same Vue component
Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/33223
Diffstat (limited to 'spec')
6 files changed, 101 insertions, 9 deletions
diff --git a/spec/javascripts/environments/environment_actions_spec.js b/spec/javascripts/environments/environment_actions_spec.js index 596d812c724..ea40a1fcd4b 100644 --- a/spec/javascripts/environments/environment_actions_spec.js +++ b/spec/javascripts/environments/environment_actions_spec.js @@ -32,9 +32,16 @@ describe('Actions Component', () => { }).$mount(); }); + describe('computed', () => { + it('title', () => { + expect(component.title).toEqual('Deploy to...'); + }); + }); + it('should render a dropdown button with icon and title attribute', () => { expect(component.$el.querySelector('.fa-caret-down')).toBeDefined(); - expect(component.$el.querySelector('.dropdown-new').getAttribute('title')).toEqual('Deploy to...'); + expect(component.$el.querySelector('.dropdown-new').getAttribute('data-original-title')).toEqual('Deploy to...'); + expect(component.$el.querySelector('.dropdown-new').getAttribute('aria-label')).toEqual('Deploy to...'); }); it('should render a dropdown with the provided list of actions', () => { diff --git a/spec/javascripts/environments/environment_monitoring_spec.js b/spec/javascripts/environments/environment_monitoring_spec.js index 0f3dba66230..f8d8223967a 100644 --- a/spec/javascripts/environments/environment_monitoring_spec.js +++ b/spec/javascripts/environments/environment_monitoring_spec.js @@ -3,21 +3,30 @@ import monitoringComp from '~/environments/components/environment_monitoring.vue describe('Monitoring Component', () => { let MonitoringComponent; + let component; + + const monitoringUrl = 'https://gitlab.com'; beforeEach(() => { MonitoringComponent = Vue.extend(monitoringComp); - }); - it('should render a link to environment monitoring page', () => { - const monitoringUrl = 'https://gitlab.com'; - const component = new MonitoringComponent({ + component = new MonitoringComponent({ propsData: { monitoringUrl, }, }).$mount(); + }); + describe('computed', () => { + it('title', () => { + expect(component.title).toEqual('Monitoring'); + }); + }); + + it('should render a link to environment monitoring page', () => { expect(component.$el.getAttribute('href')).toEqual(monitoringUrl); expect(component.$el.querySelector('.fa-area-chart')).toBeDefined(); - expect(component.$el.getAttribute('title')).toEqual('Monitoring'); + expect(component.$el.getAttribute('data-original-title')).toEqual('Monitoring'); + expect(component.$el.getAttribute('aria-label')).toEqual('Monitoring'); }); }); diff --git a/spec/javascripts/environments/environment_stop_spec.js b/spec/javascripts/environments/environment_stop_spec.js index 8131f1e5b11..3f95faf466a 100644 --- a/spec/javascripts/environments/environment_stop_spec.js +++ b/spec/javascripts/environments/environment_stop_spec.js @@ -17,8 +17,15 @@ describe('Stop Component', () => { }).$mount(); }); + describe('computed', () => { + it('title', () => { + expect(component.title).toEqual('Stop'); + }); + }); + it('should render a button to stop the environment', () => { expect(component.$el.tagName).toEqual('BUTTON'); - expect(component.$el.getAttribute('title')).toEqual('Stop'); + expect(component.$el.getAttribute('data-original-title')).toEqual('Stop'); + expect(component.$el.getAttribute('aria-label')).toEqual('Stop'); }); }); diff --git a/spec/javascripts/environments/environment_terminal_button_spec.js b/spec/javascripts/environments/environment_terminal_button_spec.js index 858472af4b6..f1576b19d1b 100644 --- a/spec/javascripts/environments/environment_terminal_button_spec.js +++ b/spec/javascripts/environments/environment_terminal_button_spec.js @@ -16,9 +16,16 @@ describe('Stop Component', () => { }).$mount(); }); + describe('computed', () => { + it('title', () => { + expect(component.title).toEqual('Terminal'); + }); + }); + it('should render a link to open a web terminal with the provided path', () => { expect(component.$el.tagName).toEqual('A'); - expect(component.$el.getAttribute('title')).toEqual('Terminal'); + expect(component.$el.getAttribute('data-original-title')).toEqual('Terminal'); + expect(component.$el.getAttribute('aria-label')).toEqual('Terminal'); expect(component.$el.getAttribute('href')).toEqual(terminalPath); }); }); diff --git a/spec/javascripts/vue_shared/components/time_ago_tooltip_spec.js b/spec/javascripts/vue_shared/components/time_ago_tooltip_spec.js index f3b4adc0b70..b4c1f70ed1e 100644 --- a/spec/javascripts/vue_shared/components/time_ago_tooltip_spec.js +++ b/spec/javascripts/vue_shared/components/time_ago_tooltip_spec.js @@ -22,7 +22,6 @@ describe('Time ago with tooltip component', () => { }).$mount(); expect(vm.$el.tagName).toEqual('TIME'); - expect(vm.$el.classList.contains('js-vue-timeago')).toEqual(true); expect( vm.$el.getAttribute('data-original-title'), ).toEqual(gl.utils.formatDate('2017-05-08T14:57:39.781Z')); diff --git a/spec/javascripts/vue_shared/directives/tooltip_spec.js b/spec/javascripts/vue_shared/directives/tooltip_spec.js new file mode 100644 index 00000000000..b1b3071527b --- /dev/null +++ b/spec/javascripts/vue_shared/directives/tooltip_spec.js @@ -0,0 +1,63 @@ +import Vue from 'vue'; +import tooltip from '~/vue_shared/directives/tooltip'; + +describe('Tooltip directive', () => { + let vm; + + afterEach(() => { + if (vm) { + vm.$destroy(); + } + }); + + describe('with a single tooltip', () => { + beforeEach(() => { + const SomeComponent = Vue.extend({ + directives: { + tooltip, + }, + template: ` + <div + v-tooltip + title="foo"> + </div> + `, + }); + + vm = new SomeComponent().$mount(); + }); + + it('should have tooltip plugin applied', () => { + expect($(vm.$el).data('bs.tooltip')).toBeDefined(); + }); + }); + + describe('with multiple tooltips', () => { + beforeEach(() => { + const SomeComponent = Vue.extend({ + directives: { + tooltip, + }, + template: ` + <div> + <div + v-tooltip + class="js-look-for-tooltip" + title="foo"> + </div> + <div + v-tooltip + title="bar"> + </div> + </div> + `, + }); + + vm = new SomeComponent().$mount(); + }); + + it('should have tooltip plugin applied to all instances', () => { + expect($(vm.$el).find('.js-look-for-tooltip').data('bs.tooltip')).toBeDefined(); + }); + }); +}); |