[Karma] Refactor code inside views and tests