Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Testing the DOM that templates output #908

Open
arschles opened this issue Feb 8, 2018 · 4 comments
Open

Testing the DOM that templates output #908

arschles opened this issue Feb 8, 2018 · 4 comments
Labels
proposal A suggestion for a change, feature, enhancement, etc
Milestone

Comments

@arschles
Copy link
Contributor

arschles commented Feb 8, 2018

Storytime

A few weeks back, I realized that my templates were a mess, so I went to rewrite a bunch of them. When I did so, I broke a bunch of links and the next release was a big mess. The old Google Analytics chart was down and to the right. Sad face.

I didn't really want to build a whole ui testing thing (like in #888) but I figured something that got me kinda-sorta-almost there would do just fine for now.

My Interim Solution

I reached for goquery and hooked it up to my actions tests. Any time I run a test on an action that outputs HTML, I load that HTML into a goquery document and test some basic things about the structure of the HTML. Mostly, I just wanna make sure that links go to the right place. I'm gonna add some tests to make sure stuff doesn't show up when the user is logged out.

What to Do Now

I have just a little bit of code in a private project right now and it's decently generalized. I figure there's a ton more use cases that folks could come up with.

Any interest in putting the code here, or maybe in suite?

See Also

#888 is about selenium testing. This goquery-based thing would only work on statically output HTML, would not be able to simulate events, and probably a bunch more limitations. It's somewhere between nothing to see here, these are just templates and selenium all the things!

@stanislas-m
Copy link
Member

I'd love to see some examples for that. 👍
For the buffalo integration part, I think you're right, that might be better to have it in the suite project.
In terms of HTML (or even XML) render testing, a complementary solution can be https://github.com/antchfx/xpath (or maybe I'm too old-fashioned). Thoughts?

@arschles
Copy link
Contributor Author

@stanislas-m I'll submit a small PR to the suite library when I get a chance, and link it to here. I'm sad (happy?) to say I never learned much about XPath, so I don't know if it'd be complementary?

@stanislas-m
Copy link
Member

Xpath is a query tool for XML, it's a common solution when you want to extract data from an XML tree. See it as a more general solution, with advanced queries capabilities.

In my opinion, goqueries can be a good solution for simple tests, though.

@arschles
Copy link
Contributor Author

I haven't forgotten about this... I've gotten to the point where the code is fairly generalized and I can extract it fairly easily. Hoping to get this done soon, and thanks so much for being patient!

😄

@stanislas-m stanislas-m added enhancement New feature or request and removed Feature Request labels Apr 16, 2018
@sio4 sio4 added this to the Proposal milestone Sep 27, 2022
@sio4 sio4 added proposal A suggestion for a change, feature, enhancement, etc and removed enhancement New feature or request labels Sep 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
proposal A suggestion for a change, feature, enhancement, etc
Projects
None yet
Development

No branches or pull requests

3 participants