gitlab-org--gitlab-foss/spec/helpers
Fatih Acet f9d5cb1340 Merge branch '19183-refactor-sidebar-js' into 'master'
Refactor sidebar logic for more predictable behavior

## What does this MR do?

Fixes a few bugs with the sidebar and "pin" functionality:

1. Pinned state would get reset when loading a page with a viewport smaller than 1024px (#19183)
2. Toggle buttons could occasionally end up in an invalid state in which the toggle is hidden from view at the same time the sidebar is collapsed.
    ![2016-09-03-09.39.07](/uploads/75d9a836ab58aae9f89f38cc29e90bbd/2016-09-03-09.39.07.gif)

3. Clicking outside the sidebar to trigger 'collapse' when below the 1024px breakpoint would work only if not pinned, even though pin status should only effect the sidebar above the 1024px breakpoint.
4. Code confusing with no single source of truth for the state of the sidebar.  Sometimes pinned state is inferred from the cookie, sometimes from the DOM.  Code to handle these functions was confusingly split across both `sidebar.js` and `application.js` for no apparent reason.

I've created a singleton ES6 class to handle the sidebar DOM manipulations, using the properties `isExpanded` and `isPinned` as the canonical state and providing a `renderState` method to sync the DOM with this state whenever it needs updating.  This avoids the possibility of invalid states caused by reliance on jQuery `toggleClass()` methods and makes the code much more readable/maintainable.

## Are there points in the code the reviewer needs to double check?

It is a substantial rewrite, so I could use another set of eyes to make sure nothing was left behind from the original implementation.

## Why was this MR needed?

I initially intended to just fix #19183 by modifying the code in place, but it proved to be a difficult mess and rather than add to the technical debt it made sense to write a more readable implementation of the sidebar functionality.

## Does this MR meet the acceptance criteria?

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- Tests
  - [ ] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?

Closes #19183

See merge request !6169
2016-09-07 20:54:49 +00:00
..
application_helper_spec.rb
auth_helper_spec.rb
blob_helper_spec.rb edit_blob_link can receive the blob to avoid access to the repository 2016-08-18 16:30:25 +02:00
broadcast_messages_helper_spec.rb
ci_status_helper_spec.rb
commits_helper_spec.rb
diff_helper_spec.rb
emails_helper_spec.rb
events_helper_spec.rb
form_helper_spec.rb
gitlab_markdown_helper_spec.rb
gitlab_routing_helper_spec.rb
graph_helper_spec.rb
groups_helper_spec.rb
icons_helper_spec.rb
import_helper_spec.rb Don't create groups for unallowed users when importing projects 2016-08-31 12:55:45 -03:00
issuables_helper_spec.rb Changed file name 2016-08-19 15:36:49 +01:00
issues_helper_spec.rb Award tooltips refer to current user as "You" 2016-08-17 21:25:39 +01:00
labels_helper_spec.rb
members_helper_spec.rb
merge_requests_helper_spec.rb
notes_helper_spec.rb Revert unrelevant changes 2016-08-16 10:00:13 +02:00
notifications_helper_spec.rb
page_layout_helper_spec.rb Update Hamlit to 2.6.1 2016-08-18 13:26:32 -05:00
preferences_helper_spec.rb
projects_helper_spec.rb Fix project settings field 2016-09-06 17:37:56 -03:00
runners_helper_spec.rb
search_helper_spec.rb Add failing test for #14360 2016-09-07 15:11:42 +02:00
submodule_helper_spec.rb
tab_helper_spec.rb
time_helper_spec.rb
tree_helper_spec.rb
visibility_level_helper_spec.rb