From 8f6f7b3e86a05d4c1f79eeab248a0a4836cc3b8c Mon Sep 17 00:00:00 2001 From: Benjamin Franzke <bfr@qbus.de> Date: Mon, 20 Dec 2021 22:34:23 +0100 Subject: [PATCH] [TASK] Port remaining JavaScript unit tests to TypeScript Helps to migrate to ES6 modules as that's just a tsconfig setting then. Releases: main Resolves: #96409 Related: #96323 Change-Id: Ib897c3c2cfdb6d7ff0a88ea70ed9213b33dd2138 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72753 Tested-by: Benni Mack <benni@typo3.org> Tested-by: core-ci <typo3@b13.com> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Benjamin Franzke <bfr@qbus.de> Reviewed-by: Benni Mack <benni@typo3.org> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Benjamin Franzke <bfr@qbus.de> --- .../backend/Tests/FormEngineValidationTest.ts | 440 ++++++++++++++++++ .../TypeScript/backend/Tests/IconsTest.ts | 65 +++ .../TypeScript/backend/Tests/PopoverTest.ts | 77 +++ Build/types/TYPO3/index.d.ts | 12 + .../Public/JavaScript/FormEngineValidation.js | 2 +- .../JavaScript/FormEngineValidationTest.js | 434 +---------------- .../backend/Tests/JavaScript/IconsTest.js | 77 +-- .../backend/Tests/JavaScript/PopoverTest.js | 90 +--- 8 files changed, 634 insertions(+), 563 deletions(-) create mode 100644 Build/Sources/TypeScript/backend/Tests/FormEngineValidationTest.ts create mode 100644 Build/Sources/TypeScript/backend/Tests/IconsTest.ts create mode 100644 Build/Sources/TypeScript/backend/Tests/PopoverTest.ts diff --git a/Build/Sources/TypeScript/backend/Tests/FormEngineValidationTest.ts b/Build/Sources/TypeScript/backend/Tests/FormEngineValidationTest.ts new file mode 100644 index 000000000000..721c156ab3ba --- /dev/null +++ b/Build/Sources/TypeScript/backend/Tests/FormEngineValidationTest.ts @@ -0,0 +1,440 @@ +import $ from 'jquery'; +import FormEngineValidation = require('TYPO3/CMS/Backend/FormEngineValidation'); + +declare function using(values: Function|Array<Object>|Object, func: Function): void; + +interface FormEngineConfig { + [x: string]: any; +} + +interface FormatValueData { + description: string, + type: string, + value: number|string, + config: FormEngineConfig, + result: string +} + +interface ProcessValueData { + description: string, + command: string, + value: string, + config: FormEngineConfig, + result: string +} + +describe('TYPO3/CMS/Backend/FormEngineValidationTest:', () => { + const formatValueDataProvider: Array<FormatValueData> = [ + { + 'description': 'works for type date', + 'type': 'date', + 'value': 0, + 'config': {}, + 'result': '' + }, + { + 'description': 'works for type date with timestamp', + 'type': 'date', + 'value': 10000000, + 'config': {}, + 'result': '26-04-1970' + }, + { + 'description': 'works for type date with iso date', + 'type': 'date', + 'value': '2016-12-02T11:16:06+00:00', + 'config': {}, + 'result': '02-12-2016' + }, + { + 'description': 'works for type datetime', + 'type': 'datetime', + 'value': 0, + 'config': {}, + 'result': '' + }, + { + 'description': 'works for type datetime with timestamp', + 'type': 'datetime', + 'value': 10000000, + 'config': {}, + 'result': '17:46 26-04-1970' + }, + { + 'description': 'works for type datetime with iso date', + 'type': 'datetime', + 'value': '2016-12-02T11:16:06+00:00', + 'config': {}, + 'result': '11:16 02-12-2016' + }, + { + 'description': 'resolves to empty result for zero value', + 'type': 'datetime', + 'value': 0, + 'config': {}, + 'result': '' + }, + { + 'description': 'resolves to empty result for invalid value', + 'type': 'datetime', + 'value': 'invalid', + 'config': {}, + 'result': '' + }, + { + 'description': 'works for type time', + 'type': 'time', + 'value': 0, + 'config': {}, + 'result': '00:00' + }, + { + 'description': 'works for type time with timestamp', + 'type': 'time', + 'value': 10000000, + 'config': {}, + 'result': '17:46' + }, + { + 'description': 'works for type time with iso date', + 'type': 'time', + 'value': '2016-12-02T11:16:06+00:00', + 'config': {}, + 'result': '11:16' + } + ]; + + /** + * @dataProvider formatValueDataProvider + * @test + */ + describe('tests for formatValue', () => { + using(formatValueDataProvider, function(testCase: FormatValueData) { + it(testCase.description, () => { + FormEngineValidation.USmode = 0; + FormEngineValidation.initialize(); + const result = FormEngineValidation.formatValue(testCase.type, testCase.value, testCase.config); + expect(result).toBe(testCase.result); + }); + }); + }); + + const formatValueUsModeDataProvider: Array<FormatValueData> = [ + { + 'description': 'works for type date with timestamp in US mode', + 'type': 'date', + 'value': 10000000, + 'config': {}, + 'result': '04-26-1970' + }, + { + 'description': 'works for type date with iso date in US mode', + 'type': 'date', + 'value': '2016-12-02T11:16:06+00:00', + 'config': {}, + 'result': '12-02-2016' + }, + { + 'description': 'works for type datetime with timestamp in US mode', + 'type': 'datetime', + 'value': 10000000, + 'config': {}, + 'result': '17:46 04-26-1970' + }, + { + 'description': 'works for type datetime with iso date in US mode', + 'type': 'datetime', + 'value': '2016-12-02T11:16:06+00:00', + 'config': {}, + 'result': '11:16 12-02-2016' + }, + { + 'description': 'works for type time with timestamp in US mode', + 'type': 'time', + 'value': 10000000, + 'config': {}, + 'result': '17:46' + }, + { + 'description': 'works for type time with iso date in US mode', + 'type': 'time', + 'value': '2016-12-02T11:16:06+00:00', + 'config': {}, + 'result': '11:16' + } + ]; + + /** + * @dataProvider formatValueUsModeDataProvider + * @test + */ + describe('tests for formatValue in US Mode', () => { + using(formatValueUsModeDataProvider, function(testCase: FormatValueData) { + it(testCase.description, () => { + FormEngineValidation.USmode = 1; + FormEngineValidation.initialize(); + const result = FormEngineValidation.formatValue(testCase.type, testCase.value, testCase.config); + expect(result).toBe(testCase.result); + }); + }); + }); + + const processValueDataProvider: Array<ProcessValueData> = [ + { + 'description': 'works for command alpha with numeric value', + 'command': 'alpha', + 'value': '1234', + 'config': {}, + 'result': '' + }, + { + 'description': 'works for command alpha with string value', + 'command': 'alpha', + 'value': 'abc', + 'config': {}, + 'result': 'abc' + }, + { + 'description': 'works for command alpha with alphanum input', + 'command': 'alpha', + 'value': 'abc123', + 'config': {}, + 'result': 'abc' + }, + { + 'description': 'works for command alpha with alphanum input', + 'command': 'alpha', + 'value': '123abc123', + 'config': {}, + 'result': 'abc' + } + ]; + + /** + * @dataProvider processValueDataProvider + * @test + */ + describe('test for processValue', () => { + using(processValueDataProvider, function(testCase: ProcessValueData) { + it(testCase.description, () => { + const result = FormEngineValidation.processValue(testCase.command, testCase.value, testCase.config); + expect(result).toBe(testCase.result); + }); + }); + }); + + /** + * @test + */ + xdescribe('tests for validateField', () => { + /* tslint:disable:no-empty */ + }); + + /** + * @test + */ + describe('tests for trimExplode', () => { + it('works for comma as separator and list without spaces', () => { + expect(FormEngineValidation.trimExplode(',', 'foo,bar,baz')).toEqual(['foo', 'bar', 'baz']); + }); + it('works for comma as separator and list with spaces', () => { + expect(FormEngineValidation.trimExplode(',', ' foo , bar , baz ')).toEqual(['foo', 'bar', 'baz']); + }); + it('works for pipe as separator and list with spaces', () => { + expect(FormEngineValidation.trimExplode('|', ' foo | bar | baz ')).toEqual(['foo', 'bar', 'baz']); + }); + }); + + /** + * @test + */ + describe('tests for parseInt', () => { + it('works for value 0', () => { + expect(FormEngineValidation.parseInt(0)).toBe(0); + }); + it('works for value 1', () => { + expect(FormEngineValidation.parseInt(1)).toBe(1); + }); + it('works for value -1', () => { + expect(FormEngineValidation.parseInt(-1)).toBe(-1); + }); + it('works for value "0"', () => { + expect(FormEngineValidation.parseInt('0')).toBe(0); + }); + it('works for value "1"', () => { + expect(FormEngineValidation.parseInt('1')).toBe(1); + }); + it('works for value "-1"', () => { + expect(FormEngineValidation.parseInt('-1')).toBe(-1); + }); + it('works for value 0.5', () => { + expect(FormEngineValidation.parseInt(0.5)).toBe(0); + }); + it('works for value "0.5"', () => { + expect(FormEngineValidation.parseInt('0.5')).toBe(0); + }); + it('works for value "foo"', () => { + expect(FormEngineValidation.parseInt('foo')).toBe(0); + }); + it('works for value true', () => { + expect(FormEngineValidation.parseInt(true)).toBe(0); + }); + it('works for value false', () => { + expect(FormEngineValidation.parseInt(false)).toBe(0); + }); + it('works for value null', () => { + expect(FormEngineValidation.parseInt(null)).toBe(0); + }); + }); + + /** + * @test + */ + describe('tests for parseDouble', () => { + it('works for value 0', () => { + expect(FormEngineValidation.parseDouble(0)).toBe('0.00'); + }); + it('works for value 1', () => { + expect(FormEngineValidation.parseDouble(1)).toBe('1.00'); + }); + it('works for value -1', () => { + expect(FormEngineValidation.parseDouble(-1)).toBe('-1.00'); + }); + it('works for value "0"', () => { + expect(FormEngineValidation.parseDouble('0')).toBe('0.00'); + }); + it('works for value "1"', () => { + expect(FormEngineValidation.parseDouble('1')).toBe('1.00'); + }); + it('works for value "-1"', () => { + expect(FormEngineValidation.parseDouble('-1')).toBe('-1.00'); + }); + it('works for value 0.5', () => { + expect(FormEngineValidation.parseDouble(0.5)).toBe('0.50'); + }); + it('works for value "0.5"', () => { + expect(FormEngineValidation.parseDouble('0.5')).toBe('0.50'); + }); + it('works for value "foo"', () => { + expect(FormEngineValidation.parseDouble('foo')).toBe('0.00'); + }); + it('works for value true', () => { + expect(FormEngineValidation.parseDouble(true)).toBe('0.00'); + }); + it('works for value false', () => { + expect(FormEngineValidation.parseDouble(false)).toBe('0.00'); + }); + it('works for value null', () => { + expect(FormEngineValidation.parseDouble(null)).toBe('0.00'); + }); + }); + + /** + * @test + */ + describe('tests for btrim', () => { + const result = FormEngineValidation.btrim(' test '); + + it('works for string with whitespace in begin and end', () => { + expect(result).toBe(' test'); + }); + }); + + /** + * @test + */ + describe('tests for ltrim', () => { + const result = FormEngineValidation.ltrim(' test '); + + it('works for string with whitespace in begin and end', () => { + expect(result).toBe('test '); + }); + }); + + /** + * @test + */ + xdescribe('tests for parseDateTime', () => { + /* tslint:disable:no-empty */ + }); + + /** + * @test + */ + xdescribe('tests for parseDate', () => { + /* tslint:disable:no-empty */ + }); + + /** + * @test + */ + xdescribe('tests for parseTime', () => { + /* tslint:disable:no-empty */ + }); + + /** + * @test + */ + xdescribe('tests for parseYear', () => { + /* tslint:disable:no-empty */ + }); + + /** + * @test + */ + describe('tests for getYear', () => { + const currentDate = new Date(); + afterEach(() => { + jasmine.clock().mockDate(currentDate); + }); + + it('works for current date', () => { + const date = new Date(); + expect(FormEngineValidation.getYear(date)).toBe(date.getFullYear()); + }); + it('works for year 2013', () => { + const baseTime = new Date(2013, 9, 23); + jasmine.clock().mockDate(baseTime); + expect(FormEngineValidation.getYear(baseTime)).toBe(2013); + }) + }); + + /** + * @test + */ + describe('tests for getDate', () => { + const currentDate = new Date(); + afterEach(() => { + jasmine.clock().mockDate(currentDate); + }); + + xit('works for year 2013', () => { + const baseTime = new Date(2013, 9, 23, 13, 13, 13); + jasmine.clock().mockDate(baseTime); + expect(FormEngineValidation.getDate(baseTime)).toBe(1382479200); + }) + }); + + /** + * @test + */ + describe('tests for splitStr', () => { + it('works for command and index', () => { + expect(FormEngineValidation.splitStr('foo,bar,baz', ',', -1)).toBe('foo'); + expect(FormEngineValidation.splitStr('foo,bar,baz', ',', 0)).toBe('foo'); + expect(FormEngineValidation.splitStr('foo,bar,baz', ',', 1)).toBe('foo'); + expect(FormEngineValidation.splitStr('foo,bar,baz', ',', 2)).toBe('bar'); + expect(FormEngineValidation.splitStr('foo,bar,baz', ',', 3)).toBe('baz'); + expect(FormEngineValidation.splitStr(' foo , bar , baz ', ',', 1)).toBe(' foo '); + expect(FormEngineValidation.splitStr(' foo , bar , baz ', ',', 2)).toBe(' bar '); + expect(FormEngineValidation.splitStr(' foo , bar , baz ', ',', 3)).toBe(' baz '); + }); + }); + + /** + * @test + */ + xdescribe('tests for split', () => { + /* tslint:disable:no-empty */ + }); +}); diff --git a/Build/Sources/TypeScript/backend/Tests/IconsTest.ts b/Build/Sources/TypeScript/backend/Tests/IconsTest.ts new file mode 100644 index 000000000000..57fffac2e559 --- /dev/null +++ b/Build/Sources/TypeScript/backend/Tests/IconsTest.ts @@ -0,0 +1,65 @@ +import $ from 'jquery'; +import Icons = require('TYPO3/CMS/Backend/Icons'); + +describe('TYPO3/CMS/Backend/IconsTest:', () => { + /** + * @test + */ + describe('tests for Icons object', () => { + it('has all sizes', () => { + expect(Icons.sizes.small).toBe('small'); + expect(Icons.sizes.default).toBe('default'); + expect(Icons.sizes.large).toBe('large'); + expect(Icons.sizes.overlay).toBe('overlay'); + }); + it('has all states', () => { + expect(Icons.states.default).toBe('default'); + expect(Icons.states.disabled).toBe('disabled'); + }); + it('has all markupIdentifiers', () => { + expect(Icons.markupIdentifiers.default).toBe('default'); + expect(Icons.markupIdentifiers.inline).toBe('inline'); + }); + }); + + /** + * @test + */ + describe('tests for Icons::getIcon', () => { + beforeEach(() => { + spyOn(Icons, 'getIcon'); + Icons.getIcon('test', Icons.sizes.small, null, Icons.states.default, Icons.markupIdentifiers.default); + }); + + it('tracks that the spy was called', () => { + expect(Icons.getIcon).toHaveBeenCalled(); + }); + it('tracks all the arguments of its calls', () => { + expect(Icons.getIcon).toHaveBeenCalledWith('test', Icons.sizes.small, null, Icons.states.default, Icons.markupIdentifiers.default); + }); + xit('works get icon from remote server'); + }); + + /** + * @test + */ + describe('tests for Icons::putInCache', () => { + it('works for simply identifier and markup', () => { + const promise = new Promise((reveal) => reveal()); + (Icons as any).putInPromiseCache('foo', promise); + expect((Icons as any).getFromPromiseCache('foo')).toBe(promise); + expect((Icons as any).isPromiseCached('foo')).toBe(true); + }); + }); + + /** + * @test + */ + describe('tests for Icons::getFromPromiseCache', () => { + it('return undefined for uncached promise', () => { + expect((Icons as any).getFromPromiseCache('bar')).not.toBeDefined(); + expect((Icons as any).isPromiseCached('bar')).toBe(false); + }); + }); +}); +; diff --git a/Build/Sources/TypeScript/backend/Tests/PopoverTest.ts b/Build/Sources/TypeScript/backend/Tests/PopoverTest.ts new file mode 100644 index 000000000000..8e22f0ad8719 --- /dev/null +++ b/Build/Sources/TypeScript/backend/Tests/PopoverTest.ts @@ -0,0 +1,77 @@ +import $ from 'jquery'; +import {Popover as BootstrapPopover} from 'bootstrap'; +import Popover = require('TYPO3/CMS/Backend/Popover'); + +describe('TYPO3/CMS/Backend/PopoverTest:', () => { + /** + * @test + */ + describe('initialize', () => { + const $body = $('body'); + const $element = $('<div data-bs-toggle="popover">'); + $body.append($element); + it('works with default selector', () => { + Popover.initialize(); + expect($element[0].outerHTML).toBe('<div data-bs-toggle="popover" data-bs-original-title="" title=""></div>'); + }); + + const $element2 = $('<div data-bs-toggle="popover" data-title="foo">'); + $body.append($element2); + it('works with default selector and title attribute', () => { + Popover.initialize(); + expect($element2[0].outerHTML).toBe('<div data-bs-toggle="popover" data-title="foo" data-bs-original-title="" title=""></div>'); + }); + + const $element3 = $('<div data-bs-toggle="popover" data-bs-content="foo">'); + $body.append($element3); + it('works with default selector and content attribute', () => { + Popover.initialize(); + expect($element3[0].outerHTML).toBe('<div data-bs-toggle="popover" data-bs-content="foo" data-bs-original-title="" title=""></div>'); + }); + + const $element4 = $('<div class="t3js-popover">'); + $body.append($element4); + it('works with custom selector', () => { + Popover.initialize('.t3js-popover'); + expect($element4[0].outerHTML).toBe('<div class="t3js-popover" data-bs-original-title="" title=""></div>'); + }); + }); + + describe('call setOptions', () => { + const $body = $('body'); + const $element = $('<div class="t3js-test-set-options" data-title="foo-title" data-bs-content="foo-content">'); + $body.append($element); + it('can set title', () => { + Popover.initialize('.t3js-test-set-options'); + expect($element.attr('data-title')).toBe('foo-title'); + expect($element.attr('data-bs-content')).toBe('foo-content'); + expect($element.attr('data-bs-original-title')).toBe(''); + expect($element.attr('title')).toBe(''); + Popover.setOptions($element, <BootstrapPopover.Options>{ + 'title': 'bar-title' + }); + expect($element.attr('data-title')).toBe('foo-title'); + expect($element.attr('data-bs-content')).toBe('foo-content'); + expect($element.attr('data-bs-original-title')).toBe('bar-title'); + expect($element.attr('title')).toBe(''); + }); + const $element2 = $('<div class="t3js-test-set-options2" data-title="foo-title" data-bs-content="foo-content">'); + $body.append($element2); + it('can set content', () => { + Popover.initialize('.t3js-test-set-options2'); + // Popover must be visible before the content can be updated manually via setOptions() + Popover.show($element2); + expect($element2.attr('data-title')).toBe('foo-title'); + expect($element2.attr('data-bs-content')).toBe('foo-content'); + expect($element2.attr('data-bs-original-title')).toBe(''); + expect($element2.attr('title')).toBe(''); + Popover.setOptions($element2, <BootstrapPopover.Options>{ + 'content': 'bar-content' + }); + expect($element2.attr('data-title')).toBe('foo-title'); + expect($element2.attr('data-bs-content')).toBe('bar-content'); + expect($element2.attr('data-bs-original-title')).toBe('foo-title'); + expect($element2.attr('title')).toBe(''); + }); + }); +}); diff --git a/Build/types/TYPO3/index.d.ts b/Build/types/TYPO3/index.d.ts index ca20acb1d028..b664899fdec4 100644 --- a/Build/types/TYPO3/index.d.ts +++ b/Build/types/TYPO3/index.d.ts @@ -39,12 +39,24 @@ declare namespace TYPO3 { export namespace Backend { export class FormEngineValidation { + public USmode: number; public readonly errorClass: string; public markFieldAsChanged(field: HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement|JQuery): void; + public trimExplode(delimiter: string, string: string): Array<string>; + public parseInt(value: number|string|boolean): number; + public parseDouble(value: number|string|boolean): string; + public ltrim(value: string): string; + public btrim(value: string): string; + public getYear(timeObj: Date): number|null; + public getDate(timeObj: Date): number; + public splitStr(theStr1: string, delim: string, index: number): Array<string>; public initializeInputFields(): void; public registerCustomEvaluation(name: string, handler: Function): void; + public formatValue(type: string, value: string|number, config: Object): string; public validate(section?: Element): void; public validateField(field: HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement|JQuery, value?: string): void; + public processValue(command: string, value: string, config: Object): string; + public initialize(): void; } export namespace FormEngine { diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js b/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js index 894d50c145a7..8cfbf340e9bc 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js @@ -152,7 +152,7 @@ define([ * Format field value * * @param {String} type - * @param {String} value + * @param {String|Number} value * @param {Object} config * @returns {String} */ diff --git a/typo3/sysext/backend/Tests/JavaScript/FormEngineValidationTest.js b/typo3/sysext/backend/Tests/JavaScript/FormEngineValidationTest.js index 97731bebbb93..72c73d54f1cb 100644 --- a/typo3/sysext/backend/Tests/JavaScript/FormEngineValidationTest.js +++ b/typo3/sysext/backend/Tests/JavaScript/FormEngineValidationTest.js @@ -1,421 +1,13 @@ -define(['jquery', 'TYPO3/CMS/Backend/FormEngineValidation'], function($, FormEngineValidation) { - 'use strict'; - - describe('TYPO3/CMS/Backend/FormEngineValidationTest:', function() { - /** - * @type {*[]} - */ - var formatValueDataProvider = [ - { - 'description': 'works for type date', - 'type': 'date', - 'value': 0, - 'config': [], - 'result': '' - }, - { - 'description': 'works for type date with timestamp', - 'type': 'date', - 'value': 10000000, - 'config': [], - 'result': '26-04-1970' - }, - { - 'description': 'works for type date with iso date', - 'type': 'date', - 'value': '2016-12-02T11:16:06+00:00', - 'config': [], - 'result': '02-12-2016' - }, - { - 'description': 'works for type datetime', - 'type': 'datetime', - 'value': 0, - 'config': [], - 'result': '' - }, - { - 'description': 'works for type datetime with timestamp', - 'type': 'datetime', - 'value': 10000000, - 'config': [], - 'result': '17:46 26-04-1970' - }, - { - 'description': 'works for type datetime with iso date', - 'type': 'datetime', - 'value': '2016-12-02T11:16:06+00:00', - 'config': [], - 'result': '11:16 02-12-2016' - }, - { - 'description': 'resolves to empty result for zero value', - 'type': 'datetime', - 'value': 0, - 'config': [], - 'result': '' - }, - { - 'description': 'resolves to empty result for invalid value', - 'type': 'datetime', - 'value': 'invalid', - 'config': [], - 'result': '' - }, - { - 'description': 'works for type time', - 'type': 'time', - 'value': 0, - 'config': [], - 'result': '00:00' - }, - { - 'description': 'works for type time with timestamp', - 'type': 'time', - 'value': 10000000, - 'config': [], - 'result': '17:46' - }, - { - 'description': 'works for type time with iso date', - 'type': 'time', - 'value': '2016-12-02T11:16:06+00:00', - 'config': [], - 'result': '11:16' - } - ]; - - /** - * @dataProvider formatValueDataProvider - * @test - */ - describe('tests for formatValue', function() { - using(formatValueDataProvider, function(testCase) { - it(testCase.description, function() { - FormEngineValidation.USmode = 0; - FormEngineValidation.initialize(); - var result = FormEngineValidation.formatValue(testCase.type, testCase.value, testCase.config); - expect(result).toBe(testCase.result); - }); - }); - }); - - /** - * @type {*[]} - */ - var formatValueUsModeDataProvider = [ - { - 'description': 'works for type date with timestamp in US mode', - 'type': 'date', - 'value': 10000000, - 'config': [], - 'result': '04-26-1970' - }, - { - 'description': 'works for type date with iso date in US mode', - 'type': 'date', - 'value': '2016-12-02T11:16:06+00:00', - 'config': [], - 'result': '12-02-2016' - }, - { - 'description': 'works for type datetime with timestamp in US mode', - 'type': 'datetime', - 'value': 10000000, - 'config': [], - 'result': '17:46 04-26-1970' - }, - { - 'description': 'works for type datetime with iso date in US mode', - 'type': 'datetime', - 'value': '2016-12-02T11:16:06+00:00', - 'config': [], - 'result': '11:16 12-02-2016' - }, - { - 'description': 'works for type time with timestamp in US mode', - 'type': 'time', - 'value': 10000000, - 'config': [], - 'result': '17:46' - }, - { - 'description': 'works for type time with iso date in US mode', - 'type': 'time', - 'value': '2016-12-02T11:16:06+00:00', - 'config': [], - 'result': '11:16' - } - ]; - - /** - * @dataProvider formatValueUsModeDataProvider - * @test - */ - describe('tests for formatValue in US Mode', function() { - using(formatValueUsModeDataProvider, function(testCase) { - it(testCase.description, function() { - FormEngineValidation.USmode = 1; - FormEngineValidation.initialize(); - var result = FormEngineValidation.formatValue(testCase.type, testCase.value, testCase.config); - expect(result).toBe(testCase.result); - }); - }); - }); - - /** - * @type {*[]} - */ - var processValueDataProvider = [ - { - 'description': 'works for command alpha with numeric value', - 'command': 'alpha', - 'value': '1234', - 'config': [], - 'result': '' - }, - { - 'description': 'works for command alpha with string value', - 'command': 'alpha', - 'value': 'abc', - 'config': [], - 'result': 'abc' - }, - { - 'description': 'works for command alpha with alphanum input', - 'command': 'alpha', - 'value': 'abc123', - 'config': [], - 'result': 'abc' - }, - { - 'description': 'works for command alpha with alphanum input', - 'command': 'alpha', - 'value': '123abc123', - 'config': [], - 'result': 'abc' - } - ]; - - /** - * @dataProvider processValueDataProvider - * @test - */ - describe('test for processValue', function() { - using(processValueDataProvider, function(testCase) { - it(testCase.description, function() { - var result = FormEngineValidation.processValue(testCase.command, testCase.value, testCase.config); - expect(result).toBe(testCase.result); - }); - }); - }); - - /** - * @test - */ - xdescribe('tests for validateField', function() { - }); - - /** - * @test - */ - describe('tests for trimExplode', function() { - it('works for comma as separator and list without spaces', function() { - expect(FormEngineValidation.trimExplode(',', 'foo,bar,baz')).toEqual(['foo', 'bar', 'baz']); - }); - it('works for comma as separator and list with spaces', function() { - expect(FormEngineValidation.trimExplode(',', ' foo , bar , baz ')).toEqual(['foo', 'bar', 'baz']); - }); - it('works for pipe as separator and list with spaces', function() { - expect(FormEngineValidation.trimExplode('|', ' foo | bar | baz ')).toEqual(['foo', 'bar', 'baz']); - }); - }); - - /** - * @test - */ - describe('tests for parseInt', function() { - it('works for value 0', function() { - expect(FormEngineValidation.parseInt(0)).toBe(0); - }); - it('works for value 1', function() { - expect(FormEngineValidation.parseInt(1)).toBe(1); - }); - it('works for value -1', function() { - expect(FormEngineValidation.parseInt(-1)).toBe(-1); - }); - it('works for value "0"', function() { - expect(FormEngineValidation.parseInt('0')).toBe(0); - }); - it('works for value "1"', function() { - expect(FormEngineValidation.parseInt('1')).toBe(1); - }); - it('works for value "-1"', function() { - expect(FormEngineValidation.parseInt('-1')).toBe(-1); - }); - it('works for value 0.5', function() { - expect(FormEngineValidation.parseInt(0.5)).toBe(0); - }); - it('works for value "0.5"', function() { - expect(FormEngineValidation.parseInt('0.5')).toBe(0); - }); - it('works for value "foo"', function() { - expect(FormEngineValidation.parseInt('foo')).toBe(0); - }); - it('works for value true', function() { - expect(FormEngineValidation.parseInt(true)).toBe(0); - }); - it('works for value false', function() { - expect(FormEngineValidation.parseInt(false)).toBe(0); - }); - it('works for value null', function() { - expect(FormEngineValidation.parseInt(null)).toBe(0); - }); - }); - /** - * @test - */ - describe('tests for parseDouble', function() { - it('works for value 0', function() { - expect(FormEngineValidation.parseDouble(0)).toBe('0.00'); - }); - it('works for value 1', function() { - expect(FormEngineValidation.parseDouble(1)).toBe('1.00'); - }); - it('works for value -1', function() { - expect(FormEngineValidation.parseDouble(-1)).toBe('-1.00'); - }); - it('works for value "0"', function() { - expect(FormEngineValidation.parseDouble('0')).toBe('0.00'); - }); - it('works for value "1"', function() { - expect(FormEngineValidation.parseDouble('1')).toBe('1.00'); - }); - it('works for value "-1"', function() { - expect(FormEngineValidation.parseDouble('-1')).toBe('-1.00'); - }); - it('works for value 0.5', function() { - expect(FormEngineValidation.parseDouble(0.5)).toBe('0.50'); - }); - it('works for value "0.5"', function() { - expect(FormEngineValidation.parseDouble('0.5')).toBe('0.50'); - }); - it('works for value "foo"', function() { - expect(FormEngineValidation.parseDouble('foo')).toBe('0.00'); - }); - it('works for value true', function() { - expect(FormEngineValidation.parseDouble(true)).toBe('0.00'); - }); - it('works for value false', function() { - expect(FormEngineValidation.parseDouble(false)).toBe('0.00'); - }); - it('works for value null', function() { - expect(FormEngineValidation.parseDouble(null)).toBe('0.00'); - }); - }); - - /** - * @test - */ - describe('tests for btrim', function() { - var result = FormEngineValidation.btrim(' test '); - - it('works for string with whitespace in begin and end', function() { - expect(result).toBe(' test'); - }); - }); - - /** - * @test - */ - describe('tests for ltrim', function() { - var result = FormEngineValidation.ltrim(' test '); - - it('works for string with whitespace in begin and end', function() { - expect(result).toBe('test '); - }); - }); - - /** - * @test - */ - xdescribe('tests for parseDateTime', function() { - }); - - /** - * @test - */ - xdescribe('tests for parseDate', function() { - }); - - /** - * @test - */ - xdescribe('tests for parseTime', function() { - }); - - /** - * @test - */ - xdescribe('tests for parseYear', function() { - }); - - /** - * @test - */ - describe('tests for getYear', function() { - var currentDate = new Date(); - afterEach(function() { - jasmine.clock().mockDate(currentDate); - }); - - it('works for current date', function() { - var date = new Date(); - expect(FormEngineValidation.getYear(date)).toBe(date.getFullYear()); - }); - it('works for year 2013', function() { - var baseTime = new Date(2013, 9, 23); - jasmine.clock().mockDate(baseTime); - expect(FormEngineValidation.getYear(baseTime)).toBe(2013); - }) - }); - - /** - * @test - */ - describe('tests for getDate', function() { - var currentDate = new Date(); - afterEach(function() { - jasmine.clock().mockDate(currentDate); - }); - - xit('works for year 2013', function() { - var baseTime = new Date(2013, 9, 23, 13, 13, 13); - jasmine.clock().mockDate(baseTime); - expect(FormEngineValidation.getDate(baseTime)).toBe(1382479200); - }) - }); - - /** - * @test - */ - describe('tests for splitStr', function() { - it('works for command and index', function() { - expect(FormEngineValidation.splitStr('foo,bar,baz', ',', -1)).toBe('foo'); - expect(FormEngineValidation.splitStr('foo,bar,baz', ',', 0)).toBe('foo'); - expect(FormEngineValidation.splitStr('foo,bar,baz', ',', 1)).toBe('foo'); - expect(FormEngineValidation.splitStr('foo,bar,baz', ',', 2)).toBe('bar'); - expect(FormEngineValidation.splitStr('foo,bar,baz', ',', 3)).toBe('baz'); - expect(FormEngineValidation.splitStr(' foo , bar , baz ', ',', 1)).toBe(' foo '); - expect(FormEngineValidation.splitStr(' foo , bar , baz ', ',', 2)).toBe(' bar '); - expect(FormEngineValidation.splitStr(' foo , bar , baz ', ',', 3)).toBe(' baz '); - }); - }); - - /** - * @test - */ - xdescribe('tests for split', function() { - }); - }); -}); +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ +define(["require","exports","TYPO3/CMS/Backend/FormEngineValidation"],(function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),describe("TYPO3/CMS/Backend/FormEngineValidationTest:",()=>{const e=[{description:"works for type date",type:"date",value:0,config:{},result:""},{description:"works for type date with timestamp",type:"date",value:1e7,config:{},result:"26-04-1970"},{description:"works for type date with iso date",type:"date",value:"2016-12-02T11:16:06+00:00",config:{},result:"02-12-2016"},{description:"works for type datetime",type:"datetime",value:0,config:{},result:""},{description:"works for type datetime with timestamp",type:"datetime",value:1e7,config:{},result:"17:46 26-04-1970"},{description:"works for type datetime with iso date",type:"datetime",value:"2016-12-02T11:16:06+00:00",config:{},result:"11:16 02-12-2016"},{description:"resolves to empty result for zero value",type:"datetime",value:0,config:{},result:""},{description:"resolves to empty result for invalid value",type:"datetime",value:"invalid",config:{},result:""},{description:"works for type time",type:"time",value:0,config:{},result:"00:00"},{description:"works for type time with timestamp",type:"time",value:1e7,config:{},result:"17:46"},{description:"works for type time with iso date",type:"time",value:"2016-12-02T11:16:06+00:00",config:{},result:"11:16"}];describe("tests for formatValue",()=>{using(e,(function(e){it(e.description,()=>{o.USmode=0,o.initialize();const t=o.formatValue(e.type,e.value,e.config);expect(t).toBe(e.result)})}))});const t=[{description:"works for type date with timestamp in US mode",type:"date",value:1e7,config:{},result:"04-26-1970"},{description:"works for type date with iso date in US mode",type:"date",value:"2016-12-02T11:16:06+00:00",config:{},result:"12-02-2016"},{description:"works for type datetime with timestamp in US mode",type:"datetime",value:1e7,config:{},result:"17:46 04-26-1970"},{description:"works for type datetime with iso date in US mode",type:"datetime",value:"2016-12-02T11:16:06+00:00",config:{},result:"11:16 12-02-2016"},{description:"works for type time with timestamp in US mode",type:"time",value:1e7,config:{},result:"17:46"},{description:"works for type time with iso date in US mode",type:"time",value:"2016-12-02T11:16:06+00:00",config:{},result:"11:16"}];describe("tests for formatValue in US Mode",()=>{using(t,(function(e){it(e.description,()=>{o.USmode=1,o.initialize();const t=o.formatValue(e.type,e.value,e.config);expect(t).toBe(e.result)})}))});const r=[{description:"works for command alpha with numeric value",command:"alpha",value:"1234",config:{},result:""},{description:"works for command alpha with string value",command:"alpha",value:"abc",config:{},result:"abc"},{description:"works for command alpha with alphanum input",command:"alpha",value:"abc123",config:{},result:"abc"},{description:"works for command alpha with alphanum input",command:"alpha",value:"123abc123",config:{},result:"abc"}];describe("test for processValue",()=>{using(r,(function(e){it(e.description,()=>{const t=o.processValue(e.command,e.value,e.config);expect(t).toBe(e.result)})}))}),xdescribe("tests for validateField",()=>{}),describe("tests for trimExplode",()=>{it("works for comma as separator and list without spaces",()=>{expect(o.trimExplode(",","foo,bar,baz")).toEqual(["foo","bar","baz"])}),it("works for comma as separator and list with spaces",()=>{expect(o.trimExplode(","," foo , bar , baz ")).toEqual(["foo","bar","baz"])}),it("works for pipe as separator and list with spaces",()=>{expect(o.trimExplode("|"," foo | bar | baz ")).toEqual(["foo","bar","baz"])})}),describe("tests for parseInt",()=>{it("works for value 0",()=>{expect(o.parseInt(0)).toBe(0)}),it("works for value 1",()=>{expect(o.parseInt(1)).toBe(1)}),it("works for value -1",()=>{expect(o.parseInt(-1)).toBe(-1)}),it('works for value "0"',()=>{expect(o.parseInt("0")).toBe(0)}),it('works for value "1"',()=>{expect(o.parseInt("1")).toBe(1)}),it('works for value "-1"',()=>{expect(o.parseInt("-1")).toBe(-1)}),it("works for value 0.5",()=>{expect(o.parseInt(.5)).toBe(0)}),it('works for value "0.5"',()=>{expect(o.parseInt("0.5")).toBe(0)}),it('works for value "foo"',()=>{expect(o.parseInt("foo")).toBe(0)}),it("works for value true",()=>{expect(o.parseInt(!0)).toBe(0)}),it("works for value false",()=>{expect(o.parseInt(!1)).toBe(0)}),it("works for value null",()=>{expect(o.parseInt(null)).toBe(0)})}),describe("tests for parseDouble",()=>{it("works for value 0",()=>{expect(o.parseDouble(0)).toBe("0.00")}),it("works for value 1",()=>{expect(o.parseDouble(1)).toBe("1.00")}),it("works for value -1",()=>{expect(o.parseDouble(-1)).toBe("-1.00")}),it('works for value "0"',()=>{expect(o.parseDouble("0")).toBe("0.00")}),it('works for value "1"',()=>{expect(o.parseDouble("1")).toBe("1.00")}),it('works for value "-1"',()=>{expect(o.parseDouble("-1")).toBe("-1.00")}),it("works for value 0.5",()=>{expect(o.parseDouble(.5)).toBe("0.50")}),it('works for value "0.5"',()=>{expect(o.parseDouble("0.5")).toBe("0.50")}),it('works for value "foo"',()=>{expect(o.parseDouble("foo")).toBe("0.00")}),it("works for value true",()=>{expect(o.parseDouble(!0)).toBe("0.00")}),it("works for value false",()=>{expect(o.parseDouble(!1)).toBe("0.00")}),it("works for value null",()=>{expect(o.parseDouble(null)).toBe("0.00")})}),describe("tests for btrim",()=>{const e=o.btrim(" test ");it("works for string with whitespace in begin and end",()=>{expect(e).toBe(" test")})}),describe("tests for ltrim",()=>{const e=o.ltrim(" test ");it("works for string with whitespace in begin and end",()=>{expect(e).toBe("test ")})}),xdescribe("tests for parseDateTime",()=>{}),xdescribe("tests for parseDate",()=>{}),xdescribe("tests for parseTime",()=>{}),xdescribe("tests for parseYear",()=>{}),describe("tests for getYear",()=>{const e=new Date;afterEach(()=>{jasmine.clock().mockDate(e)}),it("works for current date",()=>{const e=new Date;expect(o.getYear(e)).toBe(e.getFullYear())}),it("works for year 2013",()=>{const e=new Date(2013,9,23);jasmine.clock().mockDate(e),expect(o.getYear(e)).toBe(2013)})}),describe("tests for getDate",()=>{const e=new Date;afterEach(()=>{jasmine.clock().mockDate(e)}),xit("works for year 2013",()=>{const e=new Date(2013,9,23,13,13,13);jasmine.clock().mockDate(e),expect(o.getDate(e)).toBe(1382479200)})}),describe("tests for splitStr",()=>{it("works for command and index",()=>{expect(o.splitStr("foo,bar,baz",",",-1)).toBe("foo"),expect(o.splitStr("foo,bar,baz",",",0)).toBe("foo"),expect(o.splitStr("foo,bar,baz",",",1)).toBe("foo"),expect(o.splitStr("foo,bar,baz",",",2)).toBe("bar"),expect(o.splitStr("foo,bar,baz",",",3)).toBe("baz"),expect(o.splitStr(" foo , bar , baz ",",",1)).toBe(" foo "),expect(o.splitStr(" foo , bar , baz ",",",2)).toBe(" bar "),expect(o.splitStr(" foo , bar , baz ",",",3)).toBe(" baz ")})}),xdescribe("tests for split",()=>{})})})); \ No newline at end of file diff --git a/typo3/sysext/backend/Tests/JavaScript/IconsTest.js b/typo3/sysext/backend/Tests/JavaScript/IconsTest.js index b198d160eef9..692b7144b0bd 100644 --- a/typo3/sysext/backend/Tests/JavaScript/IconsTest.js +++ b/typo3/sysext/backend/Tests/JavaScript/IconsTest.js @@ -1,64 +1,13 @@ -define(['jquery', 'TYPO3/CMS/Backend/Icons'], function($, Icons) { - 'use strict'; - - describe('TYPO3/CMS/Backend/IconsTest:', function() { - /** - * @test - */ - describe('tests for Icons object', function() { - it('has all sizes', function() { - expect(Icons.sizes.small).toBe('small'); - expect(Icons.sizes.default).toBe('default'); - expect(Icons.sizes.large).toBe('large'); - expect(Icons.sizes.overlay).toBe('overlay'); - }); - it('has all states', function() { - expect(Icons.states.default).toBe('default'); - expect(Icons.states.disabled).toBe('disabled'); - }); - it('has all markupIdentifiers', function() { - expect(Icons.markupIdentifiers.default).toBe('default'); - expect(Icons.markupIdentifiers.inline).toBe('inline'); - }); - }); - - /** - * @test - */ - describe('tests for Icons::getIcon', function() { - beforeEach(function() { - spyOn(Icons, 'getIcon'); - Icons.getIcon('test', Icons.sizes.small, null, Icons.states.default, Icons.markupIdentifiers.default); - }); - - it("tracks that the spy was called", function() { - expect(Icons.getIcon).toHaveBeenCalled(); - }); - it("tracks all the arguments of its calls", function() { - expect(Icons.getIcon).toHaveBeenCalledWith('test', Icons.sizes.small, null, Icons.states.default, Icons.markupIdentifiers.default); - }); - xit('works get icon from remote server'); - }); - - /** - * @test - */ - describe('tests for Icons::putInCache', function() { - it('works for simply identifier and markup', function() { - Icons.putInPromiseCache('foo', 'bar'); - expect(Icons.promiseCache['foo']).toBe('bar'); - expect(Icons.isPromiseCached('foo')).toBe(true); - }); - }); - - /** - * @test - */ - describe('tests for Icons::getFromPromiseCache', function() { - it('return undefined for uncached promise', function() { - expect(Icons.getFromPromiseCache('bar')).not.toBeDefined(); - expect(Icons.isPromiseCached('bar')).toBe(false); - }); - }); - }); -}); +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ +define(["require","exports","TYPO3/CMS/Backend/Icons"],(function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),describe("TYPO3/CMS/Backend/IconsTest:",()=>{describe("tests for Icons object",()=>{it("has all sizes",()=>{expect(s.sizes.small).toBe("small"),expect(s.sizes.default).toBe("default"),expect(s.sizes.large).toBe("large"),expect(s.sizes.overlay).toBe("overlay")}),it("has all states",()=>{expect(s.states.default).toBe("default"),expect(s.states.disabled).toBe("disabled")}),it("has all markupIdentifiers",()=>{expect(s.markupIdentifiers.default).toBe("default"),expect(s.markupIdentifiers.inline).toBe("inline")})}),describe("tests for Icons::getIcon",()=>{beforeEach(()=>{spyOn(s,"getIcon"),s.getIcon("test",s.sizes.small,null,s.states.default,s.markupIdentifiers.default)}),it("tracks that the spy was called",()=>{expect(s.getIcon).toHaveBeenCalled()}),it("tracks all the arguments of its calls",()=>{expect(s.getIcon).toHaveBeenCalledWith("test",s.sizes.small,null,s.states.default,s.markupIdentifiers.default)}),xit("works get icon from remote server")}),describe("tests for Icons::putInCache",()=>{it("works for simply identifier and markup",()=>{const e=new Promise(e=>e());s.putInPromiseCache("foo",e),expect(s.getFromPromiseCache("foo")).toBe(e),expect(s.isPromiseCached("foo")).toBe(!0)})}),describe("tests for Icons::getFromPromiseCache",()=>{it("return undefined for uncached promise",()=>{expect(s.getFromPromiseCache("bar")).not.toBeDefined(),expect(s.isPromiseCached("bar")).toBe(!1)})})})})); \ No newline at end of file diff --git a/typo3/sysext/backend/Tests/JavaScript/PopoverTest.js b/typo3/sysext/backend/Tests/JavaScript/PopoverTest.js index 7b472248a306..0122cd4e6b85 100644 --- a/typo3/sysext/backend/Tests/JavaScript/PopoverTest.js +++ b/typo3/sysext/backend/Tests/JavaScript/PopoverTest.js @@ -1,77 +1,13 @@ -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-bs-toggle="popover">'); - $body.append($element); - it('works with default selector', function() { - Popover.initialize(); - expect($element[0].outerHTML).toBe('<div data-bs-toggle="popover" data-bs-original-title="" title=""></div>'); - }); - - var $element2 = $('<div data-bs-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-bs-toggle="popover" data-title="foo" data-bs-original-title="" title=""></div>'); - }); - - var $element3 = $('<div data-bs-toggle="popover" data-bs-content="foo">'); - $body.append($element3); - it('works with default selector and content attribute', function() { - Popover.initialize(); - expect($element3[0].outerHTML).toBe('<div data-bs-toggle="popover" data-bs-content="foo" data-bs-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-bs-original-title="" title=""></div>'); - }); - }); - - describe('call setOptions', function() { - var $body = $('body'); - var $element = $('<div class="t3js-test-set-options" data-title="foo-title" data-bs-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-bs-content')).toBe('foo-content'); - expect($element.attr('data-bs-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-bs-content')).toBe('foo-content'); - expect($element.attr('data-bs-original-title')).toBe('bar-title'); - expect($element.attr('title')).toBe(''); - }); - var $element2 = $('<div class="t3js-test-set-options2" data-title="foo-title" data-bs-content="foo-content">'); - $body.append($element2); - it('can set content', function() { - Popover.initialize('.t3js-test-set-options2'); - // Popover must be visible before the content can be updated manually via setOptions() - Popover.show($element2); - expect($element2.attr('data-title')).toBe('foo-title'); - expect($element2.attr('data-bs-content')).toBe('foo-content'); - expect($element2.attr('data-bs-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-bs-content')).toBe('bar-content'); - expect($element2.attr('data-bs-original-title')).toBe('foo-title'); - expect($element2.attr('title')).toBe(''); - }); - }); - }); -}); +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ +var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};define(["require","exports","jquery","TYPO3/CMS/Backend/Popover"],(function(t,e,o,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),o=__importDefault(o),describe("TYPO3/CMS/Backend/PopoverTest:",()=>{describe("initialize",()=>{const t=o.default("body"),e=o.default('<div data-bs-toggle="popover">');t.append(e),it("works with default selector",()=>{a.initialize(),expect(e[0].outerHTML).toBe('<div data-bs-toggle="popover" data-bs-original-title="" title=""></div>')});const i=o.default('<div data-bs-toggle="popover" data-title="foo">');t.append(i),it("works with default selector and title attribute",()=>{a.initialize(),expect(i[0].outerHTML).toBe('<div data-bs-toggle="popover" data-title="foo" data-bs-original-title="" title=""></div>')});const l=o.default('<div data-bs-toggle="popover" data-bs-content="foo">');t.append(l),it("works with default selector and content attribute",()=>{a.initialize(),expect(l[0].outerHTML).toBe('<div data-bs-toggle="popover" data-bs-content="foo" data-bs-original-title="" title=""></div>')});const s=o.default('<div class="t3js-popover">');t.append(s),it("works with custom selector",()=>{a.initialize(".t3js-popover"),expect(s[0].outerHTML).toBe('<div class="t3js-popover" data-bs-original-title="" title=""></div>')})}),describe("call setOptions",()=>{const t=o.default("body"),e=o.default('<div class="t3js-test-set-options" data-title="foo-title" data-bs-content="foo-content">');t.append(e),it("can set title",()=>{a.initialize(".t3js-test-set-options"),expect(e.attr("data-title")).toBe("foo-title"),expect(e.attr("data-bs-content")).toBe("foo-content"),expect(e.attr("data-bs-original-title")).toBe(""),expect(e.attr("title")).toBe(""),a.setOptions(e,{title:"bar-title"}),expect(e.attr("data-title")).toBe("foo-title"),expect(e.attr("data-bs-content")).toBe("foo-content"),expect(e.attr("data-bs-original-title")).toBe("bar-title"),expect(e.attr("title")).toBe("")});const i=o.default('<div class="t3js-test-set-options2" data-title="foo-title" data-bs-content="foo-content">');t.append(i),it("can set content",()=>{a.initialize(".t3js-test-set-options2"),a.show(i),expect(i.attr("data-title")).toBe("foo-title"),expect(i.attr("data-bs-content")).toBe("foo-content"),expect(i.attr("data-bs-original-title")).toBe(""),expect(i.attr("title")).toBe(""),a.setOptions(i,{content:"bar-content"}),expect(i.attr("data-title")).toBe("foo-title"),expect(i.attr("data-bs-content")).toBe("bar-content"),expect(i.attr("data-bs-original-title")).toBe("foo-title"),expect(i.attr("title")).toBe("")})})})})); \ No newline at end of file -- GitLab