Skip to content

Commit

Permalink
For bug #61936
Browse files Browse the repository at this point in the history
Add test to check floating position of a drawing in some cases in different compatibility modes
  • Loading branch information
KirillovIlya committed Jun 6, 2023
1 parent c818c2d commit 764da5b
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
node-qunit-puppeteer tests/word/unit-tests/paragraphContentPos.html
node-qunit-puppeteer tests/word/content-control/block-level/cursorAndSelection.html
node-qunit-puppeteer tests/word/content-control/inline-level/cursorAndSelection.html
node-qunit-puppeteer tests/word/document-calculation/floating-position/drawing.html
node-qunit-puppeteer tests/word/document-calculation/paragraph.html
node-qunit-puppeteer tests/word/document-calculation/table/correctBadTable.html
node-qunit-puppeteer tests/word/document-calculation/table/flowTablePosition.html
Expand Down
1 change: 1 addition & 0 deletions tests/runAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const allTests = [
'word/unit-tests/paragraphContentPos.html',
'word/content-control/block-level/cursorAndSelection.html',
'word/content-control/inline-level/cursorAndSelection.html',
'word/document-calculation/floating-position/drawing.html',
'word/document-calculation/paragraph.html',
'word/document-calculation/table/correctBadTable.html',
'word/document-calculation/table/flowTablePosition.html',
Expand Down
21 changes: 21 additions & 0 deletions tests/word/common/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@
{
return new AscWord.CTable(AscTest.DrawingDocument, null, true, rows, cols);
}
function CreateImage(w, h)
{
if (!logicDocument)
return null;

let drawingObjects = logicDocument.GetDrawingObjects();
let drawing = new ParaDrawing(w, h, null, drawingObjects, logicDocument, null);
let image = drawingObjects.createImage(AscCommon.g_sWordPlaceholderImage, 0, 0, w, h);
image.setParent(drawing);
drawing.Set_GraphicObject(image);
return drawing;
}
function GetParagraphText(paragraph)
{
return paragraph.GetText({ParaEndToSpace : false});
Expand Down Expand Up @@ -328,10 +340,18 @@

return logicDocument.SectPr;
}
function SetCompatibilityMode(mode)
{
if (!logicDocument)
return;

logicDocument.Settings.CompatibilityMode = mode;
}
//--------------------------------------------------------export----------------------------------------------------
AscTest.CreateLogicDocument = CreateLogicDocument;
AscTest.CreateParagraph = CreateParagraph;
AscTest.CreateTable = CreateTable;
AscTest.CreateImage = CreateImage;
AscTest.GetParagraphText = GetParagraphText;
AscTest.RemoveTableBorders = RemoveTableBorders;
AscTest.SetFillingFormMode = SetFillingFormMode;
Expand All @@ -356,6 +376,7 @@
AscTest.SetParagraphNumberingLvl = SetParagraphNumberingLvl;
AscTest.SelectDocumentRange = SelectDocumentRange;
AscTest.GetFinalSection = GetFinalSection;
AscTest.SetCompatibilityMode = SetCompatibilityMode;

})(window);

36 changes: 36 additions & 0 deletions tests/word/document-calculation/floating-position/drawing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

<title>Test the positioning of floating drawings</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="drawing.js"></script>
</head>
<body>
<h1 id="qunit-header">Test the positioning of floating drawings</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>
125 changes: 125 additions & 0 deletions tests/word/document-calculation/floating-position/drawing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* (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-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
*
*/

"use strict";

$(function ()
{
const logicDocument = AscTest.CreateLogicDocument();

function SetupDocumentSection()
{
AscTest.ClearDocument();
let sectPr = AscTest.GetFinalSection();
sectPr.SetPageSize(500, 1000);
sectPr.SetPageMargins(50, 50, 50, 50);
}
SetupDocumentSection();

function CreateImageInParagraph(p, w, h)
{
let d = AscTest.CreateImage(w, h);
let run = new AscWord.CRun();
p.AddToContent(0, run);
run.AddToContent(0, d);
return d;
}

function AddTextToParagraph(p, text)
{
let run = new AscWord.CRun();
p.AddToContentToEnd(run);
run.AddText(text);
}

QUnit.module("Test the positioning of floating drawings");

QUnit.test("Test bugs #50253 #61936", function (assert)
{
let p1 = AscTest.CreateParagraph();
let p2 = AscTest.CreateParagraph();

p1.SetParagraphSpacing({Before : 0, After : 0, LineRule : linerule_Auto, Line : 1});

let d1 = CreateImageInParagraph(p1, 50, 50);
let d2 = CreateImageInParagraph(p2, 50, 50);

AscTest.ClearDocument();
logicDocument.PushToContent(p1);
logicDocument.PushToContent(p2);

assert.strictEqual(logicDocument.GetElementsCount(), 2, "Should be 2 paragraphs in the document");

d1.Set_DrawingType(drawing_Anchor);
d1.Set_Distance(10, 10, 10, 10);
d1.Set_WrappingType(WRAPPING_TYPE_SQUARE);
d1.Set_PositionH(Asc.c_oAscRelativeFromH.Page, false, 40);
d1.Set_PositionV(Asc.c_oAscRelativeFromV.Page, false, 40);

d2.Set_DrawingType(drawing_Anchor);
d2.Set_PositionH(Asc.c_oAscRelativeFromH.Column, false, 0);
d2.Set_PositionV(Asc.c_oAscRelativeFromV.Paragraph, false, 0);
d2.Set_WrappingType(WRAPPING_TYPE_NONE);
d2.Set_BehindDoc(false);

function CheckPositions()
{
AscTest.SetCompatibilityMode(AscCommon.document_compatibility_mode_Word14);
AscTest.Recalculate();
assert.ok(true, "Set compatibility mode equal to 14 (Word2010)");
assert.strictEqual(d1.X, 40, "Check drawing1.x");
assert.strictEqual(d1.Y, 40, "Check drawing1.y");
assert.strictEqual(d2.X, 100, "Check drawing2.x");
assert.strictEqual(d2.Y, 50 + AscTest.FontHeight, "Check drawing2.y");

AscTest.SetCompatibilityMode(AscCommon.document_compatibility_mode_Word15);
AscTest.Recalculate();
assert.ok(true, "Set compatibility mode equal to 15 (Word2013-2019)");
assert.strictEqual(d1.X, 40, "Check drawing1.x");
assert.strictEqual(d1.Y, 40, "Check drawing1.y");
assert.strictEqual(d2.X, 50, "Check drawing2.x");
assert.strictEqual(d2.Y, 50 + AscTest.FontHeight, "Check drawing2.y");
}

assert.ok(true, "Both paragraphs have no text");
CheckPositions();

AddTextToParagraph(p1, "First");
AddTextToParagraph(p2, "Second");

assert.ok(true, "Fill in paragraphs with text");
CheckPositions();

AscTest.SetCompatibilityMode(AscCommon.document_compatibility_mode_Current);
});

});

0 comments on commit 764da5b

Please sign in to comment.