Fix error on view event and add unit test