budoux
Version:
A small chunk segmenter.
66 lines • 3.31 kB
JavaScript
;
/**
* @license
* Copyright 2021 Google LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
require("../webcomponents/budoux-ja.js");
(0, vitest_1.describe)('Web Components', () => {
(0, vitest_1.beforeAll)(async () => {
await window.customElements.whenDefined('budoux-ja');
});
(0, vitest_1.beforeEach)(() => {
window.document.body.innerText = '';
});
(0, vitest_1.it)('should process the provided text.', () => {
const budouxElement = window.document.createElement('budoux-ja');
budouxElement.textContent = '今日は良い天気です。';
window.document.body.appendChild(budouxElement);
(0, vitest_1.expect)(budouxElement.innerHTML).toBe('今日は\u200B良い\u200B天気です。');
});
(0, vitest_1.it)('should react to text content changes after attached.', () => new Promise(resolve => {
const budouxElement = window.document.createElement('budoux-ja');
budouxElement.textContent = '今日は良い天気です。';
window.document.body.appendChild(budouxElement);
const observer = new window.MutationObserver(() => {
(0, vitest_1.expect)(budouxElement.innerHTML).toBe('明日は\u200B晴れるかな?');
resolve();
});
observer.observe(budouxElement, {
childList: true,
});
budouxElement.textContent = '明日は晴れるかな?';
}));
(0, vitest_1.it)('should work with HTML inputs.', () => {
const budouxElement = window.document.createElement('budoux-ja');
budouxElement.appendChild(window.document.createTextNode('昨日は'));
const b = window.document.createElement('b');
b.textContent = '雨';
budouxElement.appendChild(b);
budouxElement.appendChild(window.document.createTextNode('でした。'));
window.document.body.appendChild(budouxElement);
(0, vitest_1.expect)(budouxElement.innerHTML).toBe('昨日は<b>\u200B雨</b>でした。');
});
(0, vitest_1.it)('should have wrapping styles to control line breaks.', () => {
var _a, _b;
const budouxElement = window.document.createElement('budoux-ja');
budouxElement.textContent = 'Hello world';
window.document.body.appendChild(budouxElement);
const styles = budouxElement.computedStyleMap();
(0, vitest_1.expect)((_a = styles.get('word-break')) === null || _a === void 0 ? void 0 : _a.toString()).toBe('keep-all');
(0, vitest_1.expect)((_b = styles.get('overflow-wrap')) === null || _b === void 0 ? void 0 : _b.toString()).toBe('anywhere');
});
});
//# sourceMappingURL=test_webcomponents.js.map