Quick way to access elements built up by render without building a proxy view?

2 views
Skip to first unread message

Vestrit

unread,
Oct 4, 2011, 6:19:04 PM10/4/11
to lebowskifw
I have a bunch of views that are built up via render: function(), but
they are really basic things. For example, one of them is simply 3
divs pushed into the view.

e.g. context.push("<div data-type='a' class= 'z'><img src
='somepath'></img></div>")

I want to quickly access stuff inside without building out the proxys
(mostly because I tried my hand at the proxys and failed miserably) so
I tried something like this

PickerPaneView = App['mainPage.downloader.contentView.picker']

at this point in SC the picker is
'picker:MyApp.myCustomView.design({ contentBinding: blahblah });

I want to be able to say PickerPaneView.data-type.'a'.click or
something. Basically, some way to access the div and click on it. I
tried doing something like PickerPaneView.childViews[0].click etc but
that doesn't work.

This is a reoccurring problem for me where I get really simple views
given to me, but they have the context.push to do something really
basic. Another example is this one

context.push(
'<div class="align">',
'<div class="name"><span class="click">%@</span></
div>'.fmt(title1),
'<div class="date"><span class="click">%@</span></
div>'.fmt(value2),
'<div class="clickable"></div>',
'</div>'
);

and I just want to be able to click on those specific divs. I tried
writing a custom view like here,
https://github.com/FrozenCanuck/Lebowski/blob/master/examples/custom_view/spec/custom_view.rb
for the second one (with a view with two divs that represent nothing
more than name/date) so I could click on them, and it was a mess. Is
there some way to just utilize core_query from the top level and say
"core_query('some div or class property')[0].click" ? I have atleast
30 views that are nothing more than 1-2 divs/spans with a single
string in them, and making proxy views for these seem cumbersome and
mostly pointless. That could also be frustrating speaking. Note I
don't control the SC code given to me, and cannot alter that code at
all. I'm just trying to automate testing of it.

Any guidance would be appreciated

MikeC

unread,
Oct 4, 2011, 7:11:41 PM10/4/11
to lebowskifw
Yep, you can use a view's core_query method at the top level of your
unit tests to interact with specific DOM elements. DOM elements also
get proxied like SC views and can (mostly) be interacted with in the
same way. As an example:

view = app['path.to.some.view']
cq = view.core_query('div.foo-class')
cq.each do |elem|
elem.click
end

-Mike
> writing a custom view like here,https://github.com/FrozenCanuck/Lebowski/blob/master/examples/custom_...
Reply all
Reply to author
Forward
0 new messages