My latest project is something I call “LJ Content Sieve”: a Greasemonkey script to filter out content on one’s Livejournal views based on nearly any attribute of a post or comment.
However, Livejournal is very customizable. It has 31 different “layouts”, each of which can then be further “themed” by application of CSS. This means that a user viewing a given journal, community, or single post, at a given time, may receive an HTML document containing any of 31 different DOM structures.
This means that finding a post’s author, or title, or even just a single post or comment, is not a straightforward process. I’ve set myself up a Ruby script that downloaded my “friends” view, a representative entry with lots of comments, and my own journal view, thus giving me a set of 93 fixtures that I can test against. The Ruby script also tweaked each fixture in the process of spooling it to my hard drive, by adding the proper calls to JSUnit files.
At the end of each document’s <head> element, there’s a call to
jsUnitCore.js. Then, at the end of each <body>, I add a call to the
lj-content-sieve.user.js script itself, as well as a set of test files that depends on which fixture this is. Every fixture gets an
ljcs-global-tests.js call added to it — that file contains tests that should work anywhere, regardless of what sort of page you’re on.
Then all the “friends” page fixtures get an
ljcs-friends-tests.js file, which tests operations that should happen on every friends page. For example, determining which entries need to be deleted. (In contrast, single-entry pages get
ljcs-entry-tests.js, and the page from my own journal — which stands in for a view of a community — gets
Finally, each fixture page gets a test file based on its layout: the “3 Column” layout gets
ljcs-3 Column-tests.js, while “Cuteness Attack” gets
ljcs-Cuteness Attack-tests.js. (Hey, I didn’t write or name the layouts; I just have to make sure LJCS works with all of ‘em.) These files will test that the actual DOM manipulations work properly.
Without test-driven development and automated testing to ensure that each layout and page-type is being handled properly, I don’t think this project would be manageable at all.
Originally published at Coyote Tracks. You can comment here or there.