diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2018-08-28 18:19:52 +0200 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2018-10-02 11:12:22 +0200 |
commit | 23563f5e0a5f3875289569126562f0f2fc63d3a6 (patch) | |
tree | dc7b3935d22f7ad12ef2508b0713e24780d7d95c /spec/javascripts | |
parent | 7c1cfd0bf5fd394e0e4387e350d69767aa873f84 (diff) | |
download | gitlab-ce-23563f5e0a5f3875289569126562f0f2fc63d3a6.tar.gz |
Highlight current user in comments and system notes
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/behaviors/markdown/highlight_current_user_spec.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/javascripts/behaviors/markdown/highlight_current_user_spec.js b/spec/javascripts/behaviors/markdown/highlight_current_user_spec.js new file mode 100644 index 00000000000..3305ddc412d --- /dev/null +++ b/spec/javascripts/behaviors/markdown/highlight_current_user_spec.js @@ -0,0 +1,55 @@ +import highlightCurrentUser from '~/behaviors/markdown/highlight_current_user'; + +describe('highlightCurrentUser', () => { + let rootElement; + let elements; + + beforeEach(() => { + setFixtures(` + <div id="dummy-root-element"> + <div data-user="1">@first</div> + <div data-user="2">@second</div> + </div> + `); + rootElement = document.getElementById('dummy-root-element'); + elements = rootElement.querySelectorAll('[data-user]'); + }); + + describe('without current user', () => { + beforeEach(() => { + window.gon = window.gon || {}; + window.gon.current_user_id = null; + }); + + afterEach(() => { + delete window.gon.current_user_id; + }); + + it('does not highlight the user', () => { + const initialHtml = rootElement.outerHTML; + + highlightCurrentUser(elements); + + expect(rootElement.outerHTML).toBe(initialHtml); + }); + }); + + describe('with current user', () => { + beforeEach(() => { + window.gon = window.gon || {}; + window.gon.current_user_id = 2; + }); + + afterEach(() => { + delete window.gon.current_user_id; + }); + + it('highlights current user', () => { + highlightCurrentUser(elements); + + expect(elements.length).toBe(2); + expect(elements[0]).not.toHaveClass('current-user'); + expect(elements[1]).toHaveClass('current-user'); + }); + }); +}); |