Skip to content

Commit

Permalink
[8.1][CDE] Export/import to json check (#841)
Browse files Browse the repository at this point in the history
* Paragraph to json

* Run to json

* * Hyperlink to json
* Range to json

* * DocContent to json

* * Table to json

* [ref] ref api_hyperlink/to_json.js

* * Style to json

* [ref] DocContent to json

* [ref] DocContent. BlockLvlSdt & Table check

* ref: yardoc fix rule

* fix: unify static data for specs

* fix: ApiDocumentContent.ToJSON expected custom name

* [7.6.0][CDE] ApiRGBColor.ToJSON check (#997)

* feature: Fill.ToJSON (#1008)

* revert: TestData (#1009)

* [7.6.0][CDE] ApiUniColor.ToJSON check  (#1015)

* feature: ApiUniColor.ToJSON

* ref: ApiUniColor.ToJSON

* ref: ApiUniColor.ToJSON

* ref: ApiUniColor.ToJSON

* ref: ApiUniColor.ToJSON

* [7.6.0][CDE] ApiGradientStop.ToJSON check (#1014)

* feature: ApiGradientStop.ToJSON

* ApiGradientStop.ToJSON

* [7.6.0][CDE] ApiStroke.ToJSON check (#1010)

* feature: ApiStroke.ToJSON

* ref: ApiStroke.ToJSON

* feature: ApiStroke.ToJSON

* feature: ApiStroke.ToJSON

* ref: ApiStroke.ToJSON

* ref: ApiStroke.ToJSON

* ref: ApiStroke.ToJSON

* ref: ApiStroke.ToJSON

* ref: ApiStroke.ToJSON

* ref: ApiStroke.ToJSON

* ref: ApiStroke.ToJSON

* [8.0.0][CDE] Document.ToJSON

* [8.1][CDE] InlineLvlSdt.ToJSON

* fix: 66725

* fix: ApiTable.ToJSON

* [8.1][CDE] BlockLvlSdt.ToJSON()

* [8.1][CDE] TablePr.ToJSON()

* [8.1][CDE] TableRowPr.ToJSON()

* [8.1][CDE] TableCellPr.ToJSON()

* [8.1][CDE] TableStylePr.ToJSON()

* [8.1][CDE] TableCell.ToJSON()

* [8.1][CDE] TableRow.ToJSON()

* [8.1][CDE] Drawing.ToJSON()

* [8.1][CDE] SchemeColor.ToJSON()

* [8.1][CDE] ApiPresetColor.ToJSON()

* Revert "[8.1][CDE] BlockLvlSdt.ToJSON()"

This reverts commit 68db03d.

* [8.1][CDE] ApiParaPr.ToJSON()

* [8.1] remove doc-builder-static-data

* [8.1] skip renamed CDE style

* ref: default_styles order & doc_builder_testing require order

* info: coverage

---------

Co-authored-by: Yarosalv Maslov <[email protected]>
  • Loading branch information
askonev and Yar04ek authored Jun 18, 2024
1 parent bfbf79e commit d8b1b2a
Show file tree
Hide file tree
Showing 54 changed files with 1,124 additions and 108 deletions.
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-24 19:07:30 UTC using RuboCop version 1.57.1.
# on 2024-06-18 14:03:12 UTC using RuboCop version 1.64.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 16
Max: 21

# Offense count: 116
# Offense count: 130
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 21

# Offense count: 410
# Offense count: 411
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
61 changes: 61 additions & 0 deletions js/docx/smoke/api_document/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
builder.CreateFile("docx");
// oParagraph
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.AddText("paragraph");
oDocument.Push(oParagraph);

// oTable
var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered"));
var oTable = Api.CreateTable(3, 3);
oTable.SetWidth("percent", 100);
oTable.SetTableDescription("Empty table");
oTable.SetStyle(oTableStyle);
var oCell = oTable.GetCell(0, 0);
oCell.GetContent().GetElement(0).AddText(oTable.GetClassType());
oDocument.Push(oTable);

// oBlockLvlSdt
var oBlockLvlSdt = Api.CreateBlockLvlSdt();
oBlockLvlSdt.GetContent().GetElement(0).AddText(oBlockLvlSdt.GetClassType());
oParagraph = Api.CreateParagraph();
oParagraph.AddText("This is a block text content control.");
oBlockLvlSdt.Push(oParagraph);
oDocument.Push(oBlockLvlSdt)

var bWriteDefaultTextPr = false
// Specifies if the default text properties will be written to the JSON object or not.
var bWriteDefaultParaPr = false
// Specifies if the default paragraph properties will be written to the JSON object or not.
var bWriteTheme = false
// Specifies if the document theme will be written to the JSON object or not.
var bWriteSectionPr = false
// Specifies if the document section properties will be written to the JSON object or not.
var bWriteNumberings = false
// Specifies if the document numberings will be written to the JSON object or not.
var bWriteStyles = false
// Specifies if the document styles will be written to the JSON object or not.

var json = oDocument.ToJSON(bWriteDefaultTextPr,
bWriteDefaultParaPr,
bWriteTheme,
bWriteSectionPr,
bWriteNumberings,
bWriteStyles);

GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["JSON"];
var oDocumentFromJSON = Api.FromJSON(json);
var oDocument = Api.GetDocument();
oDocument.GetElement(0).AddText(json);
oDocument.Push(oDocumentFromJSON[1]);
oDocument.Push(oDocumentFromJSON[2]);
oDocument.Push(oDocumentFromJSON[4]);
builder.SaveFile("docx", "DocumentToJSON.docx");
builder.CloseFile();
46 changes: 46 additions & 0 deletions js/docx/smoke/api_document_content/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oFill = Api.CreateSolidFill(Api.CreateRGBColor(104, 155, 104));
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oDrawing = Api.CreateShape("rect", 3212465, 963295, oFill, oStroke);
oParagraph.AddDrawing(oDrawing);
var oDocContent = oDrawing.GetDocContent();
// Add Hyperlink
oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('Hyperlink');
var oRange = oParagraph.GetRange(0, 8);
oRange.AddHyperlink('https://api.onlyoffice.com')
// Add BlockLvlSdt
var oBlockLvlSdt = Api.CreateBlockLvlSdt();
oBlockLvlSdt.AddText('oBlockLvlSdt');
oDocContent.Push(oBlockLvlSdt);
// Add Table
var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered - Accent 5"));
var oTable = Api.CreateTable(3, 3);
var oCell = oTable.GetCell(0, 0);
oCell.GetContent().GetElement(0).AddText("Cell #1");
oTable.SetWidth("percent", 100);
oTable.SetStyle(oTableStyle);
oDocContent.Push(oTable);
var json = oDocContent.ToJSON(true, true);
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["JSON"]
var oDocContentFromJSON = Api.FromJSON(json);
var oDocument = Api.GetDocument();
var arrElements = []
for( var i = 0; i < oDocContentFromJSON.GetElementsCount(); i++) {
arrElements.push(oDocContentFromJSON.GetElement(i));
}
oDocument.InsertContent(arrElements)
var oParagraph = Api.CreateParagraph();
oParagraph.AddText(json);
oDocument.Push(oParagraph);
builder.SaveFile("docx", "DocContentToJSON.docx");
builder.CloseFile();
25 changes: 25 additions & 0 deletions js/docx/smoke/api_drawing/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 224, 204), 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 164, 101), 100000);
var oFill = Api.CreateLinearGradientFill([oGs1, oGs2], 5400000);
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oDrawing = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke);
var json = oDrawing.ToJSON(true, true);
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["JSON"]
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText(json);
oDocument.Push(oParagraph);
var oDrawingFromJSON = Api.FromJSON(json)
oParagraph = Api.CreateParagraph();
oParagraph.AddDrawing(oDrawingFromJSON);
oDocument.Push(oParagraph);
builder.SaveFile("docx", "ToJSON.docx");
builder.CloseFile();
29 changes: 29 additions & 0 deletions js/docx/smoke/api_fill/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
builder.CreateFile("docx");
let oDocument = Api.GetDocument();
let oParagraph = oDocument.GetElement(0);
let oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 0);
let oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 213, 191), 100000);
let oFill = Api.CreateRadialGradientFill([oGs1, oGs2]);
let jsonFill = oFill.ToJSON();
oParagraph.AddText(jsonFill);
GlobalVariable["JSON_Fill"] = jsonFill;
builder.CloseFile();

//////////////////////

builder.CreateFile("docx");
let oDocument = Api.GetDocument();
let oParagraph = oDocument.GetElement(0);
let jsonFill = GlobalVariable["JSON_Fill"];
let oFill = Api.FromJSON(jsonFill);
oParagraph.AddText(jsonFill);
oDocument.Push(oParagraph);
let oParagraph2 = Api.CreateParagraph();
let oStroke = Api.CreateStroke(0, Api.CreateNoFill());
let oDrawing = Api.CreateShape("rect", 1908000, 1404000, oFill, oStroke);
oDrawing.Fill(oFill);
let jsonDrawing = oDrawing.ToJSON(false, true);
oParagraph2.AddText(jsonDrawing);
oDocument.Push(oParagraph2);
builder.SaveFile("docx", "FillToJson.docx");
builder.CloseFile();
28 changes: 28 additions & 0 deletions js/docx/smoke/api_gradient_stop/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
builder.CreateFile("docx");
var oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 213, 191), 100000);
GlobalVariable["json"] = {
start: oGs1.ToJSON(),
stop: oGs2.ToJSON()
};
builder.CloseFile();

//////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["json"];
var oDocument = Api.GetDocument();
for (var [key, value] of Object.entries(json)) {
var oPar = Api.CreateParagraph();
oPar.AddText(value);
oDocument.Push(oPar)
}
var oPar1 = oDocument.GetElement(0);
var oFill = Api.CreateRadialGradientFill([Api.FromJSON(json.start), Api.FromJSON(json.stop)]);
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oDrawing = Api.CreateShape("rect", 1908000, 1404000, oFill, oStroke);
oPar1.AddDrawing(oDrawing);
oPar1.AddLineBreak();
oPar1.AddText(oDrawing.ToJSON(bWriteNumberings = false, bWriteStyles = false))
builder.SaveFile("docx", "GradientStopToJSON.docx");
builder.CloseFile();
24 changes: 24 additions & 0 deletions js/docx/smoke/api_hyperlink/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oHyperlink = Api.CreateHyperlink("https://api.onlyoffice.com/", "ONLYOFFICE Document Builder", "ONLYOFFICE for developers");
oParagraph.Push(oHyperlink)
let json = oHyperlink.ToJSON(true);
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var json = GlobalVariable["JSON"]
var oHyperlinkFromJSON = Api.FromJSON(json);
oHyperlinkFromJSON.SetDefaultStyle();
oParagraph.AddElement(oHyperlinkFromJSON);

var oParagraph1 = Api.CreateParagraph();
oDocument.Push(oParagraph1);
oParagraph1.AddText(json);
builder.SaveFile("docx", "RunToJSON.docx");
builder.CloseFile();
25 changes: 25 additions & 0 deletions js/docx/smoke/api_inline_lvl_sdt/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oInlineLvlSdt = Api.CreateInlineLvlSdt();
oInlineLvlSdt.SetAlias("№1");
oInlineLvlSdt.AddText(oInlineLvlSdt.GetClassType());
oParagraph.AddInlineLvlSdt(oInlineLvlSdt);
var json = oInlineLvlSdt.ToJSON(true);

GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["JSON"];
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oInlineLvlSdtFromJSON = Api.FromJSON(json);
oParagraph.AddInlineLvlSdt(oInlineLvlSdtFromJSON);
oParagraph = Api.CreateParagraph();
oParagraph.AddText(json)
oDocument.Push(oParagraph)
builder.SaveFile("docx", "ToJSON.docx");
builder.CloseFile();
15 changes: 15 additions & 0 deletions js/docx/smoke/api_para_pr/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oMyStyle = oDocument.CreateStyle("My document style");
var oParaPr = oMyStyle.GetParaPr();
oParaPr.SetLeftBorder("single", 24, 0, 0, 255, 0);
var json = oParaPr.ToJSON(true);
var oParaPrFromJSON = Api.FromJSON(json);
var sType = oParaPrFromJSON.GetClassType();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText(sType);
oParagraph = Api.CreateParagraph();
oParagraph.AddText(json);
oDocument.Push(oParagraph);
builder.SaveFile("docx", "ToJSON.docx");
builder.CloseFile();
19 changes: 19 additions & 0 deletions js/docx/smoke/api_paragraph/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText("This is a paragraph");
var json = oParagraph.ToJSON(true, true);
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var json = GlobalVariable["JSON"]
oParagraph.AddText(json);
var oParagraphFromJSON = Api.FromJSON(json);
oDocument.Push(oParagraphFromJSON);
builder.SaveFile("docx", "ParagraphToJSON.docx");
builder.CloseFile();
31 changes: 31 additions & 0 deletions js/docx/smoke/api_preset_color/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oPresetColor = Api.CreatePresetColor("peachPuff");
var json = oPresetColor.ToJSON();
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["JSON"]
var oDocument = Api.GetDocument();
var oPresetColorFromJSON = Api.FromJSON(json);
var oParagraph = oDocument.GetElement(0);
var sClassType = oPresetColorFromJSON.GetClassType();
oParagraph.AddText(sClassType);
oDocument.Push(oParagraph)
oParagraph = Api.CreateParagraph();
oParagraph.AddText(json);
oDocument.Push(oParagraph)
var oGs1 = Api.CreateGradientStop(oPresetColorFromJSON, 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 100000);
var oFill = Api.CreateRadialGradientFill([oGs1, oGs2]);
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oDrawing = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke);
oParagraph = Api.CreateParagraph();
oParagraph.AddDrawing(oDrawing);
oDocument.Push(oParagraph);
builder.SaveFile("docx", "ToJSON.docx");
builder.CloseFile();
20 changes: 20 additions & 0 deletions js/docx/smoke/api_range/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText("ONLYOFFICE Document Builder");
var oRange = Api.CreateRange(oParagraph, 0, 10);
var json = oRange.ToJSON(true, true);
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var json = GlobalVariable["JSON"]
var oRangeFromJSON = Api.FromJSON(json);
oDocument.Push(oRangeFromJSON[0]);
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText(json);
builder.SaveFile("docx", "ParagraphToJSON.docx");
builder.CloseFile();
29 changes: 29 additions & 0 deletions js/docx/smoke/api_rgb_color/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
builder.CreateFile("docx");
let oDocument = Api.GetDocument();
let oParagraph = oDocument.GetElement(0);
let oRGBColor = Api.CreateRGBColor(255, 111, 61);
let jsonRGBColor = oRGBColor.ToJSON();
oParagraph.AddText(jsonRGBColor);
GlobalVariable["JSON_RGBColor"] = jsonRGBColor;
builder.CloseFile();

/////////////////////

builder.CreateFile("docx");
let oDocument = Api.GetDocument();
let oParagraph1 = oDocument.GetElement(0);
let jsonRGBColor = GlobalVariable["JSON_RGBColor"];
let oRGBColor = Api.FromJSON(jsonRGBColor);
oParagraph1.AddText(jsonRGBColor);
oDocument.Push(oParagraph1);
let oParagraph2 = Api.CreateParagraph();
let oGs1 = Api.CreateGradientStop(oRGBColor, 0);
let oGs2 = Api.CreateGradientStop(255, 213, 191, 100000);
let oFill = Api.CreateLinearGradientFill([oGs1, oGs2], 5400000);
let oStroke = Api.CreateStroke(0, Api.CreateNoFill());
let oDrawing = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke);
let jsonDrawing = oDrawing.ToJSON(false, true);
oParagraph2.AddText(jsonDrawing);
oDocument.Push(oParagraph2);
builder.SaveFile("docx", "RGBCoolorToJson.docx");
builder.CloseFile();
Loading

0 comments on commit d8b1b2a

Please sign in to comment.