From d8a5a92fd67100faff112b4a4f9a61809b363ffe Mon Sep 17 00:00:00 2001 From: Yarosalv Maslov <148754748+Yar04ek@users.noreply.github.com> Date: Fri, 24 Nov 2023 10:59:16 +0100 Subject: [PATCH] Rgb color test --- Gemfile.lock | 32 +++++++----------- js/docx/smoke/api_rgb_color/to_json.js | 46 ++++++++++---------------- spec/docx/smoke/api_rgb_color_spec.rb | 14 ++++---- spec/spec_helper.rb | 7 +++- 4 files changed, 42 insertions(+), 57 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3bcfe7aaa..dcd9a7533 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,10 +11,9 @@ GEM iniparse (1.5.0) json (2.6.3) jwt (2.7.1) - language_server-protocol (3.17.0.3) - mini_portile2 (2.8.5) - nokogiri (1.15.4) - mini_portile2 (~> 2.8.2) + nokogiri (1.15.5-arm64-darwin) + racc (~> 1.4) + nokogiri (1.15.5-x86_64-darwin) racc (~> 1.4) onlyoffice_pdf_parser (0.5.0) image_size (>= 2, < 4) @@ -23,7 +22,7 @@ GEM ooxml_decrypt (1.0.0) nokogiri (~> 1.10) ruby-ole (~> 1.2) - ooxml_parser (0.37.1) + ooxml_parser (0.34.2) nokogiri (~> 1) ooxml_decrypt (~> 1) rubyzip (~> 2) @@ -32,7 +31,7 @@ GEM iniparse (~> 1.4) rexml (~> 3.2) parallel (1.23.0) - parallel_tests (4.3.0) + parallel_tests (3.13.0) parallel parser (3.2.2.4) ast (~> 2.4.1) @@ -64,32 +63,25 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.1) - rubocop (1.57.2) + rubocop (1.50.2) json (~> 2.3) - language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.4) + parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.28.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) - rubocop-capybara (2.19.0) - rubocop (~> 1.41) - rubocop-factory_bot (2.24.0) - rubocop (~> 1.33) - rubocop-performance (1.19.1) + rubocop-performance (1.17.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-rspec (2.25.0) - rubocop (~> 1.40) - rubocop-capybara (~> 2.17) - rubocop-factory_bot (~> 2.22) + rubocop-rspec (2.17.1) + rubocop (~> 1.33) ruby-ole (1.2.12.2) ruby-progressbar (1.13.0) ruby-rc4 (0.1.5) @@ -100,7 +92,7 @@ GEM yard (0.9.34) PLATFORMS - ruby + universal-darwin-23 DEPENDENCIES jwt diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js index 82d61faa7..5d843737a 100644 --- a/js/docx/smoke/api_rgb_color/to_json.js +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -1,38 +1,28 @@ builder.CreateFile("docx"); var oDocument = Api.GetDocument(); -var oParagraph, oRGBColor; - -// Создаем элемент параграфа -oParagraph = Api.CreateParagraph(); - -// Создаем RGB цвет с помощью значений RGB (красный, зеленый, синий) -oRGBColor = Api.CreateRGBColor(255, 0, 0); // Например, красный цвет - -// Преобразуем RGB цвет в JSON -var jsonRGB = oRGBColor.ToJSON(); - -// Добавляем текстовую строку с JSON представлением RGB цвета в параграф -oParagraph.AddText("JSON representation of RGB color: " + jsonRGB); - -// Добавляем созданный параграф в документ +var oParagraph = Api.CreateParagraph(); +var oRGBColor = Api.CreateRGBColor(255, 0, 0); +var json = oRGBColor.ToJSON(); +oParagraph.AddText("JSON representation of RGB color: " + json); oDocument.Push(oParagraph); +GlobalVariable["RGBColorJSON"] = json; +builder.CloseFile() +///////////////////////// -// Сохраняем файл -builder.SaveFile("docx", "RGBColorJSONCheck.docx"); +builder.CreateFile("docx"); +var oDocument = Api.GetDocument(); +var oParagraph = oDocument.GetElement(0); +var json = GlobalVariable["RGBColorJSON"]; +var oRGBColorFromJSON = Api.FromJSON(json); +oRGBColorFromJSON.SetDefaultStyle(); +oParagraph.AddElement(oRGBColorFromJSON); +var oParagraph1 = Api.CreateParagraph(); +oDocument.Push(oParagraph1); +oParagraph1.AddText(json); +builder.SaveFile("docx", "RGBColorDocument.docx"); builder.CloseFile(); -///////////////////////// -builder.CreateFile("docx"); -var oDocument = Api.GetDocument(); -var oRGBColor = Api.CreateRGBColor(255, 164, 101); -var json = oRGBColor.ToJSON(); -GlobalVariable["RGBColorJSON"] = json; -var oParagraph = Api.CreateParagraph(); -oParagraph.AddText("JSON representation of RGBColor: " + json); -oDocument.Push(oParagraph); -builder.SaveFile("docx", "RGBColorToJSON.docx"); -builder.CloseFile(); diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index 4135dd978..ea24149be 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -8,16 +8,14 @@ end + it 'ApiRGBColor | ToJSON method' do docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/to_json.js') - json = docx.to_json - parsed_json = JSON.parse(json) - # Проверка наличия ключа 'rgba' для второго цвета - expect(parsed_json['graphic']).not_to be_nil - # Проверка ожидаемых значений красного, зеленого и синего цветов для второго цвета - expect(parsed_json['graphic']['red']).to eq(255) - expect(parsed_json['graphic']['green']).to eq(0) - expect(parsed_json['graphic']['blue']).to eq(0) + p docx + # expect(docx.paragraphs[0].text).to include(GlobalVariable['RGBColorJSON']) + # json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + # expected_rgba = (GlobalVariable['RGBColorJSON'])['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba'] + # expect(json['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba']).to eq(expected_rgba) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c39a5335e..d6f40ff7f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,12 +10,17 @@ # @return [WebDocBuilderWrapper, DocBuilderWrapper] def builder @builder ||= if web_builder? - WebDocBuilderWrapper.new + WebDocBuilderWrapper.new( + jwt_key: 'h6DwLNlgK0ALVDvW8V8FfNJK8NSH6AiZ', + jwt_header: 'Authorization', + documentserver_path: 'http://192.168.100.2' + ) else DocBuilderWrapper.new end end + # @return [String] which platform is used to run builder tests def builder_platform ENV.fetch('BUILDER_PLATFORM', 'DESKTOP')