Fix deselect publishing an event, even if it wasn't previously selected.

Check previous value before enqueuing a deselect event.
Add tests for select and deselect events.