mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 11:11:13 +08:00

Usage: ```js @service capabilities; ... this.capabilities.viewport.sm; // True when viewport is sm or larger this.capabilities.viewport.md; // True when viewport is md or larger // etc. ``` These booleans will update live when the browser is resized. Therefore, they should only be used in an autotracking context, so that Ember will re-render things appropriately when they change.
25 lines
602 B
Ruby
25 lines
602 B
Ruby
# frozen_string_literal: true
|
|
|
|
describe "capabilities service", type: :system do
|
|
describe "viewport helpers" do
|
|
it "works" do
|
|
def matches(name)
|
|
page.evaluate_script("Discourse.lookup('service:capabilities').viewport[#{name.to_json}]")
|
|
end
|
|
|
|
visit "/"
|
|
expect(page).to have_css("#site-logo")
|
|
|
|
expect(matches("sm")).to eq(true)
|
|
expect(matches("lg")).to eq(true)
|
|
|
|
resize_window(width: 700) do
|
|
try_until_success do
|
|
expect(matches("sm")).to eq(true)
|
|
expect(matches("lg")).to eq(false)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|