Files
discourse/spec/system/capabilities_service_spec.rb
David Taylor 19e93142e4 DEV: Introduce reactive JS API for viewport size (#32060)
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.
2025-04-30 15:26:59 +01:00

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