-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add system spec for testing visible columns - chart sync
- Loading branch information
Showing
6 changed files
with
124 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module CupriteHelpers | ||
# Drop #pause anywhere in a test to stop the execution. | ||
# Useful when you want to checkout the contents of a web page in the middle of a test | ||
# running in a headful mode. | ||
def pause | ||
page.driver.pause | ||
end | ||
|
||
# Drop #debug anywhere in a test to open a Chrome inspector and pause the execution | ||
def debug(*args) | ||
page.driver.debug(*args) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require "system_helper" | ||
|
||
RSpec.describe "Admin: Visible Columns and Charts", type: :system do | ||
let(:admin) { create(:admin) } | ||
|
||
before do | ||
country1 = create(:country, name: "Poland") | ||
country2 = create(:country, name: "Germany") | ||
operator1 = create(:operator, fa_id: "FA1", country: country1) | ||
operator2 = create(:operator, fa_id: "FA2", country: country2) | ||
|
||
travel_to 2.days.ago do | ||
create(:operator_document_country, operator: operator1, force_status: "doc_valid") | ||
create(:operator_document_country, operator: operator1) | ||
create(:operator_document_country, operator: operator2, force_status: "doc_valid") | ||
create(:operator_document_country, operator: operator2) | ||
end | ||
|
||
travel_to 1.day.ago do | ||
create(:operator_document_country, operator: operator1, force_status: "doc_valid") | ||
end | ||
|
||
[2.days.ago, Date.yesterday, Date.today].each do |date| | ||
# nil represents all countries | ||
[country1.id, country2.id, nil].each do |country_id| | ||
OperatorDocumentStatistic.generate_for_country_and_day(country_id, date) | ||
end | ||
end | ||
end | ||
|
||
before do | ||
sign_in admin | ||
visit "/admin/producer_documents_dashboards" | ||
end | ||
|
||
it "should sync columns and chart visibility" do | ||
sleep 1 # wait for chart to be rendered | ||
# toggle valid visible column and see if column disappear/appear in table and on the chart | ||
# expect input checkbox to be checked | ||
expect(page).to have_field("valid", checked: true) | ||
expect(page).to have_selector("th.col-valid", visible: true) | ||
expect(get_legend_item("Valid")["hidden"]).to eq(false) | ||
page.uncheck("valid") | ||
expect(page).to have_field("valid", checked: false) | ||
expect(page).to have_selector("th.col-valid", visible: false) | ||
expect(get_legend_item("Valid")["hidden"]).to eq(true) | ||
# toggle valid in chart legend and see if column disappear/appear in table and on the chart and checkbox is changed as well | ||
legend_item_valid_hitbox = get_legend_item_hitbox("Valid") | ||
chart_x = page.evaluate_script("document.getElementById('chart-1').getBoundingClientRect().x") | ||
chart_y = page.evaluate_script("document.getElementById('chart-1').getBoundingClientRect().y") | ||
legend_item_valid_x = chart_x + legend_item_valid_hitbox["left"] + 10 | ||
legend_item_valid_y = chart_y + legend_item_valid_hitbox["top"] + 3 | ||
page.driver.click(legend_item_valid_x, legend_item_valid_y) | ||
expect(page).to have_field("valid", checked: true) | ||
expect(page).to have_selector("th.col-valid", visible: true) | ||
expect(get_legend_item("Valid")["hidden"]).to eq(false) | ||
# once there was something wrong after clicking on the legend item, so test clicking on checkbox again | ||
page.uncheck("valid") | ||
expect(page).to have_field("valid", checked: false) | ||
expect(page).to have_selector("th.col-valid", visible: false) | ||
expect(get_legend_item("Valid")["hidden"]).to eq(true) | ||
end | ||
|
||
def get_legend_item(name) | ||
page.evaluate_script("Chartkick.charts['chart-1'].chart.legend.legendItems.find(x => x.text === '#{name}')") | ||
end | ||
|
||
def get_legend_item_hitbox(name) | ||
legend_item = get_legend_item(name) | ||
page.evaluate_script("Chartkick.charts['chart-1'].chart.legend.legendHitBoxes[#{legend_item["datasetIndex"]}]") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters