natgeo/modules-activitysnippet — pull request #5 by jleja (2014-03-10 19:58:26+00:00)
Title: [MIE-805] - Accept arrays of functions in ActivityStreamFactory config f...

...or active and inactive callbacks; bind callbacks to snippets; fire callbacks based on active state; update documentation, unit tests, and demo page.

https://ngjira.nationalgeographic.com/browse/MIE-805

NEW: Ability to pass in arrays of functions for inactive and active states
NEW: Fire callbacks when snippet is clicked based on active state
CHANGED: Removed unnecessary code relating to this feature that was started in another branch
CHANGED: Some code cleanup/formatting
CHANGED: Remove leftover console.logs

TO TEST:
- Ensure Activity Streams service is running (~/code/activitystreams)
- Ensure Neo4j database is running (http://localhost:7474)
- Switch to base of this repo (~/code/modules-activitysnippet)
- grunt test (see expected results below)
- grunt serve
- You should see a welcome message "Hello anonymous user"
- Click on a snippet. You should see an alert message "Inactive Callback Fired"
- Click on the button "Toggle User State"
- The welcome message should change to "Hello active user"
- Click on a snippet. You should see an alert message "Active Callback Fired"
- Click on the button "Toggle User State"
- You should see a welcome message "Hello anonymous user"
- Click on a snippet. You should see an alert message "Inactive Callback Fired"

KNOWN ISSUES:
- Toggling from an active user to an inactive user does not change the status of the active snippets (i.e. the ones that are clicked because the active user had previously interacted with it). Breaking out into another ticket, MIE-823 as it is functionality outside of the scope of this ticket.

UNIT TEST RESULTS:
Unit Testing Activity Stream Factory:
Initialization
✓ should not be able to initialize without the service endpoint
✓ should have some internal defaults
✓ should allow for overriding the internal defaults by accepting config
✓ should be able to find the amount of snippets on the page
✓ should instantiate ActivityStreamSnippet objects for every element on the page
✓ should give an id to every snippet on the page
Handle lazy loading of snippets
✓ should be able to find new elements on the page when refresh is called
State Management
✓ should allow to toggle state
✓ should switch snippet(s) state on factory toggle
Actor Management
✓ should allow setting a different actor
✓ should set the new actor on all the snippets

Unit Testing of Activty Stream Snippet
Instantization
✓ Takes an element, ActivityStreamAPI and templates objects
✓ should throw excpetion when element is not passed in
✓ should throw exception when templates object is not passed in
✓ should throw exception when setting object is not passed in
State Management
✓ should be able to toggle active state
✓ should be able to set actor
Service Calls
✓ should be able to construct fetch url
✓ should be able to construct fetch url given an actor
✓ should be able to construct JSON object for saving
✓ should be able to fetch empty data
✓ should be able to fetch some data
✓ should be able to fetch data given an actor
◦ should be able to post a new activity given an actor: [object Object]
✓ should be able to post a new activity given an actor
✓ firing callbacks should be able to gracefully handle not having callbacks defined
✓ should be able to fire a callback
View Rendering
✓ should be able to update view given new counts
✓ should be able to return 0 counts

28 passing (110ms)

Per-File Coverage Results: (80% minimum)
PASS : 2 files passed coverage

Unit Test Results: 28 specs passed! (0.11s)
>> No issues found.

Done, without errors.