[BUGFIX] Fix bug in Popover.setOptions and add JSUnit tests 39/50339/3
authorFrank Naegler <frank.naegler@typo3.org>
Mon, 24 Oct 2016 14:01:28 +0000 (16:01 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 24 Oct 2016 16:27:31 +0000 (18:27 +0200)
Resolves: #78396
Releases: master
Change-Id: I9a132a547b3be04417094b3ce5a2e1eed6dd843c
Reviewed-on: https://review.typo3.org/50339
Reviewed-by: Stefan Bürk <stefan.buerk@impactmedia.de>
Tested-by: Stefan Bürk <stefan.buerk@impactmedia.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Resources/Public/JavaScript/Popover.js
typo3/sysext/backend/Tests/JavaScript/PopoverTest.js [new file with mode: 0644]

index ad3689d..f7904e6 100644 (file)
@@ -51,8 +51,8 @@ define(['jquery', 'bootstrap'], function($) {
         */
        Popover.setOptions = function($element, options) {
                options = options || {};
-               var title = options.title || '';
-               var content = options.content || ';
+               var title = options.title || $element.data('title') || '';
+               var content = options.content || $element.data('content') || '';
                $element
                        .attr('data-original-title', title)
                        .attr('data-content', content)
diff --git a/typo3/sysext/backend/Tests/JavaScript/PopoverTest.js b/typo3/sysext/backend/Tests/JavaScript/PopoverTest.js
new file mode 100644 (file)
index 0000000..e213158
--- /dev/null
@@ -0,0 +1,75 @@
+define(['jquery', 'bootstrap', 'TYPO3/CMS/Backend/Popover'], function($, bootstrap, Popover) {
+       'use strict';
+
+       describe('TYPO3/CMS/Backend/PopoverTest:', function() {
+               /**
+                * @test
+                */
+               describe('initialize', function() {
+                       var $body = $('body');
+                       var $element = $('<div data-toggle="popover">');
+                       $body.append($element);
+                       it('works with default selector', function() {
+                               Popover.initialize();
+                               expect($element[0].outerHTML).toBe('<div data-toggle="popover" data-original-title="" title=""></div>');
+                       });
+
+                       var $element2 = $('<div data-toggle="popover" data-title="foo">');
+                       $body.append($element2);
+                       it('works with default selector and title attribute', function() {
+                               Popover.initialize();
+                               expect($element2[0].outerHTML).toBe('<div data-toggle="popover" data-title="foo" data-original-title="" title=""></div>');
+                       });
+
+                       var $element3 = $('<div data-toggle="popover" data-content="foo">');
+                       $body.append($element3);
+                       it('works with default selector and content attribute', function() {
+                               Popover.initialize();
+                               expect($element3[0].outerHTML).toBe('<div data-toggle="popover" data-content="foo" data-original-title="" title=""></div>');
+                       });
+
+                       var $element4 = $('<div class="t3js-popover">');
+                       $body.append($element4);
+                       it('works with custom selector', function() {
+                               Popover.initialize('.t3js-popover');
+                               expect($element4[0].outerHTML).toBe('<div class="t3js-popover" data-original-title="" title=""></div>');
+                       });
+               });
+
+               describe('call setOptions', function() {
+                       var $body = $('body');
+                       var $element = $('<div class="t3js-test-set-options" data-title="foo-title" data-content="foo-content">');
+                       $body.append($element);
+                       it('can set title', function() {
+                               Popover.initialize('.t3js-test-set-options');
+                               expect($element.attr('data-title')).toBe('foo-title');
+                               expect($element.attr('data-content')).toBe('foo-content');
+                               expect($element.attr('data-original-title')).toBe('');
+                               expect($element.attr('title')).toBe('');
+                               Popover.setOptions($element, {
+                                       'title': 'bar-title'
+                               });
+                               expect($element.attr('data-title')).toBe('foo-title');
+                               expect($element.attr('data-content')).toBe('foo-content');
+                               expect($element.attr('data-original-title')).toBe('bar-title');
+                               expect($element.attr('title')).toBe('');
+                       });
+                       var $element2 = $('<div class="t3js-test-set-options2" data-title="foo-title" data-content="foo-content">');
+                       $body.append($element2);
+                       it('can set content', function() {
+                               Popover.initialize('.t3js-test-set-options2');
+                               expect($element2.attr('data-title')).toBe('foo-title');
+                               expect($element2.attr('data-content')).toBe('foo-content');
+                               expect($element2.attr('data-original-title')).toBe('');
+                               expect($element2.attr('title')).toBe('');
+                               Popover.setOptions($element2, {
+                                       'content': 'bar-content'
+                               });
+                               expect($element2.attr('data-title')).toBe('foo-title');
+                               expect($element2.attr('data-content')).toBe('bar-content');
+                               expect($element2.attr('data-original-title')).toBe('foo-title');
+                               expect($element2.attr('title')).toBe('');
+                       });
+               });
+       });
+});