Skip to content

Commit

Permalink
[7.6.0][CDE] ApiRGBColor.ToJSON check (#997)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yar04ek authored and askonev committed Dec 6, 2023
1 parent 504010d commit d8da9d6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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();
9 changes: 9 additions & 0 deletions spec/docx/smoke/api_rgb_color_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d8da9d6

Please sign in to comment.