diff --git a/js/docx/smoke/api_block_lvl_sdt/to_json.js b/js/docx/smoke/api_block_lvl_sdt/to_json.js new file mode 100644 index 000000000..aadc47436 --- /dev/null +++ b/js/docx/smoke/api_block_lvl_sdt/to_json.js @@ -0,0 +1,38 @@ +builder.CreateFile("docx"); + var oDocument = Api.GetDocument(); + CustomDefaultStyle(oDocument) + var oBlockLvlSdt = Api.CreateBlockLvlSdt(); + oBlockLvlSdt.SetAlias("№1"); + var oBlockContent = oBlockLvlSdt.GetContent() + oBlockContent.GetElement(0).AddText("blockLvlSdt"); + var oNumbering = oDocument.CreateNumbering("bullet"); + for (let nLvl = 0; nLvl < 8; ++nLvl) { + var oNumLvl = oNumbering.GetLevel(nLvl); + var oParagraph = Api.CreateParagraph(); + oParagraph.AddText("Default bullet lvl " + (nLvl + 1)); + oParagraph.SetNumbering(oNumLvl); + oParagraph.SetContextualSpacing(true); + oBlockContent.Push(oParagraph); + } + var json = oBlockLvlSdt.ToJSON(true, true); + function CustomDefaultStyle(oDocument){ + var oNormalStyle = oDocument.GetDefaultStyle("paragraph"); + var oTextPr = oNormalStyle.GetTextPr(); + oTextPr.SetColor(0x26, 0x26, 0x26, false); + oTextPr.SetFontFamily("Calibri Light"); + oTextPr.SetFontSize(32); + } +GlobalVariable["JSON"] = json; +builder.CloseFile(); + +//////////////////////// + +builder.CreateFile("docx"); + var json = GlobalVariable["JSON"]; + var oDocument = Api.GetDocument(); + var oParagraph = oDocument.GetElement(0); + oParagraph.AddText(json) + var oBlockSdtFromJSON = Api.FromJSON(json); + oDocument.AddElement(0, oBlockSdtFromJSON); +builder.SaveFile("docx", "ToJSON.docx"); +builder.CloseFile(); diff --git a/spec/docx/smoke/api_block_lvl_sdt_spec.rb b/spec/docx/smoke/api_block_lvl_sdt_spec.rb new file mode 100644 index 000000000..3e5d30fea --- /dev/null +++ b/spec/docx/smoke/api_block_lvl_sdt_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'ApiBlockLvlSdt section tests' do + it 'ApiBlockLvlSdt | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_block_lvl_sdt/to_json.js') + expect(docx.elements[0].sdt_content.elements[0].character_style_array[1].text).to eq('blockLvlSdt') + expect(docx.elements[0].sdt_content.elements[8].numbering.i_level.value).to eq(7) + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(json['type']).to eq('blockLvlSdt') + expect(json['numbering']['type']).to eq('numbering') + end +end