mirror of
https://github.com/ONLYOFFICE/sdkjs.git
synced 2026-04-07 14:09:12 +08:00
For bug #51131
Add test that checks if the style update is working properly
This commit is contained in:
committed by
Ilya Kirillov
parent
a59c2eec34
commit
d4da3cec3c
@ -48,6 +48,7 @@ const allTests = [
|
||||
'word/api/api.html',
|
||||
'word/api/textInput.html',
|
||||
'word/styles/paraPr.html',
|
||||
'word/styles/styleApplicator.html',
|
||||
'word/plugins/pluginsApi.html',
|
||||
'word/merge-documents/mergeDocuments.html',
|
||||
|
||||
|
||||
36
tests/word/styles/styleApplicator.html
Normal file
36
tests/word/styles/styleApplicator.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>Document calculation tests</title>
|
||||
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||
<link type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/qunit/2.16.0/qunit.css" rel="stylesheet" media="screen" />
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/qunit/2.16.0/qunit.js"></script>
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xregexp/3.2.0/xregexp-all.min.js"></script>
|
||||
|
||||
|
||||
<script type="text/javascript" src="../../../develop/sdkjs/word/scripts.js"></script>
|
||||
<script type="text/javascript">
|
||||
window.sdk_scripts.forEach(function(item){
|
||||
document.write('<script type="text/javascript" src="' + item + '"><\/script>');
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="../common/common.js"></script>
|
||||
<script type="text/javascript" src="../common/editor.js"></script>
|
||||
<script type="text/javascript" src="../common/document.js"></script>
|
||||
<script type="text/javascript" src="../common/measurer.js"></script>
|
||||
|
||||
<script type="text/javascript" src="styleApplicator.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Style applicator</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup, will be hidden</div>
|
||||
</body>
|
||||
</html>
|
||||
127
tests/word/styles/styleApplicator.js
Normal file
127
tests/word/styles/styleApplicator.js
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
$(function () {
|
||||
|
||||
let logicDocument = AscTest.CreateLogicDocument();
|
||||
let styleManager = logicDocument.GetStyles();
|
||||
let numberingManager = logicDocument.GetNumbering();
|
||||
|
||||
function AddParagraph(style, text)
|
||||
{
|
||||
let p = AscTest.CreateParagraph();
|
||||
logicDocument.PushToContent(p);
|
||||
p.SetParagraphStyleById(style.GetId());
|
||||
|
||||
let run = new AscWord.CRun();
|
||||
p.AddToContent(0, run);
|
||||
run.AddText(text);
|
||||
return p;
|
||||
}
|
||||
|
||||
let styleCounter = 0;
|
||||
function CreateStyle()
|
||||
{
|
||||
let style = new AscWord.CStyle("style" + (++styleCounter), null, null, styletype_Paragraph);
|
||||
styleManager.Add(style);
|
||||
return style;
|
||||
}
|
||||
|
||||
function CreateNum()
|
||||
{
|
||||
let num = numberingManager.CreateNum();
|
||||
numberingManager.AddNum(num);
|
||||
let numLvl = num.GetLvl(0).Copy();
|
||||
|
||||
let paraPr = numLvl.GetParaPr();
|
||||
paraPr.Ind.Left = 15;
|
||||
paraPr.Ind.FirstLine = 5;
|
||||
numLvl.SetParaPr(paraPr);
|
||||
|
||||
num.SetLvl(numLvl, 0);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
QUnit.module("Style applicator");
|
||||
|
||||
QUnit.test("Style application and change from current selection", function (assert)
|
||||
{
|
||||
AscTest.ClearDocument();
|
||||
|
||||
let style = CreateStyle();
|
||||
p1 = AddParagraph(style, "First");
|
||||
p2 = AddParagraph(style, "Second");
|
||||
|
||||
let num = CreateNum();
|
||||
|
||||
function TestParagraph(p, left, right, first, align)
|
||||
{
|
||||
let compiledPr = p.GetCompiledParaPr(false);
|
||||
assert.strictEqual(compiledPr.Ind.Left, left, "Check Left indent");
|
||||
assert.strictEqual(compiledPr.Ind.Right, right, "Check Right indent");
|
||||
assert.strictEqual(compiledPr.Ind.FirstLine, first, "Check FirstLine");
|
||||
assert.strictEqual(compiledPr.Jc, align, "Check align");
|
||||
}
|
||||
|
||||
assert.ok(true, "Create empty style and set it to two paragraphs. Check default values");
|
||||
|
||||
TestParagraph(p1, 0, 0, 0, AscCommon.align_Left);
|
||||
TestParagraph(p2, 0, 0, 0, AscCommon.align_Left);
|
||||
|
||||
|
||||
assert.ok(true, "Apply direct properties and check values");
|
||||
p1.SetParagraphIndent({Left : 10, Right : 10, FirstLine : 20});
|
||||
p1.SetParagraphAlign(AscCommon.align_Center);
|
||||
|
||||
TestParagraph(p1, 10, 10, 20, AscCommon.align_Center);
|
||||
|
||||
assert.ok(true, "Apply direct numPr and check indents");
|
||||
p1.SetNumPr(num.GetId(), 0);
|
||||
p2.SetNumPr(num.GetId(), 0);
|
||||
|
||||
TestParagraph(p1, 10, 10, 20, AscCommon.align_Center);
|
||||
TestParagraph(p2, 15, 0, 5, AscCommon.align_Left);
|
||||
|
||||
// Обновление стиля в интерфейсе сейчас работает, как получение текущего по выделению, дальше ему проставляется точно такое же имя
|
||||
// и мы его заново выставляем в документ
|
||||
let uiStyle = logicDocument.GetStyleFromFormatting();
|
||||
uiStyle.put_Name(style.GetName());
|
||||
AscTest.MoveCursorToParagraph(p1, true);
|
||||
logicDocument.Add_NewStyle(uiStyle);
|
||||
|
||||
assert.ok(true, "Update style by paraPr of the first paragraph and check paragraph compiled properties after that");
|
||||
TestParagraph(p1, 10, 10, 20, AscCommon.align_Center);
|
||||
TestParagraph(p2, 10, 10, 20, AscCommon.align_Center);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user