Skip to content

Commit

Permalink
feature: refactoring
Browse files Browse the repository at this point in the history
commit 1
fix specs: product_creation_spec.rb and product_groups_spec.rb
  • Loading branch information
KirillGaliulin committed Jan 12, 2024
1 parent f05fa5f commit 9ad2c9a
Show file tree
Hide file tree
Showing 27 changed files with 1,381 additions and 800 deletions.
28 changes: 27 additions & 1 deletion lib/apress/selenium_eti.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# frozen_string_literal: true

# Упорядоченный рекваир. Небходимо сначала подключать неймспейсы, иначе будут ошибки при инициализации.
gem_directory = Gem::Specification.find_by_name("apress-selenium_eti").gem_dir
Dir["#{gem_directory}/lib/pages/**/*.rb"].each { |file| require file }

# ЕТИ
require "#{gem_directory}/lib/pages/company_site/eti/eti"
require "#{gem_directory}/lib/pages/company_site/eti/table"
require "#{gem_directory}/lib/pages/company_site/eti/action_panel"
require "#{gem_directory}/lib/pages/company_site/eti/header"
require "#{gem_directory}/lib/pages/company_site/eti/table_products"
require "#{gem_directory}/lib/pages/company_site/eti/table_status_bar"
require "#{gem_directory}/lib/pages/company_site/eti/navigation_column"

# Попапы
require "#{gem_directory}/lib/pages/company_site/eti/popups/description_popup"
require "#{gem_directory}/lib/pages/company_site/eti/popups/groups_binding_popup"
require "#{gem_directory}/lib/pages/company_site/eti/popups/images_upload_popup"
require "#{gem_directory}/lib/pages/company_site/eti/popups/price_popup"
require "#{gem_directory}/lib/pages/company_site/eti/popups/public_state_popup"
require "#{gem_directory}/lib/pages/company_site/eti/popups/rubrics_binding_popup"
require "#{gem_directory}/lib/pages/company_site/eti/popups/traits_popup"
require "#{gem_directory}/lib/pages/company_site/eti/popups/wholesale_price_popup"
require "#{gem_directory}/lib/pages/company_site/eti/popups/exists_popup"

# Мини-ЕТИ.
require "#{gem_directory}/lib/pages/company_site/mini_eti/mini_eti"
require "#{gem_directory}/lib/pages/company_site/mini_eti/pagination"
115 changes: 53 additions & 62 deletions lib/apress/selenium_eti/spec/company_site/eti/product_creation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,107 +2,98 @@

describe 'ЕТИ' do
before(:all) do
@cs_eti_page = CompanySite::EtiPage.new
@cs_main_page = CompanySite::MainPage.new
@cs_eti_table = CompanySite::ETI::Table.new
@cs_eti_table_products = CompanySite::ETI::Table::Products.new
@cs_eti_header = CompanySite::ETI::Header.new
@cs_main_page = CompanySite::MainPage.new

log_in_as(:user)
navigate_to_eti
@cs_main_page.close_banner
@cs_eti_page.close_support_contacts if @cs_eti_page.close_support_contacts?
@cs_eti_table.close_support_contacts if @cs_eti_table.close_support_contacts?(2)
end

describe 'Создание товара' do
context 'когда товар без рубрики' do
before(:all) do
@name = Faker::Number.leading_zero_number(digits: 5).to_s
@cs_eti_page.add_product
@cs_eti_page.set_name(@name)
@cs_eti_page.wait_saving
@cs_eti_page.refresh
@cs_eti_page.search_product(@name)
@cs_eti_table_products.add_product(name: @name)
@cs_eti_header.search_product(@name, exact: true)
@product = @cs_eti_table_products.product(name: @name)
end

it 'введенное имя отображается' do
expect(@cs_eti_page.product_name?(@name)).to be true
end
after(:all) { @cs_eti_table_products.delete_product(@product) }

it('введенное имя отображается') { expect(@cs_eti_table_products.name(@product)).to eq(@name) }

# Определяется через локатор какой проект, и в зависимости
# от этого ожидаемый результат. Если ни один из локаторов
# проектов не найден, то выводится ошибка 'locator not found'
it 'товар не опубликован на портале' do
if @cs_eti_page.project_pulscen?
expect(@cs_eti_page.product_archived?(@name)).to be true
elsif @cs_eti_page.project_blizko?
expect(@cs_eti_page.product_unpublished?(@name)).to be true
if @cs_eti_table.project_pulscen?
expect(@cs_eti_table_products.public_state(@product)).to eq(:archived)
elsif @cs_eti_table.project_blizko?
expect(@cs_eti_table_products.public_state(@product)).to eq(:unpublished)
else
raise ArgumentError, 'locator not found'
end
end

after(:all) { @cs_eti_page.delete_product(@name) }
end

context 'когда товар с рубрикой' do
before(:all) do
@name = Faker::Number.number(digits: 5).to_s
@cs_eti_page.add_product
@cs_eti_page.set_name(@name)
@cs_eti_page.wait_saving
@cs_eti_page.set_rubric(CONFIG['eti']['rubric'])
@cs_eti_page.wait_until { @cs_eti_page.first_product_status_element.attribute('title') == 'Опубликованные на портале' }
@cs_eti_page.refresh
@cs_eti_page.search_product(@name)
end

it 'введенное имя отображается' do
expect(@cs_eti_page.product_name?(@name)).to be true
end

it 'рубрика привязана' do
expect(@cs_eti_page.product_rubric_tree(@name)).to include CONFIG['eti']['rubric']
@name = Faker::Number.leading_zero_number(digits: 5).to_s
@cs_eti_table_products.add_product(name: @name, rubric: CONFIG['eti']['rubric'])
@cs_eti_header.search_product(@name, exact: true)
@product = @cs_eti_table_products.product(name: @name)
end

it 'товар опубликован' do
expect(@cs_eti_page.product_published?(@name)).to be true
end
after(:all) { @cs_eti_table_products.delete_product(@product) }

after(:all) { @cs_eti_page.delete_product(@name) }
it('введенное имя отображается') { expect(@cs_eti_table_products.name(@product)).to eq(@name) }
it('рубрика привязана') { expect(@cs_eti_table_products.rubric(@product)).to include(CONFIG['eti']['rubric']) }
it('товар опубликован') { expect(@cs_eti_table_products.public_state(@product)).to eq(:published) }
end

context 'когда копируем товар' do
before(:all) do
@product = {
name: Faker::Number.leading_zero_number(digits: 5),
@fields = {
name: Faker::Number.leading_zero_number(digits: 10).to_s,
rubric: CONFIG['eti']['rubric'],
exists: CONFIG['eti']['exists']['in stock'],
short_description: CONFIG['product_creation']['short_description']['valid'],
description: 'description',
price_from_to: {from: Faker::Number.number(digits: 3), to: Faker::Number.number(digits: 4)},
wholesale_price: {wholesale_price: Faker::Number.number(digits: 2), wholesale_number: Faker::Number.number(digits: 2)}
}

@portal_traits = {
trait_1: CONFIG['eti']['portal_traits']['trait_value_1'],
trait_2: CONFIG['eti']['portal_traits']['trait_value_2']
traits: {
CONFIG['eti']['portal_traits']['trait_1'] => CONFIG['eti']['portal_traits']['trait_value_1'],
CONFIG['eti']['portal_traits']['trait_2'] => CONFIG['eti']['portal_traits']['trait_value_2'],
},
announce: Faker::Movies::Hobbit.quote,
description: Faker::Movies::Hobbit.quote,
price: {
type: :range,
price: Faker::Number.number(digits: 3),
price_max: Faker::Number.number(digits: 4),
},
wholesale_price: {
price: Faker::Number.number(digits: 2),
min_qty: Faker::Number.number(digits: 2),
},
exists: :available,
}

@cs_eti_page.create_and_set_product_fields(@product)
@cs_eti_page.refresh
@cs_eti_page.search_product(@product[:name])
@cs_eti_page.set_portal_traits(@product[:name], @portal_traits)
@cs_eti_page.copy_product(@product[:name])

# TODO: Расскоментить после фикса https://jira.railsc.ru/browse/GOODS-3568
# сейчас заккомментировал строки, чтобы озеленить спек
# @cs_eti_page.refresh
# @cs_eti_page.search_product(@product[:name])
@product = @cs_eti_table_products.add_product(@fields)
@cs_eti_table_products.copy_product(@product)
@cs_eti_header.search_product(@fields[:name], exact: true)
end

it 'отобразится 2 идентичных товара' do
@first_product = @cs_eti_page.product_rows_elements[0].text
expect(@cs_eti_table_products.products_elements.size).to eq(2)
expect(@cs_eti_table_products.products_elements[0].text).to eq(@cs_eti_table_products.products_elements[1].text)
end

expect(@cs_eti_page.product_rows_elements.length).to eq 2
expect(@cs_eti_page.product_rows_elements[1].text).to eq @first_product
after(:all) do
2.times do
@cs_eti_header.search_product(@fields[:name], exact: true)
product = @cs_eti_table_products.product(name: @fields[:name])
@cs_eti_table_products.delete_product(product)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,51 @@

describe 'ЕТИ' do
before(:all) do
@cs_eti_page = CompanySite::EtiPage.new
@cs_main_page = CompanySite::MainPage.new
@cs_eti_table = CompanySite::ETI::Table.new
@cs_eti_header = CompanySite::ETI::Header.new
@cs_eti_table_products = CompanySite::ETI::Table::Products.new
@cs_eti_navigation_column = CompanySite::ETI::NavigationColumn.new
@cs_main_page = CompanySite::MainPage.new

log_in_as(:user)
navigate_to_eti
@cs_main_page.close_banner
@cs_eti_table.close_support_contacts if @cs_eti_table.close_support_contacts?(2)

@group1 = CONFIG['product_creation']['group']
@group2 = CONFIG['product_creation']['group_2']
end

describe 'Добавление групп' do
context 'когда привязываем группу к товару' do
before(:all) do
@product = {name: Faker::Number.leading_zero_number(digits: 5).to_s}
@cs_eti_page.create_and_set_product_fields(@product)
@cs_eti_page.navigate_to_groups_element.click
sleep 2
@cs_eti_page.set_group(CONFIG['product_creation']['group'])
@cs_eti_page.wait_saving
@cs_eti_page.refresh
@cs_eti_page.search_product(@product[:name])
@cs_eti_navigation_column.navigate_to_groups
@name = Faker::Number.leading_zero_number(digits: 5)
@cs_eti_table_products.add_product(name: @name, group: @group1)
@cs_eti_header.search_product(@name, exact: true)
@product = @cs_eti_table_products.product(name: @name)
end

it 'группа привязывается' do
expect(@cs_eti_page.group_cell).to eq CONFIG['product_creation']['group']
expect(@cs_eti_table_products.group(@product)).to eq @group1
end

context 'когда выбираем другую группу' do
before do
@cs_eti_page.set_group(CONFIG['product_creation']['group_2'])
@cs_eti_page.wait_saving
@cs_eti_page.refresh
@cs_eti_table_products.set_group(@product, @group2)
@cs_eti_header.search_product(@name, exact: true)
@product = @cs_eti_table_products.product(name: @name)
end

it 'группа меняется на новую' do
expect(@cs_eti_page.group_cell).to eq CONFIG['product_creation']['group_2']
expect(@cs_eti_table_products.group(@product)).to eq @group2
end
end

after(:all) { @cs_eti_page.delete_product(@product[:name]) }
after(:all) do
product = @cs_eti_table_products.product(name: @name)
@cs_eti_table_products.delete_product(product)
end
end
end
end
Loading

0 comments on commit 9ad2c9a

Please sign in to comment.