[de] Add RemoveSelection and AddText to api

This commit is contained in:
KirillovIlya
2022-08-18 16:14:22 +03:00
parent 4dc773a332
commit 75219b2b1f
6 changed files with 135 additions and 1 deletions

View File

@ -31,6 +31,7 @@ jobs:
node-qunit-puppeteer tests/word/document-calculation/paragraph.html
node-qunit-puppeteer tests/word/forms/forms.html
node-qunit-puppeteer tests/word/forms/complexForm.html
node-qunit-puppeteer tests/word/api/api.html
builder-tests:
runs-on: ubuntu-latest
steps:

View File

@ -39,7 +39,8 @@ const allTests = [
'word/unit-tests/paragraphContentPos.html',
'word/document-calculation/paragraph.html',
'word/forms/forms.html',
'word/forms/complexForm.html'
'word/forms/complexForm.html',
'word/api/api.html'
];
const {performance} = require('perf_hooks');

35
tests/word/api/api.html Normal file
View File

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Api test</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="api.js"></script>
</head>
<body>
<h1 id="qunit-header">Test the api of the document editor</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>

71
tests/word/api/api.js Normal file
View File

@ -0,0 +1,71 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* 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-12 Ernesta Birznieka-Upisha
* 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();
QUnit.module("Test api for the document editor");
QUnit.test("Test AddText/RemoveSelection", function (assert)
{
AscTest.ClearDocument();
let p = new AscWord.CParagraph(AscTest.DrawingDocument);
logicDocument.AddToContent(0, p);
logicDocument.SelectAll();
assert.strictEqual(logicDocument.GetSelectedText(), "", "Check empty selection");
logicDocument.AddText("Hello World!");
logicDocument.SelectAll();
assert.strictEqual(logicDocument.GetSelectedText(false, {NewLineParagraph : true}), "Hello World!\r\n", "Add text 'Hello World!'");
let p2 = new AscWord.CParagraph(AscTest.DrawingDocument);
logicDocument.AddToContent(1, p2);
logicDocument.RemoveSelection();
p2.SetThisElementCurrent();
p2.MoveCursorToStartPos();
logicDocument.AddText("Second paragraph");
logicDocument.SelectAll();
assert.strictEqual(logicDocument.GetSelectedText(false, {NewLineParagraph : true}), "Hello World!\r\nSecond paragraph\r\n", "Add text to the second paragraph");
logicDocument.AddText("Test");
logicDocument.SelectAll();
assert.strictEqual(logicDocument.GetSelectedText(false, {NewLineParagraph : true}), "Test\r\n", "Replace all with adding text 'Test'");
});
});

View File

@ -132,6 +132,13 @@
logicDocument.RecalculateFromStart(false);
}
function ClearDocument()
{
if (!logicDocument)
return;
logicDocument.RemoveFromContent(0, logicDocument.GetElementsCount(), false);
}
//--------------------------------------------------------export----------------------------------------------------
AscTest.CreateLogicDocument = CreateLogicDocument;
AscTest.SetFillingFormMode = SetFillingFormMode;
@ -141,6 +148,7 @@
AscTest.MoveCursorRight = MoveCursorRight;
AscTest.Recalculate = Recalculate;
AscTest.ClickMouseButton = ClickMouseButton;
AscTest.ClearDocument = ClearDocument;
AscTest.KeyCode = KeyCode;
})(window);

View File

@ -11511,6 +11511,22 @@ background-repeat: no-repeat;\
return oLogicDocument.GetFirstLetterAutoCorrectExceptions();
};
asc_docs_api.prototype.asc_RemoveSelection = function()
{
let oLogicDocument = this.private_GetLogicDocument();
if (!oLogicDocument)
return "";
return oLogicDocument.RemoveSelection();
};
asc_docs_api.prototype.asc_AddText = function(sText)
{
let oLogicDocument = this.private_GetLogicDocument();
if (!oLogicDocument)
return "";
return oLogicDocument.AddText(sText);
};
asc_docs_api.prototype.asc_GetCurrentWord = function(nDirection)
{
var oLogicDocument = this.private_GetLogicDocument();
@ -13313,6 +13329,8 @@ background-repeat: no-repeat;\
asc_docs_api.prototype['asc_SetFirstLetterAutoCorrectExceptions'] = asc_docs_api.prototype.asc_SetFirstLetterAutoCorrectExceptions;
asc_docs_api.prototype['asc_GetFirstLetterAutoCorrectExceptions'] = asc_docs_api.prototype.asc_GetFirstLetterAutoCorrectExceptions;
asc_docs_api.prototype['asc_RemoveSelection'] = asc_docs_api.prototype.asc_RemoveSelection;
asc_docs_api.prototype['asc_AddText'] = asc_docs_api.prototype.asc_AddText;
asc_docs_api.prototype['asc_GetCurrentWord'] = asc_docs_api.prototype.asc_GetCurrentWord;
asc_docs_api.prototype['asc_ReplaceCurrentWord'] = asc_docs_api.prototype.asc_ReplaceCurrentWord;
asc_docs_api.prototype['asc_GetSelectedText'] = asc_docs_api.prototype.asc_GetSelectedText;