Skip to content

Commit

Permalink
11058: add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
chahmedejaz committed May 9, 2024
1 parent 86f8879 commit b5fe19c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/views/admin/products_v3/_content.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%turbo-frame#products-content{ target: "_top", refresh: "morph" }
.spinner-overlay.hidden
.spinner-overlay{ "data-controller": "loading", "data-products-target": "loading", class: "hidden" }
.spinner-container
.spinner
= t('.loading')
Expand Down
27 changes: 25 additions & 2 deletions spec/system/admin/products_v3/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,43 @@
describe "sorting" do
let!(:product_b) { create(:simple_product, name: "Bananas") }
let!(:product_a) { create(:simple_product, name: "Apples") }
let(:products_table) { "table.products" }

before do
visit admin_products_url
end

it "Should sort products alphabetically by default" do
within "table.products" do
it "Should sort products alphabetically by default in ascending order" do
within products_table do
# Gather input values, because page.content doesn't include them.
input_content = page.find_all('input[type=text]').map(&:value).join

# Products are in correct order.
expect(input_content).to match /Apples.*Bananas/
end
end

context "when clicked on 'Name' column header" do
it "Should sort products alphabetically in descending/ascending order" do
within products_table do
name_header = page.find('th > a[data-column="name"]')

# Sort in descending order
name_header.click
expect(page).to have_content("Name ▼") # this indicates the re-sorted content has loaded

input_content = page.find_all('input[type=text]').map(&:value).join
expect(input_content).to match /Bananas.*Apples/

# Sort in ascending order
name_header.click
expect(page).to have_content("Name ▲") # this indicates the re-sorted content has loaded

input_content = page.find_all('input[type=text]').map(&:value).join
expect(input_content).to match /Apples.*Bananas/
end
end
end
end

describe "pagination" do
Expand Down

0 comments on commit b5fe19c

Please sign in to comment.