Posts

Showing posts from July, 2012

5 minute guide to using JS PubSub and Noty

5 minute guide to using PubSubJS and Noty A little background, Publish/Subscribe is a design pattern for decoupling components in software (or i guess anywhere in the world). The basic idea is that one thing publishes information to a well known place and another subscribes to it. There is lots of good writing about it out there, check it out on Wikipedia. In my situation we wanted to display page level notifications. I would consider these to be messages that aren't tied to a web widget or element (like a message in a form). Page level notifications can increase the usability of your application (too many or badly placed one can reduce it :) This tutorial will show you a simple way to create a subscriber that publishes messages to the browser using noty. And uses PubSubJS to handle the Publish/Subscribe work. The toolsYou will need a few things for this tutorial. jQueryPubSubJSnoty - jquery pluginGrab them and download, or you can try this shell snippet: mkdir js wget https://r…

Using (Test::?)WWW::Mechanize to test AJAX calls

Test::WWW::Mechanize + AJAX = Love? As we use more and more client side driven forms, testing in a standard way for unit/expanded unit tests becomes more and more difficult.
I've been in the process of creating more use case tests so as underlying components in our system changes those non-web people can verify that their changes don't break the webapp. 
This is often our REST API but can apply to DB changes or modules updates.
I've found this basic code block to work pretty well at using Test::WWW::Mechanize to simulate the situations where there are elements that use client side forms. (AJAX! But really AJAJ since we use JSON instead of XML).

BEGIN { use Test::More; use Test::Exception; use Test::WWW::Mechanize; use JSON; } # # setup test data or load it from db # # # in this test, i login w/ many page, jump to account page # then run ajax form and check json results # { diag "Running login and create user test"; my $mech = Test::WWW::Mechani…