Some refactoring, and unit test for 'topnavbar' directive