From 272086b81278cbe408a2ae2a0f32c1fcdbf42da3 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Mon, 25 Mar 2024 19:27:46 +0300 Subject: [PATCH] [8.1] InliveLvlSdt.ToJSON --- js/docx/smoke/api_inline_lvl_sdt/to_json.js | 25 +++++++++++++++++++++ spec/docx/smoke/api_inline_lvl_sdt_spec.rb | 13 +++++++++++ 2 files changed, 38 insertions(+) create mode 100644 js/docx/smoke/api_inline_lvl_sdt/to_json.js create mode 100644 spec/docx/smoke/api_inline_lvl_sdt_spec.rb 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 000000000..6024493e5 --- /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/spec/docx/smoke/api_inline_lvl_sdt_spec.rb b/spec/docx/smoke/api_inline_lvl_sdt_spec.rb new file mode 100644 index 000000000..c1844fbdb --- /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