本文整理汇总了TypeScript中@ephox/bedrock.UnitTest.test方法的典型用法代码示例。如果您正苦于以下问题:TypeScript UnitTest.test方法的具体用法?TypeScript UnitTest.test怎么用?TypeScript UnitTest.test使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ephox/bedrock.UnitTest
的用法示例。
在下文中一共展示了UnitTest.test方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
import { Assertions } from '@ephox/agar';
import Editor from 'tinymce/core/Editor';
import EditorManager from 'tinymce/core/EditorManager';
import Settings from 'tinymce/plugins/toc/api/Settings';
import { UnitTest } from '@ephox/bedrock';
UnitTest.test('browser.tinymce.plugins.toc.api.SettingsTest', function () {
Assertions.assertEq('Should be default toc class', 'mce-toc', Settings.getTocClass(new Editor('x', {}, EditorManager)));
Assertions.assertEq('Should be specified toc class', 'c', Settings.getTocClass(new Editor('x', { toc_class: 'c' }, EditorManager)));
Assertions.assertEq('Should be default h2', 'h2', Settings.getTocHeader(new Editor('x', {}, EditorManager)));
Assertions.assertEq('Should be h3', 'h3', Settings.getTocHeader(new Editor('x', { toc_header: 'h3' }, EditorManager)));
Assertions.assertEq('Should be h2 since h75 is invalid', 'h2', Settings.getTocHeader(new Editor('x', { toc_header: 'h75' }, EditorManager)));
Assertions.assertEq('Should be default 3', 3, Settings.getTocDepth(new Editor('x', {}, EditorManager)));
Assertions.assertEq('Should be specified toc depth (string)', 5, Settings.getTocDepth(new Editor('x', { toc_depth: '5' }, EditorManager)));
Assertions.assertEq('Should be specified toc depth', 5, Settings.getTocDepth(new Editor('x', { toc_depth: 5 }, EditorManager)));
Assertions.assertEq('Should be default toc depth for invalid', 3, Settings.getTocDepth(new Editor('x', { toc_depth: '53' }, EditorManager)));
});
示例2: function
import { Assertions } from '@ephox/agar';
import Features from 'tinymce/themes/mobile/features/Features';
import { UnitTest } from '@ephox/bedrock';
UnitTest.test('features.IdentifyToolbarTest', function () {
const check = function (label, expected, input) {
const actual = Features.identify(input);
Assertions.assertEq(label, expected, actual);
};
check('Default toolbar', [ 'undo', 'bold', 'italic', 'link', 'image', 'bullist', 'styleselect' ], { });
check('Empty toolbar', [ ], { toolbar: '' });
check('Empty toolbar (array)', [ ], { toolbar: [ ] });
check('Flat toolbar', [ 'undo', 'bold' ], { toolbar: 'undo bold' });
check('Flat toolbar (array)', [ 'undo', 'bold' ], { toolbar: [ 'undo', 'bold' ] });
check('Nested toolbar (array)', [ 'undo', 'bold', 'italic' ], { toolbar: [ [ 'undo' ], [ 'bold', 'italic' ] ] });
check('Mixed toolbar (array)', [ 'undo', 'bold', 'redo', 'italic' ], { toolbar: [ [ 'undo' ], [ ], [ 'bold redo', 'italic' ] ] });
check('Toolbar with pipes', [ 'undo', 'bold', 'italic', 'bullist', 'styleselect' ], { toolbar: [ [ 'undo | bold | italic' ], [ 'bullist styleselect' ] ] });
check('Unknown identifiers', [
'undo', 'redo', 'styleselect', 'bold', 'italic', 'alignleft', 'aligncenter', 'alignright', 'alignjustify',
'bullist', 'numlist', 'outdent', 'indent', 'link', 'image'
], { toolbar: 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image' });
});
示例3: function
import { RawAssertions } from '@ephox/agar';
import Data from 'tinymce/plugins/visualchars/core/Data';
import { UnitTest } from '@ephox/bedrock';
UnitTest.test('atomic.tinymce.plugins.visualchars.DataTest', function () {
RawAssertions.assertEq(
'should return correst selector',
'span.mce-a,span.mce-b',
Data.charMapToSelector({ a: 'a', b: 'b' })
);
RawAssertions.assertEq(
'should return correct regexp',
'/[ab]/',
Data.charMapToRegExp({ a: 'a', b: 'b' }).toString()
);
RawAssertions.assertEq(
'should return correct global regexp',
'/[ab]/g',
Data.charMapToRegExp({ a: 'a', b: 'b' }, true).toString()
);
});
示例4: function
import Arr from 'tinymce/themes/inlite/alien/Arr';
import { UnitTest, assert } from '@ephox/bedrock';
UnitTest.test('atomic.themes.alien.ArrTest', function () {
const testFlatten = function () {
assert.eq(Arr.flatten([1, 2, [3, 4, [5, 6]], [7, 8], 9]), [1, 2, 3, 4, 5, 6, 7, 8, 9]);
};
testFlatten();
});
示例5: function
UnitTest.test('atomic.tinymce.plugins.textpattern.FindPatternTest', function () {
const defaultPatterns = Settings.getPatterns({});
const testFindEndPattern = function (text, offset, space, expectedPattern) {
const actual = Patterns.findEndPattern(defaultPatterns, text, offset, space ? 1 : 0);
RawAssertions.assertEq('Assert correct pattern', expectedPattern, actual.end);
};
const testFindStartPattern = function (text, expectedPattern) {
const actual = Patterns.findPattern(defaultPatterns, text);
RawAssertions.assertEq('Assert correct pattern', expectedPattern, actual.start);
};
const testFindStartPatternUndefined = function (text) {
const actual = Patterns.findPattern(defaultPatterns, text);
RawAssertions.assertEq('Assert correct pattern', undefined, actual);
};
testFindEndPattern('y **x** ', 8, true, '**');
testFindEndPattern('y **x**', 7, false, '**');
testFindEndPattern('y *x* ', 6, true, '*');
testFindEndPattern('y *x*', 5, false, '*');
testFindStartPattern('*x*', '*');
testFindStartPattern('**x**', '**');
testFindStartPattern('***x***', '***');
testFindStartPatternUndefined('*x* ');
testFindStartPattern('#x', '#');
testFindStartPattern('##x', '##');
testFindStartPattern('###x', '###');
testFindStartPattern('####x', '####');
testFindStartPattern('#####x', '#####');
testFindStartPattern('######x', '######');
testFindStartPattern('1. x', '1. ');
testFindStartPattern('* x', '* ');
testFindStartPattern('- x', '- ');
});
示例6: value
import { RawAssertions } from '@ephox/agar';
import { UnitTest } from '@ephox/bedrock';
import { Fun } from '@ephox/katamari';
import Predicate from 'tinymce/core/util/Predicate';
UnitTest.test('atomic.tinymce.core.util.PredicateTest', () => {
const isAbove = function (target, value) {
return value() > target();
};
const isAbove5 = Fun.curry(isAbove, Fun.constant(5));
const isAbove10 = Fun.curry(isAbove, Fun.constant(10));
RawAssertions.assertEq('Should be extected and result', false, Predicate.and(isAbove10, isAbove5)(Fun.constant(10)));
RawAssertions.assertEq('Should be extected and result', true, Predicate.and(isAbove10, isAbove5)(Fun.constant(30)));
RawAssertions.assertEq('Should be extected or result', false, Predicate.or(isAbove10, isAbove5)(Fun.constant(5)));
RawAssertions.assertEq('Should be extected or result', true, Predicate.or(isAbove10, isAbove5)(Fun.constant(15)));
RawAssertions.assertEq('Should be extected or result', true, Predicate.or(isAbove5, isAbove10)(Fun.constant(15)));
});
示例7: converter
UnitTest.test('SizeInputConverterTest', () => {
const check = (converter: SizeConversion) => (expected: Option<Size>, input: Size) => {
const result = converter(input);
expected.fold(() => {
assert.eq(true, result.isNone(), 'Expected none');
}, (size) => {
result.fold(() => {
assert.fail('Expected size');
}, (resultSize) => {
assert.eq(size, resultSize);
});
});
};
const checkRatio2 = check(ratioSizeConversion(2, 'in'));
checkRatio2(Option.some(nuSize(1, 'in')), nuSize(0.5, 'in'));
checkRatio2(Option.some(nuSize(1, 'in')), nuSize(48, 'px'));
checkRatio2(Option.some(nuSize(1, 'in')), nuSize(6, 'pc'));
checkRatio2(Option.some(nuSize(1, 'in')), nuSize(36, 'pt'));
checkRatio2(Option.some(nuSize(2, 'in')), nuSize(2.54, 'cm'));
checkRatio2(Option.some(nuSize(1, 'in')), nuSize(12.7, 'mm'));
const checkRatio3 = check(ratioSizeConversion(3, 'in'));
checkRatio3(Option.some(nuSize(1, 'in')), nuSize(32, 'px'));
checkRatio3(Option.some(nuSize(1, 'in')), nuSize(4, 'pc'));
checkRatio3(Option.some(nuSize(1, 'in')), nuSize(24, 'pt'));
checkRatio3(Option.some(nuSize(3, 'in')), nuSize(2.54, 'cm'));
checkRatio3(Option.some(nuSize(3, 'in')), nuSize(25.4, 'mm'));
Jsc.property(
'ratioSizeConversion is equalivent to multipling when the units match',
Jsc.nat(100), Jsc.nat(100), Jsc.oneof(Jsc.elements(units)),
function (scale: number, value: number, unit: SizeUnit) {
const v = ratioSizeConversion(scale, unit)({ value, unit }).getOrNull();
return Jsc.eq({ value: scale * value, unit }, v);
}
);
Jsc.property(
'noSizeConversion always returns none',
Jsc.number(0, largeSensible), Jsc.oneof(Jsc.elements(units)),
function (value: number, unit: SizeUnit) {
return Jsc.eq(true, noSizeConversion({ value, unit }).isNone());
}
);
const checkRatioConv2 = check(makeRatioConverter('96px', '2in'));
checkRatioConv2(Option.some(nuSize(1, 'in')), nuSize(0.5, 'in'));
checkRatioConv2(Option.some(nuSize(1, 'in')), nuSize(48, 'px'));
checkRatioConv2(Option.some(nuSize(1, 'in')), nuSize(6, 'pc'));
checkRatioConv2(Option.some(nuSize(1, 'in')), nuSize(36, 'pt'));
checkRatioConv2(Option.some(nuSize(2, 'in')), nuSize(2.54, 'cm'));
checkRatioConv2(Option.some(nuSize(1, 'in')), nuSize(12.7, 'mm'));
const checkNoRatio = check(makeRatioConverter('96px', '1em'));
checkNoRatio(Option.none(), nuSize(1, 'em'));
checkNoRatio(Option.none(), nuSize(50, 'px'));
checkNoRatio(Option.none(), nuSize(2, 'cm'));
});
示例8: function
UnitTest.test('features.FeatureDetectTest', function () {
/*
* Check that if the feature is not known, it skips over it
*
*/
const testFeature = function (name, supported) {
return {
isSupported: Fun.constant(supported),
sketch: Fun.constant(name)
};
};
const features = {
alpha: testFeature('alpha', true),
beta: testFeature('beta', false),
gamma: testFeature('gamma', true),
delta: testFeature('delta', true)
};
const check = function (label, expected, toolbar) {
const actual = Features.detect({ toolbar }, features);
Assertions.assertEq(label, expected, actual);
};
check('Empty toolbar', [ ], '');
check('Toolbar with everything', [ 'alpha', 'gamma', 'delta' ], [ 'alpha', 'beta', 'gamma', 'delta', 'epsilon' ]);
check('Toolbar with everything', [ 'alpha', 'gamma', 'delta' ], [ 'alpha', 'beta', 'alpha', 'gamma', 'delta', 'epsilon' ]);
});
示例9: normalizeEntries
UnitTest.test('ListModelTest', () => {
const arbitratyContent = Jsc.bless({
generator: Arbitraries.content('inline').generator.map((el) => [el])
});
const arbitraryEntry = Jsc.record({
isSelected: Jsc.constant(false),
depth: Jsc.integer(1, 10),
content: Jsc.small(arbitratyContent),
listType: Jsc.oneof(Jsc.constant(ListType.OL), Jsc.constant(ListType.UL)),
listAttributes: Jsc.oneof(Jsc.constant({}), Jsc.constant({style: 'list-style-type: lower-alpha;'})),
itemAttributes: Jsc.oneof(Jsc.constant({}), Jsc.constant({style: 'color: red;'})),
});
const arbitraryEntries = Jsc.array(arbitraryEntry);
const composeParseProperty = Jsc.forall(arbitraryEntries, (inputEntries: Entry[]) => {
normalizeEntries(inputEntries);
const outputEntries = composeParse(inputEntries);
return isEqualEntries(inputEntries, outputEntries) || errorMessage(inputEntries, outputEntries);
});
const composeParse = (entries: Entry[]): Entry[] => {
return composeList(document, entries)
.map((list) => parseLists([list], Option.none()))
.bind(Arr.head)
.map((entrySet) => entrySet.entries)
.getOr([]);
};
const isEqualEntries = (a: Entry[], b: Entry[]): boolean => {
return stringifyEntries(a) === stringifyEntries(b);
};
const errorMessage = (inputEntries: Entry[], outputEntries: Entry[]): string => {
return `\nPretty print counterexample:\n` +
`input: [${stringifyEntries(inputEntries)}\n]\n` +
`output: [${stringifyEntries(outputEntries)}\n]`;
};
const stringifyEntries = (entries: Entry[]): string => {
return Arr.map(entries, stringifyEntry).join(',');
};
const stringifyEntry = (entry: Entry): string => {
return `\n {
depth: ${entry.depth}
content: ${entry.content.length > 0 ? serializeElements(entry.content) : '[Empty]'}
listType: ${entry.listType}
isSelected: ${entry.isSelected}
listAttributes: ${JSON.stringify(entry.listAttributes)}
itemAttributes: ${JSON.stringify(entry.itemAttributes)}
}`;
};
const serializeElements = (elms: Element[]): string => {
return Arr.map(elms, (el) => el.dom().outerHTML).join('');
};
Jsc.assert(composeParseProperty, {
size: 500,
tests: 500,
quiet: true
});
// Manual testing. To simplify debugging once a counterexample has been found.
/* const inputEntries: Entry[] = [
{
depth: 2,
content: [Element.fromHtml('<i>stuff</i>')],
listType: ListType.OL,
isSelected: false,
listAttributes: {style: 'list-style-type: lower-alpha;'},
itemAttributes: {}
}
];
throw composeParse(inputEntries); */
});
示例10: function
UnitTest.test('atomic.core.HtmlToDataTest', function () {
const testHtmlToData = function (html, expected) {
const actual = HtmlToData.htmlToData([], html);
RawAssertions.assertEq('Assert equal', expected, actual);
};
testHtmlToData('<div data-ephox-embed-iri="a"></div>', {
type: 'ephox-embed-iri',
source1: 'a',
source2: '',
poster: '',
width: '',
height: ''
});
testHtmlToData('<div data-ephox-embed-iri="a" style="max-width: 300px; max-height: 200px"></div>', {
type: 'ephox-embed-iri',
source1: 'a',
source2: '',
poster: '',
width: '300',
height: '200'
});
testHtmlToData('<iframe src="//www.youtube.com/embed/b3XFjWInBog" width="560" height="314" allowFullscreen="1"></iframe>', {
src: '//www.youtube.com/embed/b3XFjWInBog',
width: '560',
height: '314',
allowfullscreen: '1',
type: 'iframe',
source1: '//www.youtube.com/embed/b3XFjWInBog',
source2: '',
poster: ''
});
});