Skip to content

Commit

Permalink
[8.1] InliveLvlSdt.ToJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
askonev committed Mar 25, 2024
1 parent 93a7b5f commit 272086b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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();
13 changes: 13 additions & 0 deletions spec/docx/smoke/api_inline_lvl_sdt_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 272086b

Please sign in to comment.