discourse-adplugin/spec/system/admin_house_ad_spec.rb
Osama Sayegh c2057a5056
FEATURE: Add per-ad visibility settings for anons and logged-in users (#168)
This commit adds 2 new settings to house ads to control whether an ad is shown to anonymous users and logged in users. Existing ads that were created before this feature will default to true for both settings; i.e., they will remain to be visible to both anonymous and logged-in users, but it will be possible to change the settings. Turning off both settings will effectively disable the ad completely.
2023-04-07 17:56:22 +03:00

38 lines
1.3 KiB
Ruby

# frozen_string_literal: true
describe "Admin House Ad", type: :system, js: true do
fab!(:admin) { Fabricate(:admin) }
let(:house_ad) do
AdPlugin::HouseAd.create(
name: "some-name",
html: "<div>somecode</div>",
visible_to_anons: true,
visible_to_logged_in_users: false,
)
end
before { sign_in(admin) }
describe "when visiting the page for creating new ads" do
it "should have the visibility checkboxes on by default" do
visit("/admin/plugins/pluginad/house_creatives/new")
expect(find("input.visible-to-anonymous-checkbox").checked?).to eq(true)
expect(find("input.visible-to-logged-in-checkbox").checked?).to eq(true)
end
end
describe "when visiting the page of an existing ad" do
it "the controls reflect the correct state of the ad" do
visit("/admin/plugins/pluginad/house_creatives/#{house_ad.id}")
expect(find("input.house-ad-name").value).to eq(house_ad.name)
expect(find("input.visible-to-anonymous-checkbox").checked?).to eq(true)
expect(find("input.visible-to-logged-in-checkbox").checked?).to eq(false)
# would be nice to assert for the HTML content in ace-editor, but there
# doesn't seem to be a way to check the content in ace-editor from the
# DOM
end
end
end