From d8b1b2a3363a77357d236d0410296522f3b44ef8 Mon Sep 17 00:00:00 2001 From: Sorokin Maksim <60688343+askonev@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:26:33 +0300 Subject: [PATCH] [8.1][CDE] Export/import to json check (#841) * 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 68db03d04f369b075bd07f0db688943e45bbfa5f. * [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 <148754748+Yar04ek@users.noreply.github.com> --- .rubocop_todo.yml | 10 +- js/docx/smoke/api_document/to_json.js | 61 ++++ js/docx/smoke/api_document_content/to_json.js | 46 ++++ js/docx/smoke/api_drawing/to_json.js | 25 ++ js/docx/smoke/api_fill/to_json.js | 29 ++ js/docx/smoke/api_gradient_stop/to_json.js | 28 ++ js/docx/smoke/api_hyperlink/to_json.js | 24 ++ js/docx/smoke/api_inline_lvl_sdt/to_json.js | 25 ++ js/docx/smoke/api_para_pr/to_json.js | 15 + js/docx/smoke/api_paragraph/to_json.js | 19 ++ js/docx/smoke/api_preset_color/to_json.js | 31 +++ js/docx/smoke/api_range/to_json.js | 20 ++ js/docx/smoke/api_rgb_color/to_json.js | 29 ++ js/docx/smoke/api_run/to_json.js | 22 ++ js/docx/smoke/api_scheme_color/to_json.js | 27 ++ js/docx/smoke/api_stroke/to_json.js | 40 +++ js/docx/smoke/api_style/to_json.js | 50 ++++ js/docx/smoke/api_table/to_json.js | 25 ++ js/docx/smoke/api_table_cell/to_json.js | 36 +++ js/docx/smoke/api_table_cell_pr/to_json.js | 20 ++ js/docx/smoke/api_table_pr/to_json.js | 15 + js/docx/smoke/api_table_row/to_json.js | 20 ++ js/docx/smoke/api_table_row_pr/to_json.js | 20 ++ js/docx/smoke/api_table_style_pr/to_json.js | 19 ++ js/docx/smoke/api_uni_color/to_json.js | 25 ++ lib/doc_builder_testing.rb | 3 +- reports/coverage_result.json | 260 +++++++++++------- spec/docx/smoke/api_document_content_spec.rb | 12 + spec/docx/smoke/api_document_spec.rb | 9 + spec/docx/smoke/api_drawing_spec.rb | 6 + spec/docx/smoke/api_fill_spec.rb | 13 + spec/docx/smoke/api_gradient_stop_spec.rb | 13 + .../smoke/api_hyperlink/api_hyperlink_spec.rb | 15 + spec/docx/smoke/api_inline_lvl_sdt_spec.rb | 13 + .../smoke/api_paragraph_properties_spec.rb | 8 + spec/docx/smoke/api_paragraph_spec.rb | 8 + spec/docx/smoke/api_preset_color_spec.rb | 7 + spec/docx/smoke/api_range/api_range_spec.rb | 12 + spec/docx/smoke/api_rgb_color_spec.rb | 9 + spec/docx/smoke/api_run_spec.rb | 9 + spec/docx/smoke/api_scheme_color_spec.rb | 7 + spec/docx/smoke/api_stroke_spec.rb | 9 + spec/docx/smoke/api_style_spec.rb | 16 ++ .../smoke/api_table_cell_properties_spec.rb | 15 + spec/docx/smoke/api_table_cell_spec.rb | 19 ++ spec/docx/smoke/api_table_properties_spec.rb | 6 + .../smoke/api_table_row_properties_spec.rb | 7 + spec/docx/smoke/api_table_row_spec.rb | 7 + spec/docx/smoke/api_table_spec.rb | 8 + spec/docx/smoke/api_table_style_pr_spec.rb | 6 + spec/docx/smoke/api_uni_color_spec.rb | 10 + spec/spec_helper.rb | 3 +- spec/test_data.rb | 37 +++ spec/xlsx/smoke/api_range_spec.rb | 4 - 54 files changed, 1124 insertions(+), 108 deletions(-) create mode 100644 js/docx/smoke/api_document/to_json.js create mode 100644 js/docx/smoke/api_document_content/to_json.js create mode 100644 js/docx/smoke/api_drawing/to_json.js create mode 100644 js/docx/smoke/api_fill/to_json.js create mode 100644 js/docx/smoke/api_gradient_stop/to_json.js create mode 100644 js/docx/smoke/api_hyperlink/to_json.js create mode 100644 js/docx/smoke/api_inline_lvl_sdt/to_json.js create mode 100644 js/docx/smoke/api_para_pr/to_json.js create mode 100644 js/docx/smoke/api_paragraph/to_json.js create mode 100644 js/docx/smoke/api_preset_color/to_json.js create mode 100644 js/docx/smoke/api_range/to_json.js create mode 100644 js/docx/smoke/api_rgb_color/to_json.js create mode 100644 js/docx/smoke/api_run/to_json.js create mode 100644 js/docx/smoke/api_scheme_color/to_json.js create mode 100644 js/docx/smoke/api_stroke/to_json.js create mode 100644 js/docx/smoke/api_style/to_json.js create mode 100644 js/docx/smoke/api_table/to_json.js create mode 100644 js/docx/smoke/api_table_cell/to_json.js create mode 100644 js/docx/smoke/api_table_cell_pr/to_json.js create mode 100644 js/docx/smoke/api_table_pr/to_json.js create mode 100644 js/docx/smoke/api_table_row/to_json.js create mode 100644 js/docx/smoke/api_table_row_pr/to_json.js create mode 100644 js/docx/smoke/api_table_style_pr/to_json.js create mode 100644 js/docx/smoke/api_uni_color/to_json.js create mode 100644 spec/docx/smoke/api_hyperlink/api_hyperlink_spec.rb create mode 100644 spec/docx/smoke/api_inline_lvl_sdt_spec.rb create mode 100644 spec/docx/smoke/api_range/api_range_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 56d4d64d..791761cc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 diff --git a/js/docx/smoke/api_document/to_json.js b/js/docx/smoke/api_document/to_json.js new file mode 100644 index 00000000..958244a4 --- /dev/null +++ b/js/docx/smoke/api_document/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_document_content/to_json.js b/js/docx/smoke/api_document_content/to_json.js new file mode 100644 index 00000000..ff9b2e76 --- /dev/null +++ b/js/docx/smoke/api_document_content/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_drawing/to_json.js b/js/docx/smoke/api_drawing/to_json.js new file mode 100644 index 00000000..f9966419 --- /dev/null +++ b/js/docx/smoke/api_drawing/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_fill/to_json.js b/js/docx/smoke/api_fill/to_json.js new file mode 100644 index 00000000..4fda3f63 --- /dev/null +++ b/js/docx/smoke/api_fill/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_gradient_stop/to_json.js b/js/docx/smoke/api_gradient_stop/to_json.js new file mode 100644 index 00000000..616ad00b --- /dev/null +++ b/js/docx/smoke/api_gradient_stop/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_hyperlink/to_json.js b/js/docx/smoke/api_hyperlink/to_json.js new file mode 100644 index 00000000..0fad1f10 --- /dev/null +++ b/js/docx/smoke/api_hyperlink/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_inline_lvl_sdt/to_json.js b/js/docx/smoke/api_inline_lvl_sdt/to_json.js new file mode 100644 index 00000000..6024493e --- /dev/null +++ b/js/docx/smoke/api_inline_lvl_sdt/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_para_pr/to_json.js b/js/docx/smoke/api_para_pr/to_json.js new file mode 100644 index 00000000..4ceb2e32 --- /dev/null +++ b/js/docx/smoke/api_para_pr/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_paragraph/to_json.js b/js/docx/smoke/api_paragraph/to_json.js new file mode 100644 index 00000000..76695af3 --- /dev/null +++ b/js/docx/smoke/api_paragraph/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_preset_color/to_json.js b/js/docx/smoke/api_preset_color/to_json.js new file mode 100644 index 00000000..652b6560 --- /dev/null +++ b/js/docx/smoke/api_preset_color/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_range/to_json.js b/js/docx/smoke/api_range/to_json.js new file mode 100644 index 00000000..418430f1 --- /dev/null +++ b/js/docx/smoke/api_range/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js new file mode 100644 index 00000000..84095a9c --- /dev/null +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_run/to_json.js b/js/docx/smoke/api_run/to_json.js new file mode 100644 index 00000000..790fcb92 --- /dev/null +++ b/js/docx/smoke/api_run/to_json.js @@ -0,0 +1,22 @@ +builder.CreateFile("docx"); +var oDocument = Api.GetDocument(); +var oParagraph = oDocument.GetElement(0); +var oRun = Api.CreateRun(); +oRun.AddText("This is a text run"); +var json = oRun.ToJSON(true); +GlobalVariable["JSON"] = json; +builder.CloseFile(); + +//////////////////////// + +builder.CreateFile("docx"); +var oDocument = Api.GetDocument(); +var oParagraph = oDocument.GetElement(0); +var json = GlobalVariable["JSON"] +var oRunFromJSON = Api.FromJSON(json); +oParagraph.AddElement(oRunFromJSON); +var oParagraph1 = Api.CreateParagraph(); +oDocument.Push(oParagraph1) +oParagraph1.AddText(json); +builder.SaveFile("docx", "RunToJSON.docx"); +builder.CloseFile(); diff --git a/js/docx/smoke/api_scheme_color/to_json.js b/js/docx/smoke/api_scheme_color/to_json.js new file mode 100644 index 00000000..44e5da92 --- /dev/null +++ b/js/docx/smoke/api_scheme_color/to_json.js @@ -0,0 +1,27 @@ +builder.CreateFile("docx"); + var oSchemeColor = Api.CreateSchemeColor("w"); + var json = oSchemeColor.ToJSON(); +GlobalVariable["JSON"] = json; +builder.CloseFile(); + +//////////////////////// + +builder.CreateFile("docx"); + var json = GlobalVariable["JSON"] + var oDocument = Api.GetDocument(); + var oSchemeColorFromJSON = Api.FromJSON(json); + var sClassType = oSchemeColorFromJSON.GetClassType(); + var oParagraph = oDocument.GetElement(0); + oParagraph.AddText(sClassType); + oDocument.Push(oParagraph) + oParagraph = Api.CreateParagraph(); + oParagraph.AddText(json); + oDocument.Push(oParagraph) + var oFill = Api.CreateSolidFill(oSchemeColorFromJSON); + var oStroke = Api.CreateStroke(0, Api.CreateNoFill()); + var oDrawing = Api.CreateShape("curvedUpArrow", 5930900, 595605, oFill, oStroke); + oParagraph = Api.CreateParagraph(); + oParagraph.AddDrawing(oDrawing); + oDocument.Push(oParagraph) +builder.SaveFile("docx", "ToJSON.docx"); +builder.CloseFile(); diff --git a/js/docx/smoke/api_stroke/to_json.js b/js/docx/smoke/api_stroke/to_json.js new file mode 100644 index 00000000..776cbc35 --- /dev/null +++ b/js/docx/smoke/api_stroke/to_json.js @@ -0,0 +1,40 @@ +builder.CreateFile("docx"); + var oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 213, 191), 0); + var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 100000); + var arr = [] + arr.push(Api.CreateBlipFill("https://api.onlyoffice.com/content/img/docbuilder/examples/icon_DocumentEditors.png", "tile")); + arr.push(Api.CreateSolidFill(Api.CreateRGBColor(102, 0, 204))) + arr.push(Api.CreateLinearGradientFill([oGs1, oGs2], 5400000)) + arr.push(Api.CreateNoFill()) + arr.push(Api.CreatePatternFill("cross", Api.CreateRGBColor(255, 111, 61), Api.CreateRGBColor(51, 51, 51))) + arr.push(Api.CreateRadialGradientFill([oGs1, oGs2])) + arr = arr.map((fill) => { + var oStroke = Api.CreateStroke(10 * 36000, fill); + return oStroke.ToJSON() + }) + GlobalVariable["arrStroke"] = arr; +builder.CloseFile(); + +////////////////////// + +builder.CreateFile("docx"); + var arrStroke = GlobalVariable["arrStroke"]; + arrStroke.forEach((stroke) => { + var odoc = Api.GetDocument(); + var opar = Api.CreateParagraph(); + opar.AddText(stroke) + odoc.Push(opar) + }) + arrStroke.forEach((stroke) => { + var oStroke = Api.FromJSON(stroke); + var odoc = Api.GetDocument(); + var opar = Api.CreateParagraph(); + var oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 213, 191), 0); + var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 100000); + var oFill = Api.CreateRadialGradientFill([oGs1, oGs2]); + var oDrawing = Api.CreateShape("star10", 10000 * 593, 10000 * 590, oFill, oStroke); + opar.AddDrawing(oDrawing); + odoc.Push(opar); + }); +builder.SaveFile("docx", "StrokeToJson.docx"); +builder.CloseFile(); diff --git a/js/docx/smoke/api_style/to_json.js b/js/docx/smoke/api_style/to_json.js new file mode 100644 index 00000000..aa181391 --- /dev/null +++ b/js/docx/smoke/api_style/to_json.js @@ -0,0 +1,50 @@ +builder.CreateFile("docx"); + var odoc = Api.GetDocument(); + let arr_def_styles = ["Normal", + "No Spacing", + "Heading 1", + "Heading 2", + "Heading 3", + "Heading 4", + "Heading 5", + "Heading 6", + "Heading 7", + "Heading 8", + "Heading 9", + "Title", + "Subtitle", + "Quote", + "Intense Quote", + "List Paragraph", + "Caption", + "Header", + "Footer", + "Footnote text", + "Endnote text"] + var result_json = {} + arr_def_styles.forEach(el => { + let st = odoc.GetStyle(el); + let json = st.ToJSON() + result_json[el] = json; + }); +GlobalVariable["JSON"] = JSON.stringify(result_json); +builder.CloseFile(); + +//////////////////////// + +builder.CreateFile("docx"); + var json = GlobalVariable["JSON"] + var obj_json = JSON.parse(json) + var odoc = Api.GetDocument(); + for(let k in obj_json){ + let st = Api.FromJSON(obj_json[k]); + let opar = Api.CreateParagraph(); + opar.AddText(st.GetName()) + opar.SetStyle(st); + odoc.Push(opar) + } + let opar = Api.CreateParagraph(); + opar.AddText(json); + odoc.Push(opar) +builder.SaveFile("docx", "StyleToJSON.docx"); +builder.CloseFile(); diff --git a/js/docx/smoke/api_table/to_json.js b/js/docx/smoke/api_table/to_json.js new file mode 100644 index 00000000..b1c86265 --- /dev/null +++ b/js/docx/smoke/api_table/to_json.js @@ -0,0 +1,25 @@ +builder.CreateFile("docx"); + var oDocument = Api.GetDocument(); + var TStyleName = "List Table 5 Dark" + // "Grid Table 1 Light" + // "List Table 1 Light" + // "Lined Accent" + // "Bordered - Accent 5" + var oTableStyle = oDocument.GetStyle(TStyleName); + var oTable = Api.CreateTable(3, 3); + oTable.SetStyle(oTableStyle); + var json = oTable.ToJSON(true, true); +GlobalVariable["JSON"] = json; +builder.CloseFile(); + +//////////////////////// + +builder.CreateFile("docx"); + var oDocument = Api.GetDocument(); + var oPar = oDocument.GetElement(0); + var json = GlobalVariable["JSON"] + oPar.AddText(json); + var oTableFromJSON = Api.FromJSON(json); + oDocument.Push(oTableFromJSON); +builder.SaveFile("docx", "TableToJSON.docx"); +builder.CloseFile(); diff --git a/js/docx/smoke/api_table_cell/to_json.js b/js/docx/smoke/api_table_cell/to_json.js new file mode 100644 index 00000000..5b9d2815 --- /dev/null +++ b/js/docx/smoke/api_table_cell/to_json.js @@ -0,0 +1,36 @@ +builder.CreateFile("docx"); + var oDocument = Api.GetDocument(); + var oTable = Api.CreateTable(3, 3); + var oCell = oTable.GetCell(0,0); + oCell.SetCellBorderBottom("single", 32, 0, 51, 51, 51) + oCell.SetCellBorderLeft("single", 32, 0, 51, 51, 51) + oCell.SetCellBorderRight("single", 32, 0, 51, 51, 51) + oCell.SetCellBorderTop("single", 32, 0, 51, 51, 51) + oCell.SetCellMarginBottom(720); + oCell.SetCellMarginLeft(720); + oCell.SetCellMarginRight(720); + oCell.SetCellMarginTop(720); + oCell.SetBackgroundColor(255, 111, 61, false); + oCell.SetShd("clear", 255, 111, 61, false); + oCell.SetTextDirection("btlr"); + oCell.SetWidth("twips", 2880); + oTable.SetWidth("percent", 100); + var json = oCell.ToJSON(); +GlobalVariable["JSON"] = json; +builder.CloseFile(); + +//////////////////////// + +builder.CreateFile("docx"); + var json = GlobalVariable["JSON"] + var oCellPr = Api.FromJSON(json); + var oDocument = Api.GetDocument(); + var oTable = Api.CreateTable(3, 3); + oTable.GetCell(0,0).SetCellPr(oCellPr) + oTable.SetWidth("percent", 100); + oDocument.Push(oTable); + var oParagraph = Api.CreateParagraph(); + oParagraph.AddText(json); + oDocument.Push(oParagraph); +builder.SaveFile("docx", "ToJSON.docx"); +builder.CloseFile(); diff --git a/js/docx/smoke/api_table_cell_pr/to_json.js b/js/docx/smoke/api_table_cell_pr/to_json.js new file mode 100644 index 00000000..93e775ed --- /dev/null +++ b/js/docx/smoke/api_table_cell_pr/to_json.js @@ -0,0 +1,20 @@ +builder.CreateFile("docx"); + var oDocument = Api.GetDocument(); + var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table"); + oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered")); + var oTable = Api.CreateTable(3, 3); + oTable.SetWidth("percent", 100); + var oTableCellPr = oTableStyle.GetTableCellPr(); + oTableCellPr.SetCellBorderBottom("single", 32, 0, 51, 51, 51); + oTable.SetStyle(oTableStyle); + oDocument.Push(oTable); + var json = oTableCellPr.ToJSON(); + var oTableCellPrFromJSON = Api.FromJSON(json); + var sType = oTableCellPrFromJSON.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(); diff --git a/js/docx/smoke/api_table_pr/to_json.js b/js/docx/smoke/api_table_pr/to_json.js new file mode 100644 index 00000000..43a304fa --- /dev/null +++ b/js/docx/smoke/api_table_pr/to_json.js @@ -0,0 +1,15 @@ +builder.CreateFile("docx"); + var oDocument = Api.GetDocument(); + var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table"); + oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered")); + var oTablePr = oTableStyle.GetTablePr(); + var json = oTablePr.ToJSON(); + var oTablePrFromJSON = Api.FromJSON(json); + var sType = oTablePrFromJSON.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(); diff --git a/js/docx/smoke/api_table_row/to_json.js b/js/docx/smoke/api_table_row/to_json.js new file mode 100644 index 00000000..a42568b7 --- /dev/null +++ b/js/docx/smoke/api_table_row/to_json.js @@ -0,0 +1,20 @@ +builder.CreateFile("docx"); + var oDocument = Api.GetDocument(); + var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table"); + oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered")); + var oTable = Api.CreateTable(4, 2); + oTable.SetWidth("percent", 100); + oTable.SetStyle(oTableStyle); + var oTableRow = oTable.GetRow(1); + var oParagraph = Api.CreateParagraph(); + oDocument.Push(oParagraph); + oParagraph.AddText(oTableRow.GetClassType()); + oTableRow.SetBackgroundColor(255, 111, 61, false); + oTableRow.SetHeight("atLeast", 720); + oDocument.Push(oTable); + var json = oTableRow.ToJSON(); + oParagraph = Api.CreateParagraph(); + oParagraph.AddText(json); + oDocument.Push(oParagraph); +builder.SaveFile("docx", "ToJSON.docx"); +builder.CloseFile(); diff --git a/js/docx/smoke/api_table_row_pr/to_json.js b/js/docx/smoke/api_table_row_pr/to_json.js new file mode 100644 index 00000000..56d6ec2a --- /dev/null +++ b/js/docx/smoke/api_table_row_pr/to_json.js @@ -0,0 +1,20 @@ +builder.CreateFile("docx"); + var oDocument = Api.GetDocument(); + var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table"); + oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered")); + var oTable = Api.CreateTable(3, 3); + oTable.SetWidth("percent", 100); + var oTableRowPr = oTableStyle.GetTableRowPr(); + oTableRowPr.SetHeight("atLeast", 720); + oTable.SetStyle(oTableStyle); + oDocument.Push(oTable); + var json = oTableRowPr.ToJSON(); + var oTableRowPrFromJSON = Api.FromJSON(json); + var sType = oTableRowPrFromJSON.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(); diff --git a/js/docx/smoke/api_table_style_pr/to_json.js b/js/docx/smoke/api_table_style_pr/to_json.js new file mode 100644 index 00000000..63255aa7 --- /dev/null +++ b/js/docx/smoke/api_table_style_pr/to_json.js @@ -0,0 +1,19 @@ +builder.CreateFile("docx"); + var oDocument = Api.GetDocument(); + var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table"); + oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered")); + var oTable = Api.CreateTable(3, 3); + oTable.SetWidth("percent", 100); + var oTableStylePr = oTableStyle.GetConditionalTableStyle(); + oTable.SetStyle(oTableStyle); + oDocument.Push(oTable); + var json = oTableStylePr.ToJSON(); + var oTableStylePrFromJSON = Api.FromJSON(json); + var sType = oTableStylePrFromJSON.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(); diff --git a/js/docx/smoke/api_uni_color/to_json.js b/js/docx/smoke/api_uni_color/to_json.js new file mode 100644 index 00000000..2e63279c --- /dev/null +++ b/js/docx/smoke/api_uni_color/to_json.js @@ -0,0 +1,25 @@ +builder.CreateFile("docx"); + let oDocument = Api.GetDocument(); + let oParagraph = oDocument.GetElement(0); + // RGBColor is an inheritor of UniColor class. + // It is impossible to use an instance of UniColor class directly + let oRGBColor = Api.CreateRGBColor(255, 111, 61); + let oFill = Api.CreateSolidFill(oRGBColor); + oParagraph.AddText(oFill.ToJSON()); + GlobalVariable["JSON_UniColor"] = oFill.ToJSON(); +builder.CloseFile(); + +///////////////////// + +builder.CreateFile("docx"); + let oDocument = Api.GetDocument(); + let oParagraph = oDocument.GetElement(0); + let jsonSolidFill = GlobalVariable["JSON_UniColor"]; + let oFillRestored = Api.FromJSON(jsonSolidFill); + let oStroke = Api.CreateStroke(0, Api.CreateNoFill()); + let oDrawing = Api.CreateShape("rect", 5930900, 395605, oFillRestored, oStroke); + let jsonDrawing = oDrawing.ToJSON(false, true); + oParagraph.AddText(jsonDrawing); + oDocument.Push(oParagraph); +builder.SaveFile("docx", "UnicolorToJson.docx"); +builder.CloseFile(); diff --git a/lib/doc_builder_testing.rb b/lib/doc_builder_testing.rb index a6b165d4..36402c8f 100644 --- a/lib/doc_builder_testing.rb +++ b/lib/doc_builder_testing.rb @@ -3,7 +3,6 @@ require 'ooxml_parser' require 'onlyoffice_pdf_parser' require 'tempfile' -require_relative 'doc_builder_testing/doc_builder_wrapper' require_relative 'doc_builder_testing/exceptions' +require_relative 'doc_builder_testing/doc_builder_wrapper' require_relative 'doc_builder_testing/web_doc_builder_wrapper' -require_relative '../spec/test_data' diff --git a/reports/coverage_result.json b/reports/coverage_result.json index e9486446..30c1926d 100644 --- a/reports/coverage_result.json +++ b/reports/coverage_result.json @@ -4,16 +4,10 @@ "AddComment", "attachEvent", "ConvertDocument", - "CreateBlockLvlSdt", - "CreateBullet", - "CreateHyperlink", - "CreateInlineLvlSdt", "CreateOleObject", - "CreateRange", "CreateTextPr", "CreateWordArt", "detachEvent", - "FromJSON", "GetFullName", "GetMailMergeReceptionsCount", "GetMailMergeTemplateDocContent", @@ -40,22 +34,15 @@ "GetParentTableCell", "GetPlaceholderText", "GetPosInParent", - "GetRange", "GetTag", "ReplaceByElement", "Search", "Select", - "SetAlias", - "SetBackgroundColor", "SetLabel", "SetLock", "SetPlaceholderText", "SetTag", - "SetTextPr", - "ToJSON" - ], - "ApiBullet": [ - + "SetTextPr" ], "ApiChart": [ "ApplyChartStyle", @@ -98,7 +85,6 @@ "IsFixed", "IsRadioButton", "IsRequired", - "SetBackgroundColor", "SetBorderColor", "SetChecked", "SetFormKey", @@ -123,7 +109,6 @@ "IsFixed", "IsRequired", "SelectListValue", - "SetBackgroundColor", "SetBorderColor", "SetFormKey", "SetListValues", @@ -135,6 +120,35 @@ "ToFixed", "ToInline" ], + "apicomment": [ + "AddReply", + "Delete", + "GetAuthorName", + "GetId", + "GetQuoteText", + "GetRepliesCount", + "GetReply", + "GetText", + "GetTime", + "GetTimeUTC", + "GetUserId", + "IsSolved", + "RemoveReplies", + "SetAuthorName", + "SetSolved", + "SetText", + "SetTime", + "SetTimeUTC", + "SetUserId" + ], + "apicommentreply": [ + "GetAuthorName", + "GetText", + "GetUserId", + "SetAuthorName", + "SetText", + "SetUserId" + ], "ApiComplexForm": [ "Clear", "Copy", @@ -145,7 +159,6 @@ "GetWrapperShape", "IsFixed", "IsRequired", - "SetBackgroundColor", "SetBorderColor", "SetFormKey", "SetPlaceholderText", @@ -178,6 +191,7 @@ "apidocument": [ "AcceptAllRevisionChanges", "AddComment", + "AddDrawingToPage", "AddEndnote", "AddFootnote", "AddTableOfContents", @@ -206,8 +220,8 @@ "GetEndNotesFirstParagraphs", "GetFootnotesFirstParagraphs", "GetFormsByTag", + "GetFormsData", "GetPageCount", - "GetRange", "GetRangeBySelect", "GetSections", "GetSelectedDrawings", @@ -226,11 +240,11 @@ "Search", "SearchAndReplace", "SetControlsHighlight", + "SetFormsData", "SetFormsHighlight", "SetTrackRevisions", "SetWatermarkSettings", "ToHtml", - "ToJSON", "ToMarkdown", "UpdateAllTOC", "UpdateAllTOF" @@ -241,11 +255,9 @@ "GetAllOleObjects", "GetAllParagraphs", "GetAllShapes", - "GetAllTables", - "GetRange", - "ToJSON" + "GetAllTables" ], - "ApiDrawing": [ + "apidrawing": [ "AddBreak", "Copy", "Delete", @@ -265,11 +277,10 @@ "SetHorFlip", "SetLockValue", "SetOutLine", - "SetVertFlip", - "ToJSON" + "SetVertFlip" ], "ApiFill": [ - "ToJSON" + ], "ApiFormBase": [ "Clear", @@ -281,7 +292,6 @@ "GetWrapperShape", "IsFixed", "IsRequired", - "SetBackgroundColor", "SetBorderColor", "SetFormKey", "SetPlaceholderText", @@ -292,18 +302,15 @@ "ToInline" ], "ApiGradientStop": [ - "ToJSON" + ], "ApiHyperlink": [ "GetDisplayedText", "GetLinkedText", - "GetRange", "GetScreenTipText", - "SetDefaultStyle", "SetDisplayedText", "SetLink", - "SetScreenTipText", - "ToJSON" + "SetScreenTipText" ], "ApiImage": [ "GetNextImage", @@ -322,19 +329,16 @@ "GetParentTable", "GetParentTableCell", "GetPlaceholderText", - "GetRange", "GetTag", "IsForm", - "SetAlias", "SetLabel", "SetLock", "SetPlaceholderText", "SetTag", - "SetTextPr", - "ToJSON" + "SetTextPr" ], "ApiNumbering": [ - "ToJSON" + ], "ApiNumberingLevel": [ @@ -353,8 +357,6 @@ "AddEndnoteCrossRef", "AddFootnoteCrossRef", "AddHeadingCrossRef", - "AddHyperlink", - "AddInlineLvlSdt", "AddNumberedCrossRef", "Copy", "Delete", @@ -375,7 +377,6 @@ "GetParentTableCell", "GetPosInParent", "GetPrevious", - "GetRange", "GetSection", "GetShd", "GetSpacingAfter", @@ -389,13 +390,11 @@ "ReplaceByElement", "Search", "Select", - "SetBullet", "SetSection", "SetTextPr", - "ToJSON", "WrapInMailMergeField" ], - "ApiParaPr": [ + "apiparapr": [ "GetIndFirstLine", "GetIndLeft", "GetIndRight", @@ -404,9 +403,7 @@ "GetSpacingAfter", "GetSpacingBefore", "GetSpacingLineRule", - "GetSpacingLineValue", - "SetBullet", - "ToJSON" + "GetSpacingLineValue" ], "ApiPictureForm": [ "Clear", @@ -423,7 +420,6 @@ "IsLockAspectRatio", "IsRequired", "IsRespectBorders", - "SetBackgroundColor", "SetBorderColor", "SetFormKey", "SetImage", @@ -439,52 +435,44 @@ "ToInline" ], "ApiPresetColor": [ - "ToJSON" + ], "ApiRange": [ "AddBookmark", "AddComment", - "AddHyperlink", "Delete", "ExpandTo", "GetAllParagraphs", "GetParagraph", - "GetRange", "GetText", "IntersectWith", "Select", - "SetTextPr", - "ToJSON" + "SetTextPr" ], "ApiRGBColor": [ - "ToJSON" + ], "apirun": [ "AddComment", - "AddHyperlink", "Copy", "Delete", "GetFontNames", "GetParentContentControl", "GetParentTable", "GetParentTableCell", - "GetRange", "GetText", "Select", - "SetFill", - "SetOutLine", - "SetTextFill", "SetTextPr", - "ToJSON", "WrapInMailMergeField" ], - "ApiSchemeColor": [ - "ToJSON" + "apischemecolor": [ + ], - "ApiSection": [ + "apisection": [ "GetNext", - "GetPrevious", - "ToJSON" + "GetPageHeight", + "GetPageWidth", + "GetPrevious" ], "ApiShape": [ "GetNextShape", @@ -492,10 +480,10 @@ "SetPaddings" ], "ApiStroke": [ - "ToJSON" + ], "ApiStyle": [ - "ToJSON" + ], "apitable": [ "AddCaption", @@ -511,7 +499,6 @@ "GetParentTableCell", "GetPosInParent", "GetPrevious", - "GetRange", "GetTableDescription", "GetTables", "GetTableTitle", @@ -519,15 +506,12 @@ "ReplaceByElement", "Search", "Select", - "SetBackgroundColor", "SetHAlign", "SetPaddings", - "SetTableDescription", "SetTableTitle", "SetTextPr", "SetVAlign", - "Split", - "ToJSON" + "Split" ], "ApiTableCell": [ "AddColumns", @@ -540,22 +524,17 @@ "GetPrevious", "GetRowIndex", "Search", - "SetBackgroundColor", - "SetCellPr", "SetColumnBackgroundColor", "SetTextPr", - "Split", - "ToJSON" + "Split" ], "ApiTableCellPr": [ - "ToJSON" + ], "ApiTablePr": [ "GetTableDescription", "GetTableTitle", - "SetTableDescription", - "SetTableTitle", - "ToJSON" + "SetTableTitle" ], "ApiTableRow": [ "AddRows", @@ -566,15 +545,13 @@ "GetPrevious", "Remove", "Search", - "SetBackgroundColor", - "SetTextPr", - "ToJSON" + "SetTextPr" ], "ApiTableRowPr": [ - "ToJSON" + ], "ApiTableStylePr": [ - "ToJSON" + ], "ApiTextForm": [ "Clear", @@ -591,7 +568,6 @@ "IsMultiline", "IsRequired", "SetAutoFit", - "SetBackgroundColor", "SetBorderColor", "SetCellWidth", "SetCharactersLimit", @@ -606,14 +582,11 @@ "ToFixed", "ToInline" ], - "ApiTextPr": [ - "SetFill", - "SetOutLine", - "SetTextFill", - "ToJSON" + "apitextpr": [ + ], "ApiUniColor": [ - "ToJSON" + ], "ApiUnsupported": [ @@ -635,13 +608,17 @@ }, "Spreadsheet API": { "api": [ + "AddComment", "AddDefName", "attachEvent", "CreateNewHistoryPoint", "CreateTextPr", "detachEvent", + "GetAllComments", + "GetCommentById", "GetComments", "GetDefName", + "GetFreezePanesType", "GetFullName", "GetLocale", "GetMailMergeData", @@ -649,6 +626,7 @@ "RecalculateAllFormulas", "ReplaceTextSmart", "Save", + "SetFreezePanesType", "SetLocale", "event-onworksheetchange" ], @@ -658,6 +636,15 @@ ], "ApiBullet": [ + ], + "apicharacters": [ + "GetCaption", + "GetFont", + "GetParent", + "GetText", + "Insert", + "SetCaption", + "SetText" ], "ApiChart": [ "AddSeria", @@ -696,8 +683,37 @@ "ApiColor": [ ], - "ApiComment": [ - "GetText" + "apicomment": [ + "AddReply", + "GetAuthorName", + "GetId", + "GetQuoteText", + "GetRepliesCount", + "GetReply", + "GetText", + "GetTime", + "GetTimeUTC", + "GetUserId", + "IsSolved", + "RemoveReplies", + "SetAuthorName", + "SetSolved", + "SetText", + "SetTime", + "SetTimeUTC", + "SetUserId" + ], + "apicommentreply": [ + "GetAuthorName", + "GetText", + "GetTime", + "GetTimeUTC", + "GetUserId", + "SetAuthorName", + "SetText", + "SetTime", + "SetTimeUTC", + "SetUserId" ], "ApiDocument": [ @@ -705,7 +721,7 @@ "ApiDocumentContent": [ ], - "ApiDrawing": [ + "apidrawing": [ "GetHeight", "GetLockValue", "GetWidth", @@ -713,6 +729,28 @@ ], "ApiFill": [ + ], + "apifont": [ + "GetBold", + "GetColor", + "GetItalic", + "GetParent", + "GetSize", + "GetStrikethrough", + "GetSubscript", + "GetSuperscript", + "GetUnderline", + "SetColor", + "SetStrikethrough", + "SetSubscript", + "SetSuperscript" + ], + "apifreezepanes": [ + "FreezeAt", + "FreezeColumns", + "FreezeRows", + "GetLocation", + "Unfreeze" ], "ApiGradientStop": [ @@ -827,6 +865,7 @@ "GetComments", "GetDefName", "GetDefNames", + "GetFreezePanes", "GetPrintGridlines", "GetPrintHeadings", "Move", @@ -898,6 +937,31 @@ "SetVertAxisTickLabelPosition", "SetXValues" ], + "apicomment": [ + "AddReply", + "Delete", + "GetAuthorName", + "GetQuoteText", + "GetRepliesCount", + "GetText", + "GetTime", + "GetTimeUTC", + "IsSolved", + "RemoveReplies", + "SetAuthorName", + "SetSolved", + "SetText", + "SetTime", + "SetTimeUTC", + "SetUserId" + ], + "apicommentreply": [ + "GetAuthorName", + "GetText", + "SetAuthorName", + "SetText", + "SetUserId" + ], "ApiDocument": [ ], @@ -923,7 +987,7 @@ "ApiGradientStop": [ ], - "ApiImage": [ + "apiimage": [ ], "ApiLayout": [ @@ -1000,6 +1064,7 @@ "AddMaster", "ApplyTheme", "CreateNewHistoryPoint", + "GetAllComments", "GetMaster", "GetMastersCount", "GetSlidesCount", @@ -1110,11 +1175,14 @@ ] }, "Form API": { - "Api": [ + "api": [ "CreateCheckBoxForm", "CreateComboBoxForm", "CreatePictureForm", "CreateTextForm" + ], + "apidocument": [ + "inserttextform" ] } } \ No newline at end of file diff --git a/spec/docx/smoke/api_document_content_spec.rb b/spec/docx/smoke/api_document_content_spec.rb index 92290e4e..a2acf323 100644 --- a/spec/docx/smoke/api_document_content_spec.rb +++ b/spec/docx/smoke/api_document_content_spec.rb @@ -53,4 +53,16 @@ expect(docx.elements.first.nonempty_runs.first.alternate_content.office2010_content.graphic.data.text_body.elements[4] .nonempty_runs.first.text).to eq('We removed paragraph #3, check that out above.') end + + it 'ApiDocumentContent | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_document_content/to_json.js') + expect(docx.elements[0].hyperlink.action.to_s).to eq('external_link') + expect(docx.elements[1].sdt_content.elements[1].character_style_array[0].text).to eq('oBlockLvlSdt') + expect(docx.elements[2].properties.table_style.name).to eq('CustomTableStyle') + json = JSON.parse(docx.elements[5].nonempty_runs.first.text) + expect(json['type']).to eq('docContent') + expect(json['content'][0]['content'][2]['type']).to eq('hyperlink') + expect(json['content'][1]['type']).to eq('blockLvlSdt') + expect(json['content'][2]['type']).to eq('table') + end end diff --git a/spec/docx/smoke/api_document_spec.rb b/spec/docx/smoke/api_document_spec.rb index 9ecf875f..0e6d9e91 100644 --- a/spec/docx/smoke/api_document_spec.rb +++ b/spec/docx/smoke/api_document_spec.rb @@ -148,4 +148,13 @@ expect(docx.elements[0].sector_properties.notes[3].type).to eq('footer2') expect(docx.elements[0].sector_properties.notes[3].elements.first.nonempty_runs.first.text).to eq('This is an even page footer') end + + it 'ApiDocument | ToJSON' do + docx = builder.build_and_parse('js/docx/smoke/api_document/to_json.js') + json = JSON.parse(docx.elements[0].nonempty_runs[0].text) + expect(json['type']).to eq('document') + expect(json['content'][1]['type']).to eq(docx.elements[1].nonempty_runs[0].text) + expect(json['content'][2]['type']).to eq(docx.elements[2].rows[0].cells[0].elements[0].nonempty_runs[0].text) + expect(json['content'][4]['type']).to eq(docx.elements[4].sdt_content.elements.first.nonempty_runs[0].text) + end end diff --git a/spec/docx/smoke/api_drawing_spec.rb b/spec/docx/smoke/api_drawing_spec.rb index bc022e95..1bc0d9a3 100644 --- a/spec/docx/smoke/api_drawing_spec.rb +++ b/spec/docx/smoke/api_drawing_spec.rb @@ -49,4 +49,10 @@ docx = builder.build_and_parse('js/docx/smoke/api_drawing/set_wrapping_style.js') expect(docx.elements.first.nonempty_runs[3].alternate_content.office2010_content.properties.wrap.wrap_text).to eq(:square) end + + it 'ApiDrawing | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_drawing/to_json.js') + json = JSON.parse(docx.elements[0].nonempty_runs[0].text) + expect(docx.elements[1].nonempty_runs[0].alternate_content.office2010_content.type.to_s).to eq(json['drawingType']) + end end diff --git a/spec/docx/smoke/api_fill_spec.rb b/spec/docx/smoke/api_fill_spec.rb index ac5ab389..713c7d1e 100644 --- a/spec/docx/smoke/api_fill_spec.rb +++ b/spec/docx/smoke/api_fill_spec.rb @@ -6,4 +6,17 @@ docx = builder.build_and_parse('js/docx/smoke/api_fill/get_class_type.js') expect(docx.elements.first.nonempty_runs[1].text).to eq('Class Type = fill') end + + it 'ApiFill | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_fill/to_json.js') + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + fill = json['graphic']['spPr']['fill']['fill']['gsLst'][0]['color']['color']['rgba'] + fill1 = json['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba'] + expect(fill['red']).to eq(255) + expect(fill['green']).to eq(111) + expect(fill['blue']).to eq(61) + expect(fill1['red']).to eq(255) + expect(fill1['green']).to eq(213) + expect(fill1['blue']).to eq(191) + end end diff --git a/spec/docx/smoke/api_gradient_stop_spec.rb b/spec/docx/smoke/api_gradient_stop_spec.rb index 19c784c6..8cd969df 100644 --- a/spec/docx/smoke/api_gradient_stop_spec.rb +++ b/spec/docx/smoke/api_gradient_stop_spec.rb @@ -6,4 +6,17 @@ docx = builder.build_and_parse('js/docx/smoke/api_gradient_stop/get_class_type.js') expect(docx.elements.first.nonempty_runs[1].text).to eq('Class Type = gradientStop') end + + it 'ApiGradientStop | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_gradient_stop/to_json.js') + json_drawing = JSON.parse(docx.elements[0].runs[3].text) + gs_list = json_drawing['graphic']['spPr']['fill']['fill']['gsLst'] + start = gs_list[0]['color']['color']['rgba'] + stop = gs_list[1]['color']['color']['rgba'] + actual = [OoxmlParser::Color.new(start['red'], start['green'], start['blue']), + OoxmlParser::Color.new(stop['red'], stop['green'], stop['blue'])] + expected = [OoxmlParser::Color.new(255, 111, 61), + OoxmlParser::Color.new(255, 213, 191)] + expect(actual).to eq(expected) + end end diff --git a/spec/docx/smoke/api_hyperlink/api_hyperlink_spec.rb b/spec/docx/smoke/api_hyperlink/api_hyperlink_spec.rb new file mode 100644 index 00000000..8f8f08ca --- /dev/null +++ b/spec/docx/smoke/api_hyperlink/api_hyperlink_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' +describe 'ApiHyperlink tests' do + it 'ApiHyperlink | ToJSON methods' do + docx = builder.build_and_parse('js/docx/smoke/api_hyperlink/to_json.js') + expect(docx.elements[0].nonempty_runs.first.text).to eq('ONLYOFFICE Document Builder') + expect(docx.elements[0].nonempty_runs.first.link.url).to eq('https://api.onlyoffice.com/') + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(json['type']).to eq('hyperlink') + expect(json['value']).to eq('https://api.onlyoffice.com/') + expect(json['tooltip']).to eq('ONLYOFFICE for developers') + expect(json['styles']['174']['name']).to eq('Hyperlink') + end +end diff --git a/spec/docx/smoke/api_inline_lvl_sdt_spec.rb b/spec/docx/smoke/api_inline_lvl_sdt_spec.rb new file mode 100644 index 00000000..c1844fbd --- /dev/null +++ b/spec/docx/smoke/api_inline_lvl_sdt_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'ApiInlineLvlSdt section tests' do + it 'ApiInlineLvlSdt | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_inline_lvl_sdt/to_json.js') + expect(docx.elements[0].nonempty_runs.first.sdt_content.elements[1].text).to eq('inlineLvlSdt') + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(json['type']).to eq('inlineLvlSdt') + expect(json['sdtPr']['alias']).to eq('№1') + end +end diff --git a/spec/docx/smoke/api_paragraph_properties_spec.rb b/spec/docx/smoke/api_paragraph_properties_spec.rb index 00f366cb..124f4bd7 100755 --- a/spec/docx/smoke/api_paragraph_properties_spec.rb +++ b/spec/docx/smoke/api_paragraph_properties_spec.rb @@ -173,4 +173,12 @@ docx = builder.build_and_parse('js/docx/smoke/api_para_pr/set_widow_control.js') expect(docx.elements[5].orphan_control).to be_truthy end + + it 'ApiParaPr | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_para_pr/to_json.js') + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(docx.elements[0].nonempty_runs[0].text).to eq(json['type']) + expect(json['pBdr']['left']['value']).to eq('single') + expect(json['pBdr']['left']['color']['g']).to eq(255) + end end diff --git a/spec/docx/smoke/api_paragraph_spec.rb b/spec/docx/smoke/api_paragraph_spec.rb index b526111d..01932837 100644 --- a/spec/docx/smoke/api_paragraph_spec.rb +++ b/spec/docx/smoke/api_paragraph_spec.rb @@ -261,4 +261,12 @@ docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_widow_control.js') expect(docx.elements[5].orphan_control).to be_truthy end + + it 'ApiParagraph | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_paragraph/to_json.js') + expect(docx.elements[1].nonempty_runs.first.text).to eq('This is a paragraph') + json = JSON.parse(docx.elements[0].nonempty_runs.first.text) + expect(json['type']).to eq('paragraph') + expect(json['content'][1]['content'][0]).to eq('This is a paragraph') + end end diff --git a/spec/docx/smoke/api_preset_color_spec.rb b/spec/docx/smoke/api_preset_color_spec.rb index f71ab9df..6675c7fa 100644 --- a/spec/docx/smoke/api_preset_color_spec.rb +++ b/spec/docx/smoke/api_preset_color_spec.rb @@ -6,4 +6,11 @@ docx = builder.build_and_parse('js/docx/smoke/api_preset_color/get_class_type.js') expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = presetColor') end + + it 'ApiPresetColor | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_preset_color/to_json.js') + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(docx.elements[0].nonempty_runs.first.text).to eq(json['type']) + expect(docx.elements[2].nonempty_runs[0].alternate_content.office2010_content.graphic.type).to eq(:shape) + end end diff --git a/spec/docx/smoke/api_range/api_range_spec.rb b/spec/docx/smoke/api_range/api_range_spec.rb new file mode 100644 index 00000000..7e806e8c --- /dev/null +++ b/spec/docx/smoke/api_range/api_range_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'spec_helper' +describe 'ApiRange section tests' do + it 'ApiRange | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_range/to_json.js') + expect(docx.elements[1].nonempty_runs.first.text).to eq('ONLYOFFICE') + json = JSON.parse(docx.elements[0].nonempty_runs.first.text) + expect(json['type']).to eq('document') + expect(json['content'][0]['content'][0]['content'][0]).to eq('ONLYOFFICE') + end +end diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index d2bf39a1..15af123e 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -6,4 +6,13 @@ docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/get_class_type.js') expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = rgbColor') end + + it 'ApiRGBColor | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/to_json.js') + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + rgba = json['graphic']['spPr']['fill']['fill']['gsLst'][0]['color']['color']['rgba'] + expect(rgba['red']).to eq(255) + expect(rgba['green']).to eq(111) + expect(rgba['blue']).to eq(61) + end end diff --git a/spec/docx/smoke/api_run_spec.rb b/spec/docx/smoke/api_run_spec.rb index 69a0fa13..cf09b8a3 100644 --- a/spec/docx/smoke/api_run_spec.rb +++ b/spec/docx/smoke/api_run_spec.rb @@ -183,4 +183,13 @@ expect(docx.elements.first.nonempty_runs[3].text).to eq('This is a text run with the text aligned above the baseline vertically.') expect(docx.elements.first.nonempty_runs[3].vertical_align).to eq(:superscript) end + + it 'ApiRun | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_run/to_json.js') + expect(docx.elements[0].nonempty_runs.first.text).to eq('This is a text run') + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(json['type']).to eq('run') + expect(json['rPr']['type']).to eq('textPr') + expect(json['content'][0]).to eq('This is a text run') + end end diff --git a/spec/docx/smoke/api_scheme_color_spec.rb b/spec/docx/smoke/api_scheme_color_spec.rb index 6e03dc40..def92277 100644 --- a/spec/docx/smoke/api_scheme_color_spec.rb +++ b/spec/docx/smoke/api_scheme_color_spec.rb @@ -6,4 +6,11 @@ docx = builder.build_and_parse('js/docx/smoke/api_scheme_color/get_class_type.js') expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = schemeColor') end + + it 'ApiSchemeColor | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_scheme_color/to_json.js') + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(docx.elements[0].nonempty_runs.first.text).to eq(json['type']) + expect(docx.elements[2].nonempty_runs[0].alternate_content.office2007_content.type).to eq(:shape) + end end diff --git a/spec/docx/smoke/api_stroke_spec.rb b/spec/docx/smoke/api_stroke_spec.rb index a594cd3d..4cdabcf0 100644 --- a/spec/docx/smoke/api_stroke_spec.rb +++ b/spec/docx/smoke/api_stroke_spec.rb @@ -6,4 +6,13 @@ docx = builder.build_and_parse('js/docx/smoke/api_stroke/get_class_type.js') expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = stroke') end + + it 'ApiStroke | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_stroke/to_json.js') + type = TestData.fill_types + docx.elements[1..6].each_with_index do |el, i| + json = JSON.parse(el.nonempty_runs.first.text) + expect(type[i]).to eq(json['fill']['fill']['type']) + end + end end diff --git a/spec/docx/smoke/api_style_spec.rb b/spec/docx/smoke/api_style_spec.rb index 6e8681db..85a4917f 100644 --- a/spec/docx/smoke/api_style_spec.rb +++ b/spec/docx/smoke/api_style_spec.rb @@ -85,4 +85,20 @@ docx = builder.build_and_parse('js/docx/smoke/api_style/set_name.js') expect(docx.elements[1].properties.table_style.name).to eq('My Custom Style') end + + it 'ApiStyle | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_style/to_json.js') + json = JSON.parse(docx.elements[22].nonempty_runs[0].text) + TestData.default_styles.each_with_index do |style, index| + # TODO: To understand why incorrect names are recorded + next if (style == 'Header') || # in the metadata: Custom_Style 719 styleId: 42 + (style == 'Footer') || # in the metadata: Custom_Style 725 styleId: 44 + (style == 'Footnote text') || # in the metadata: Normal styleId: styleId => 599 + (style == 'Endnote text') || # in the metadata: Normal styleId: styleId => 599 + (style == 'Subtitle') # in the metadata: Custom_Style 723 styleId: styleId => 722 + + expect(docx.elements[index + 1].style.name).to eq(style) + expect(JSON.parse(json[style])['name']).to eq(style) + end + end end diff --git a/spec/docx/smoke/api_table_cell_properties_spec.rb b/spec/docx/smoke/api_table_cell_properties_spec.rb index a4da9896..e5369104 100644 --- a/spec/docx/smoke/api_table_cell_properties_spec.rb +++ b/spec/docx/smoke/api_table_cell_properties_spec.rb @@ -84,4 +84,19 @@ docx = builder.build_and_parse('js/docx/smoke/api_table_cell_pr/set_width.js') expect(docx.elements[1].properties.table_style.table_cell_properties.table_cell_width).to eq(OoxmlParser::OoxmlSize.new(2880, :twip)) end + + it 'ApiTableCellPr | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_table_cell_pr/to_json.js') + json = JSON.parse(docx.elements[3].nonempty_runs[0].text) + r = json['tcBorders']['bottom']['color']['r'] + g = json['tcBorders']['bottom']['color']['g'] + b = json['tcBorders']['bottom']['color']['b'] + expect(docx.elements[1].properties.table_style.table_cell_properties.borders_properties.bottom.color) + .to eq(OoxmlParser::Color.new(r, g, b)) + expect(docx.elements[1].properties.table_style.table_cell_properties.borders_properties.bottom.val.to_s) + .to eq(json['tcBorders']['bottom']['value']) + expect(docx.elements[1].properties.table_style.table_cell_properties.borders_properties.bottom.size) + .to eq(OoxmlParser::OoxmlSize.new(json['tcBorders']['bottom']['sz'], :one_eighth_point)) + expect(docx.elements[0].nonempty_runs[0].text).to eq(json['type']) + end end diff --git a/spec/docx/smoke/api_table_cell_spec.rb b/spec/docx/smoke/api_table_cell_spec.rb index 01c8253d..b5efed75 100644 --- a/spec/docx/smoke/api_table_cell_spec.rb +++ b/spec/docx/smoke/api_table_cell_spec.rb @@ -76,4 +76,23 @@ docx = builder.build_and_parse('js/docx/smoke/api_table_cell/set_width.js') expect(docx.nil?).to be(false) end + + it 'ApiTableCell | SetWidth method' do + docx = builder.build_and_parse('js/docx/smoke/api_table_cell/to_json.js') + json = JSON.parse(docx.elements[3].nonempty_runs[0].text) + cell = docx.elements[1].rows[0].cells[0] + + expect(cell.properties.table_cell_margin.bottom.value).to eq(json['tcMar']['bottom']['w']) + expect(cell.properties.table_cell_margin.top.value).to eq(json['tcMar']['top']['w']) + expect(cell.properties.table_cell_margin.left.value).to eq(json['tcMar']['left']['w']) + expect(cell.properties.table_cell_margin.right.value).to eq(json['tcMar']['right']['w']) + + expect(cell.properties.borders_properties.bottom.val.to_s).to eq(json['tcBorders']['bottom']['value']) + expect(cell.properties.borders_properties.top.val.to_s).to eq(json['tcBorders']['top']['value']) + expect(cell.properties.borders_properties.left.val.to_s).to eq(json['tcBorders']['start']['value']) + expect(cell.properties.borders_properties.right.val.to_s).to eq(json['tcBorders']['end']['value']) + + expect(cell.properties.text_direction).to eq(:bottom_to_top_left_to_right) + expect(cell.properties.table_cell_width.value.to_i).to eq(json['tcW']['w']) + end end diff --git a/spec/docx/smoke/api_table_properties_spec.rb b/spec/docx/smoke/api_table_properties_spec.rb index 49317edf..ddbca5ee 100644 --- a/spec/docx/smoke/api_table_properties_spec.rb +++ b/spec/docx/smoke/api_table_properties_spec.rb @@ -112,4 +112,10 @@ docx = builder.build_and_parse('js/docx/smoke/api_table_pr/set_width.js') expect(docx.elements[1].properties.table_style.table_properties.table_width).to eq(OoxmlParser::OoxmlSize.new(100, :percent)) end + + it 'ApiTablePr | ToJson method' do + docx = builder.build_and_parse('js/docx/smoke/api_table_pr/to_json.js') + json = JSON.parse(docx.elements[1].nonempty_runs[0].text) + expect(docx.elements[0].nonempty_runs[0].text).to eq(json['type']) + end end diff --git a/spec/docx/smoke/api_table_row_properties_spec.rb b/spec/docx/smoke/api_table_row_properties_spec.rb index b455dc31..840f46b9 100644 --- a/spec/docx/smoke/api_table_row_properties_spec.rb +++ b/spec/docx/smoke/api_table_row_properties_spec.rb @@ -16,4 +16,11 @@ docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/set_table_header.js') expect(docx.elements[1].properties.table_style.table_row_properties.table_header).to be_truthy end + + it 'ApiTableRowPr | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/to_json.js') + json = JSON.parse(docx.elements[3].nonempty_runs[0].text) + expect(docx.elements[0].nonempty_runs[0].text).to eq(json['type']) + expect(docx.elements[1].properties.table_style.table_row_properties.height.value).to eq(OoxmlParser::OoxmlSize.new(720, :twip)) + end end diff --git a/spec/docx/smoke/api_table_row_spec.rb b/spec/docx/smoke/api_table_row_spec.rb index 2afe8870..04cb2979 100644 --- a/spec/docx/smoke/api_table_row_spec.rb +++ b/spec/docx/smoke/api_table_row_spec.rb @@ -26,4 +26,11 @@ docx = builder.build_and_parse('js/docx/smoke/api_table_row/set_table_header.js') expect(docx.elements[1].rows.first.table_row_properties.table_header).to be_truthy end + + it 'ApiTableRow | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_table_row/to_json.js') + json = JSON.parse(docx.elements[4].nonempty_runs.first.text) + expect("#{docx.elements[1].nonempty_runs.first.text}Pr").to eq(json['type']) + expect(docx.elements[2].rows[1].table_row_properties.height.value.value).to eq(json['trHeight']['val'].to_f) + end end diff --git a/spec/docx/smoke/api_table_spec.rb b/spec/docx/smoke/api_table_spec.rb index 4654211a..a8e58826 100644 --- a/spec/docx/smoke/api_table_spec.rb +++ b/spec/docx/smoke/api_table_spec.rb @@ -180,4 +180,12 @@ docx = builder.build_and_parse('js/docx/smoke/api_table/set_width.js') expect(docx.elements[1].properties.table_width).to eq(OoxmlParser::OoxmlSize.new(100, :percent)) end + + it 'ApiTable | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_table/to_json.js') + json = JSON.parse(docx.elements[0].nonempty_runs[0].text) + expect(json['type']).to eq('table') + expect(json['styles']['132']['name']).to eq('List Table 5 Dark') + expect(docx.elements[1].properties.table_style.name).to eq('List Table 5 Dark') + end end diff --git a/spec/docx/smoke/api_table_style_pr_spec.rb b/spec/docx/smoke/api_table_style_pr_spec.rb index cef27793..eb313509 100644 --- a/spec/docx/smoke/api_table_style_pr_spec.rb +++ b/spec/docx/smoke/api_table_style_pr_spec.rb @@ -55,4 +55,10 @@ docx = builder.build_and_parse('js/docx/smoke/api_table_style_pr/get_type.js') expect(docx.elements.first.nonempty_runs.first.text).to eq('Style type = topLeftCell') end + + it 'ApiTableStylePr | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_table_style_pr/to_json.js') + json = JSON.parse(docx.elements[3].nonempty_runs.first.text) + expect(docx.elements[0].nonempty_runs[0].text).to include(json['type']) + end end diff --git a/spec/docx/smoke/api_uni_color_spec.rb b/spec/docx/smoke/api_uni_color_spec.rb index f5e47f06..fff70fdd 100644 --- a/spec/docx/smoke/api_uni_color_spec.rb +++ b/spec/docx/smoke/api_uni_color_spec.rb @@ -6,4 +6,14 @@ docx = builder.build_and_parse('js/docx/smoke/api_uni_color/get_class_type.js') expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = presetColor') end + + it 'ApiUniColor | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_uni_color/to_json.js') + json = JSON.parse(docx.elements[0].nonempty_runs.first.text) + color = json['graphic']['spPr']['fill']['fill']['color'] + expect(color['type']).to eq('uniColor') + expect(color['color']['rgba']['red']).to eq(255) + expect(color['color']['rgba']['green']).to eq(111) + expect(color['color']['rgba']['blue']).to eq(61) + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4f99d96f..231b3155 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true Encoding.default_external = Encoding::UTF_8 -require 'bundler/setup' require 'rspec' +require 'test_data' +require 'bundler/setup' require_relative '../lib/doc_builder_testing' # ENV['BUILDER_PLATFORM'] = 'WEB' diff --git a/spec/test_data.rb b/spec/test_data.rb index 3b0aef33..8f3f5df3 100644 --- a/spec/test_data.rb +++ b/spec/test_data.rb @@ -3,6 +3,7 @@ # Test data for autotest module TestData # CDE number formats (7.4.0) + # @return [Array] def self.number_formats ['General', '0.00', @@ -17,6 +18,17 @@ def self.number_formats '0.00E+00'].freeze end + # CDE fill types + # @return [Array] + def self.fill_types + %w[blipFill + solid + gradFill + noFill + pattFill + gradFill] + end + # @return [Array] def self.libs %w[DjVuFile.dll @@ -36,4 +48,29 @@ def self.libs UnicodeConverter.dll XpsFile.dll] end + + # Default style list in the CDE + def self.default_styles + ['Normal', + 'No Spacing', + 'Heading 1', + 'Heading 2', + 'Heading 3', + 'Heading 4', + 'Heading 5', + 'Heading 6', + 'Heading 7', + 'Heading 8', + 'Heading 9', + 'Title', + 'Subtitle', + 'Quote', + 'Intense Quote', + 'List Paragraph', + 'Caption', + 'Header', + 'Footer', + 'Footnote text', + 'Endnote text'].freeze + end end diff --git a/spec/xlsx/smoke/api_range_spec.rb b/spec/xlsx/smoke/api_range_spec.rb index 80da0a90..423053c4 100644 --- a/spec/xlsx/smoke/api_range_spec.rb +++ b/spec/xlsx/smoke/api_range_spec.rb @@ -2,10 +2,6 @@ require 'spec_helper' describe 'ApiRange section tests' do - before do - include TestData - end - it 'ApiRange | GetCol method' do xlsx = builder.build_and_parse('js/xlsx/smoke/api_range/get_col.js') expect(xlsx.worksheets.first.rows[1].cells.first.text).to eq('4')