Skip to content

added specs for component access tp action view context and added acc… #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/concepts/matestack/ui/core/app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class App < Trailblazer::Cell
include Matestack::Ui::Core::Cell
include Matestack::Ui::Core::ApplicationHelper
include Matestack::Ui::Core::ToCell
include Matestack::Ui::Core::HasViewContext

view_paths << "#{Matestack::Ui::Core::Engine.root}/app/concepts"

Expand Down
6 changes: 5 additions & 1 deletion app/concepts/matestack/ui/core/page/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ def show(component_key=nil, only_page=false)
nodes_to_cell
render :page
when :render_page_with_app
concept(@app_class).call(:show, @page_id, @nodes)
@app_class.new(nil, context: {
params: options[:context][:params],
request: options[:context][:request],
view_context: options[:context][:view_context]
}, controller_instance: options[:controller_instance]).call(:show, @page_id, @nodes)
when :render_component
begin
render_child_component component_key
Expand Down
17,049 changes: 17,049 additions & 0 deletions spec/dummy/public/packs-test/js/application-523107e3f7258f36c3ed.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*!
* Vue.js v2.6.10
* (c) 2014-2019 Evan You
* Released under the MIT License.
*/

/**
* vuex v3.1.1
* (c) 2019 Evan You
* @license MIT
*/
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
14 changes: 14 additions & 0 deletions spec/dummy/public/packs-test/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"application.js": "/packs-test/js/application-523107e3f7258f36c3ed.js",
"application.js.map": "/packs-test/js/application-523107e3f7258f36c3ed.js.map",
"entrypoints": {
"application": {
"js": [
"/packs-test/js/application-523107e3f7258f36c3ed.js"
],
"js.map": [
"/packs-test/js/application-523107e3f7258f36c3ed.js.map"
]
}
}
}
Binary file added spec/dummy/public/packs-test/manifest.json.gz
Binary file not shown.
3 changes: 3 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
require "matestack/ui/core"


Capybara.server_port = 33123
Capybara.server_host = "0.0.0.0"


# Capybara.app = Matestack::Ui::Core::Engine
Capybara.app = Dummy::Application
Expand Down
54 changes: 54 additions & 0 deletions spec/usage/base/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,60 @@ def page2

end

it "has access to view context" do

class Apps::ExampleApp < Matestack::Ui::App

def response
components {
heading size: 1, text: "My Example App Layout"
if @view_context.view_renderer.instance_of?(ActionView::Renderer)
plain "has access to ActionView Context"
end
plain link_to "Test Link", "/some/page" # calling an ActionView Url Helper here
plain time_ago_in_words(3.minutes.from_now) # calling an ActionView Date Helper here
main do
page_content
end
}
end

end

module Pages::ExampleApp

end

class Pages::ExampleApp::ExamplePage < Matestack::Ui::Page

def response
components {
div id: "my-div-on-page-1" do
heading size: 2, text: "This is Page 1"
end
}
end

end


class ExampleAppPagesController < ExampleController
include Matestack::Ui::Core::ApplicationHelper

def page1
responder_for(Pages::ExampleApp::ExamplePage)
end

end

visit "app_specs/my_example_app/page1"

expect(page).to have_content("has access to ActionView Context")
expect(page).to have_content("Test Link")
expect(page).to have_content("3 minutes")

end

it "can navigate back using browser history"

it "just uses serverside routes, which works standalone"
Expand Down
96 changes: 96 additions & 0 deletions spec/usage/base/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,102 @@ def response

end

describe "View Context Access" do

it "a component can access view context scope" do

module Matestack::Ui::Core::SomeStaticComponent
class SomeStaticComponent < Matestack::Ui::StaticComponent

def response
components {
div id: "my-component" do
if @view_context.view_renderer.instance_of?(ActionView::Renderer)
plain "has access to ActionView Context"
end
plain link_to "Test Link", "/some/page" # calling an ActionView Url Helper here
plain time_ago_in_words(3.minutes.from_now) # calling an ActionView Date Helper here
end
}
end

end
end

class Pages::ExamplePage < Matestack::Ui::Page

def response
components {
div id: "div-on-page" do
someStaticComponent
end
}
end

end

visit "/component_test"

expect(page).to have_content("has access to ActionView Context")
expect(page).to have_content("Test Link")
expect(page).to have_content("3 minutes")

end

it "a component can access view context scope when rerendered via async" do

module Matestack::Ui::Core::SomeStaticComponent
class SomeStaticComponent < Matestack::Ui::StaticComponent

def response
components {
div id: "my-component" do
div id: "timestamp" do
plain "#{DateTime.now.strftime('%Q')}"
end
if @view_context.view_renderer.instance_of?(ActionView::Renderer)
plain "has access to ActionView Context"
end
plain link_to "Test Link", "/some/page" # calling an ActionView Url Helper here
plain time_ago_in_words(3.minutes.from_now) # calling an ActionView Date Helper here
end
}
end

end
end

class Pages::ExamplePage < Matestack::Ui::Page

def response
components {
div id: "div-on-page" do
async rerender_on: "some_event" do
someStaticComponent
end
end
}
end

end

visit "/component_test"

element = page.find("#timestamp")
before_content = element.text

page.execute_script('MatestackUiCore.matestackEventHub.$emit("some_event")')

expect(page).not_to have_content(before_content)# check if async reload has really worked!

expect(page).to have_content("has access to ActionView Context")
expect(page).to have_content("Test Link")
expect(page).to have_content("3 minutes")

end

end

describe "Doesn't have Controller Action Scope Access"

describe "Default Tag Attributes"
Expand Down
41 changes: 41 additions & 0 deletions spec/usage/base/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,47 @@ def my_action

end

it "can access ActionView Context" do

class ExamplePage < Matestack::Ui::Page

def response
components {
div do
plain @bar
if @view_context.view_renderer.instance_of?(ActionView::Renderer)
plain "has access to ActionView Context"
end
plain link_to "Test Link", "/some/page" # calling an ActionView Url Helper here
plain time_ago_in_words(3.minutes.from_now) # calling an ActionView Date Helper here
end
}
end

end


class PageTestController < ActionController::Base
layout "application"

include Matestack::Ui::Core::ApplicationHelper

def my_action
@bar = "bar"
responder_for(ExamplePage)
end

end

visit "/page_test"

expect(page).to have_content("bar")
expect(page).to have_content("has access to ActionView Context")
expect(page).to have_content("Test Link")
expect(page).to have_content("3 minutes")

end

it "can resolve data in a prepare method, which runs before rendering"

it "can use classic ruby within component orchestration"
Expand Down