Skip to content

Commit

Permalink
ApiLayout smokes
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonowl committed Dec 23, 2024
1 parent 2432219 commit 925bcdd
Show file tree
Hide file tree
Showing 15 changed files with 323 additions and 17 deletions.
23 changes: 23 additions & 0 deletions js/pptx/smoke/api_layout/add_object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oSlide = oPresentation.GetSlideByIndex(0);
oSlide.RemoveAllObjects();
var oMaster = oPresentation.GetMaster(0);
var oLayout = oMaster.GetLayout(0);

var nCountBefore = oLayout.GetAllShapes().length;
var oFill = Api.CreateSolidFill(Api.CreateRGBColor(255, 111, 61));
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oShape = Api.CreateShape("flowChartMagneticTape", 300 * 36000, 130 * 36000, oFill, oStroke);
oShape.SetPosition(608400, 1267200);
oShape.SetSize(300 * 36000, 130 * 36000);
oLayout.AddObject(oShape);
var nCountAfter = oLayout.GetAllShapes().length;

var oDocContent = oShape.GetDocContent();
var oParagraph = oDocContent.GetElement(0);
var oRun = Api.CreateRun();
oRun.AddText('before: ' + nCountBefore + ', after: ' + nCountAfter);
oParagraph.AddElement(oRun);
builder.SaveFile("pptx", "AddObject.pptx");
builder.CloseFile();
13 changes: 13 additions & 0 deletions js/pptx/smoke/api_layout/clear_background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oSlide = oPresentation.GetSlideByIndex(0);
var oMaster = oPresentation.GetMaster(0);
var oLayout = oMaster.GetLayout(0);
var oRGBColor = Api.CreateRGBColor(255, 213, 191);
var oGs1 = Api.CreateGradientStop(oRGBColor, 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 100000);
var oFill = Api.CreateRadialGradientFill([oGs1, oGs2]);
oLayout.SetBackground(oFill);
oLayout.ClearBackground();
builder.SaveFile("pptx", "ClearBackground.pptx");
builder.CloseFile();
20 changes: 20 additions & 0 deletions js/pptx/smoke/api_layout/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oSlide = oPresentation.GetSlideByIndex(0);
oSlide.RemoveAllObjects();
var oMaster = oPresentation.GetMaster(0);
var oLayout = oMaster.GetLayout(0);

var nCountBefore = oMaster.GetLayoutsCount();
var oCopyLayout = oLayout.Copy();
oMaster.AddLayout(0, oCopyLayout);
var nCountAfter = oMaster.GetLayoutsCount();

var oShape = Api.CreateShape("rect", 100 * 36000, 50 * 36000);
var oDocContent = oShape.GetDocContent();
var oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('Layouts before: ' + nCountBefore + ', after: ' + nCountAfter);
oParagraph.SetHighlight("black");
oCopyLayout.AddObject(oShape);
builder.SaveFile("pptx", "Copy.pptx");
builder.CloseFile();
19 changes: 19 additions & 0 deletions js/pptx/smoke/api_layout/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oSlide = oPresentation.GetSlideByIndex(0);
oSlide.RemoveAllObjects();
var oMaster = oPresentation.GetMaster(0);

var nCountBefore = oMaster.GetLayoutsCount();
var oLayout = oMaster.GetLayout(0);
oLayout.Delete();
var nCountAfter = oMaster.GetLayoutsCount();

var oShape = Api.CreateShape("rect", 100 * 36000, 50 * 36000);
var oDocContent = oShape.GetDocContent();
var oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('Layouts before: ' + nCountBefore + ', after: ' + nCountAfter);
oParagraph.SetHighlight("black");
oSlide.AddObject(oShape);
builder.SaveFile("pptx", "Delete.pptx");
builder.CloseFile();
19 changes: 19 additions & 0 deletions js/pptx/smoke/api_layout/duplicate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oSlide = oPresentation.GetSlideByIndex(0);
oSlide.RemoveAllObjects();
var oMaster = oPresentation.GetMaster(0);
var oLayout = oMaster.GetLayout(0);

var nCountBefore = oMaster.GetLayoutsCount();
oLayout.Duplicate(1);
var nCountAfter = oMaster.GetLayoutsCount();

var oShape = Api.CreateShape("rect", 100 * 36000, 50 * 36000);
var oDocContent = oShape.GetDocContent();
var oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('Layouts before: ' + nCountBefore + ', after: ' + nCountAfter);
oParagraph.SetHighlight("black");
oSlide.AddObject(oShape);
builder.SaveFile("pptx", "Duplicate.pptx");
builder.CloseFile();
29 changes: 29 additions & 0 deletions js/pptx/smoke/api_layout/get_all_charts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oSlide = oPresentation.GetSlideByIndex(0);
oSlide.RemoveAllObjects();
var oMaster = oPresentation.GetMaster(0);
var oLayout = oMaster.GetLayout(0);

var oChart = Api.CreateChart("bar3D", [
[200, 240, 280],
[250, 260, 280]
], ["Projected Revenue", "Estimated Costs"], [2014, 2015, 2016], 4051300, 2347595, 24);
oChart.SetVerAxisTitle("USD In Hundred Thousands", 10);
oChart.SetHorAxisTitle("Year", 11);
oChart.SetLegendPos("bottom");
oChart.SetShowDataLabels(false, false, true, false);
oChart.SetTitle("Financial Overview", 13);
oChart.SetSize(300 * 36000, 130 * 36000);
oChart.SetPosition(608400, 1267200);
oLayout.AddObject(oChart);
var aCharts = oLayout.GetAllCharts();

var oShape = Api.CreateShape("rect", 100 * 36000, 50 * 36000);
var oDocContent = oShape.GetDocContent();
var oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('Charts count: ' + aCharts.length + ', type: ' + aCharts[0].GetClassType());
oParagraph.SetHighlight("black");
oSlide.AddObject(oShape);
builder.SaveFile("pptx", "GetAllCharts.pptx");
builder.CloseFile();
32 changes: 32 additions & 0 deletions js/pptx/smoke/api_layout/get_all_drawings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oSlide = oPresentation.GetSlideByIndex(0);
// oPresentation.GetMaster(0).Delete();
oSlide.RemoveAllObjects();
var oMaster = Api.CreateMaster();
oPresentation.AddMaster(1, oMaster);
var oLayout = Api.CreateLayout();
oMaster.AddLayout(0, oLayout);

var oImage = Api.CreateImage("https://legacy-api.onlyoffice.com/content/img/docbuilder/examples/coordinate_aspects.png", 60 * 36000, 35 * 36000);
oLayout.AddObject(oImage);
var oOleObject = Api.CreateOleObject("https://i.ytimg.com/vi_webp/SKGz4pmnpgY/sddefault.webp", 130 * 36000, 90 * 36000, "https://youtu.be/SKGz4pmnpgY", "asc.{38E022EA-AD92-45FC-B22B-49DF39746DB4}");
oOleObject.SetSize(200 * 36000, 130 * 36000);
oOleObject.SetPosition(70 * 36000, 30 * 36000);
oLayout.AddObject(oOleObject);
var aDrawings = oLayout.GetAllDrawings();

var oShape = Api.CreateShape("rect", 100 * 36000, 50 * 36000);
var oDocContent = oShape.GetDocContent();
var oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('Drawings count: ' + aDrawings.length);
oParagraph.AddLineBreak();
var aDrawingsTypes = []
for (var i=0; i<aDrawings.length; i++){
aDrawingsTypes.push(aDrawings[i].GetClassType());
}
oParagraph.AddText('Types: ' + aDrawingsTypes.join(', '));
oParagraph.SetHighlight("black");
oSlide.AddObject(oShape);
builder.SaveFile("pptx", "GetAllDrawings.pptx");
builder.CloseFile();
16 changes: 16 additions & 0 deletions js/pptx/smoke/api_layout/get_class_type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oSlide = oPresentation.GetSlideByIndex(0);
oSlide.RemoveAllObjects();
var oMaster = oPresentation.GetMaster(0);
var oLayout = oMaster.GetLayout(0);
var sType = oLayout.GetClassType();

var oShape = Api.CreateShape("rect", 100 * 36000, 50 * 36000);
var oDocContent = oShape.GetDocContent();
var oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('GetClassType type: ' + sType);
oParagraph.SetHighlight("black");
oLayout.AddObject(oShape);
builder.SaveFile("pptx", "GetClassType.pptx");
builder.CloseFile();
12 changes: 12 additions & 0 deletions js/pptx/smoke/api_layout/set_background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oSlide = oPresentation.GetSlideByIndex(0);
var oMaster = oPresentation.GetMaster(0);
var oLayout = oMaster.GetLayout(0);
var oRGBColor = Api.CreateRGBColor(255, 213, 191);
var oGs1 = Api.CreateGradientStop(oRGBColor, 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 100000);
var oFill = Api.CreateRadialGradientFill([oGs1, oGs2]);
oLayout.SetBackground(oFill);
builder.SaveFile("pptx", "SetBackground.pptx");
builder.CloseFile();
19 changes: 19 additions & 0 deletions js/pptx/smoke/api_layout/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oSlide = oPresentation.GetSlideByIndex(0);
oSlide.RemoveAllObjects();
var oMaster = oPresentation.GetMaster(0);
var oLayout = oMaster.GetLayout(0);
var json = oLayout.ToJSON(true, false);

var oLayoutFromJSON = Api.FromJSON(json);
oMaster.AddLayout(0, oLayoutFromJSON);
var sType = oLayoutFromJSON.GetClassType();
var oShape = Api.CreateShape("rect", 100 * 36000, 50 * 36000);
var oDocContent = oShape.GetDocContent();
var oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('sType: ' + sType);
oParagraph.SetHighlight("black");
oLayoutFromJSON.AddObject(oShape);
builder.SaveFile("pptx", "ToJSON.pptx");
builder.CloseFile();
2 changes: 1 addition & 1 deletion js/pptx/smoke/api_master/add_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ var oDocContent = oShape.GetDocContent();
var oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('Layouts before: ' + nCountBefore + ', after: ' + nCountAfter);
oParagraph.SetHighlight("black");
oSlide.AddObject(oShape);
oLayout.AddObject(oShape);
builder.SaveFile("pptx", "AddLayout.pptx");
builder.CloseFile();
4 changes: 2 additions & 2 deletions js/pptx/smoke/api_master/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ var oMaster = oPresentation.GetMaster(0);

var nCountBefore = oPresentation.GetMastersCount();
var oCopyMaster = oMaster.Copy();
oPresentation.AddMaster(1, oCopyMaster);
oPresentation.AddMaster(nCountBefore + 1, oCopyMaster);
var nCountAfter = oPresentation.GetMastersCount();

var oShape = Api.CreateShape("rect", 100 * 36000, 50 * 36000);
var oDocContent = oShape.GetDocContent();
var oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('Masters before: ' + nCountBefore + ', after: ' + nCountAfter);
oParagraph.SetHighlight("black");
oSlide.AddObject(oShape);
oCopyMaster.AddObject(oShape);
builder.SaveFile("pptx", "Copy.pptx");
builder.CloseFile();
5 changes: 3 additions & 2 deletions js/pptx/smoke/api_master/to_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ var oSlide = oPresentation.GetSlideByIndex(0);
oSlide.RemoveAllObjects();
var oMaster = oPresentation.GetMaster(0);
var json = oMaster.ToJSON(true);

var oMasterFromJSON = Api.FromJSON(json);
var sType = oMasterFromJSON.GetClassType();

var oShape = Api.CreateShape("rect", 100 * 36000, 50 * 36000);
var oDocContent = oShape.GetDocContent();
var oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('sType: ' + sType);
oSlide.AddObject(oShape);
oParagraph.SetHighlight("black");
oMasterFromJSON.AddObject(oShape);
builder.SaveFile("pptx", "ToJSON.pptx");
builder.CloseFile();
109 changes: 109 additions & 0 deletions spec/pptx/smoke/api_layout_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# frozen_string_literal: true

require 'spec_helper'
describe 'ApiLayout section tests' do
it 'ApiLayout | AddObject method' do
pptx = builder.build_and_parse('js/pptx/smoke/api_layout/add_object.js')
expect(pptx.slide_layouts.first.common_slide_data.shape_tree.elements[5].text_body.paragraphs.first.runs.first.text).to eq('before: 5, after: 6')
end

it 'ApiLayout | ClearBackground method' do
pptx = builder.build_and_parse('js/pptx/smoke/api_layout/clear_background.js')
expect(pptx.slide_layouts.first.common_slide_data.background.fill.color).to eq(:none)
end

it 'ApiLayout | Copy method' do
pptx = builder.build_and_parse('js/pptx/smoke/api_layout/copy.js')
expect(pptx.slide_layouts.size).to eq(12)
expect(pptx.slide_layouts.first.common_slide_data.shape_tree.elements[5].text_body.paragraphs.first.runs.first.text).to eq('Layouts before: 11, after: 12')
end

it 'ApiLayout | Delete method' do
pptx = builder.build_and_parse('js/pptx/smoke/api_layout/delete.js')
expect(pptx.slide_layouts.size).to eq(10)
expect(pptx.slides.first.common_slide_data.shape_tree.elements.first.text_body.paragraphs.first.runs.first.text).to eq('Layouts before: 11, after: 10')
end

it 'ApiLayout | Duplicate method' do
pptx = builder.build_and_parse('js/pptx/smoke/api_layout/duplicate.js')
expect(pptx.slide_layouts.size).to eq(12)
expect(pptx.slides.first.common_slide_data.shape_tree.elements.first.text_body.paragraphs.first.runs.first.text).to eq('Layouts before: 11, after: 12')
end

# it 'ApiLayout | FollowMasterBackground method' do
# pptx = builder.build_and_parse('js/pptx/smoke/api_layout/follow_master_background.js')
# expect(pptx.slides.first.elements.last.text_body.paragraphs.last.characters.first.text).to eq('Class Type = image')
# end

it 'ApiLayout | GetAllCharts method' do
pptx = builder.build_and_parse('js/pptx/smoke/api_layout/get_all_charts.js')
expect(pptx.slide_layouts.first.common_slide_data.shape_tree.elements[5].class).to eq(OoxmlParser::GraphicFrame)
expect(pptx.slides.first.common_slide_data.shape_tree.elements.first.text_body.paragraphs.first.runs.first.text).to eq('Charts count: 1, type: chart')
end

it 'ApiLayout | GetAllDrawings method' do
pptx = builder.build_and_parse('js/pptx/smoke/api_layout/get_all_drawings.js')
expect(pptx.slide_layouts.first.common_slide_data.shape_tree.elements[5].class).to eq(OoxmlParser::GraphicFrame)
expect(pptx.slides.first.common_slide_data.shape_tree.elements.first.text_body.paragraphs.first.runs.first.text).to eq('Charts count: 1, type: chart')
end

# it 'ApiLayout | GetAllImages method' do
# pptx = builder.build_and_parse('js/pptx/smoke/api_layout/get_all_images.js')
# expect(pptx.slides.first.elements.last.text_body.paragraphs.last.characters.first.text).to eq('Class Type = image')
# end

# it 'ApiLayout | GetAllOleObjects method' do
# pptx = builder.build_and_parse('js/pptx/smoke/api_layout/get_all_ole_objects.js')
# expect(pptx.slides.first.elements.last.text_body.paragraphs.last.characters.first.text).to eq('Class Type = image')
# end

# it 'ApiLayout | GetAllShapes method' do
# pptx = builder.build_and_parse('js/pptx/smoke/api_layout/get_all_shapes.js')
# expect(pptx.slides.first.elements.last.text_body.paragraphs.last.characters.first.text).to eq('Class Type = image')
# end

it 'ApiLayout | GetClassType method' do
pptx = builder.build_and_parse('js/pptx/smoke/api_layout/get_class_type.js')
expect(pptx.slide_layouts.first.common_slide_data.shape_tree.elements[5].text_body.paragraphs.first.runs.first.text).to eq('GetClassType type: layout')
end

# it 'ApiLayout | GetDrawingsByPlaceholderType method' do
# pptx = builder.build_and_parse('js/pptx/smoke/api_layout/get_drawings_by_placeholder_type.js')
# expect(pptx.slides.first.elements.last.text_body.paragraphs.last.characters.first.text).to eq('Class Type = image')
# end

# it 'ApiLayout | GetMaster method' do
# pptx = builder.build_and_parse('js/pptx/smoke/api_layout/get_master.js')
# expect(pptx.slides.first.elements.last.text_body.paragraphs.last.characters.first.text).to eq('Class Type = image')
# end

# it 'ApiLayout | MoveTo method' do
# pptx = builder.build_and_parse('js/pptx/smoke/api_layout/move_to.js')
# expect(pptx.slides.first.elements.last.text_body.paragraphs.last.characters.first.text).to eq('Class Type = image')
# end

# it 'ApiLayout | RemoveObject method' do
# pptx = builder.build_and_parse('js/pptx/smoke/api_layout/remove_object.js')
# expect(pptx.slides.first.elements.last.text_body.paragraphs.last.characters.first.text).to eq('Class Type = image')
# end

it 'ApiLayout | SetBackground method' do
pptx = builder.build_and_parse('js/pptx/smoke/api_layout/set_background.js')
background_color = pptx.slide_layouts.first.common_slide_data.background.fill.color
expect(background_color.gradient_stops[0].color).to eq(OoxmlParser::Color.new(255, 213, 191))
expect(background_color.gradient_stops[0].position).to eq(0)
expect(background_color.gradient_stops[1].color).to eq(OoxmlParser::Color.new(255, 111, 61))
expect(background_color.gradient_stops[1].position).to eq(100)
end

# it 'ApiLayout | SetName method' do
# pptx = builder.build_and_parse('js/pptx/smoke/api_layout/set_name.js')
# expect(pptx.slides.first.elements.last.text_body.paragraphs.last.characters.first.text).to eq('Class Type = image')
# end

it 'ApiLayout | ToJSON method' do
pptx = builder.build_and_parse('js/pptx/smoke/api_layout/to_json.js')
expect(pptx.slide_layouts.size).to eq(12)
expect(pptx.slide_layouts.first.common_slide_data.shape_tree.elements[5].text_body.paragraphs.first.runs.first.text).to eq('sType: layout')
end
end
Loading

0 comments on commit 925bcdd

Please sign in to comment.