summaryrefslogtreecommitdiff
path: root/spec/javascripts/user_callout_spec.js
blob: 69cb93bd8507229cf5f17f0e46f6317546dcab12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Cookies from 'js-cookie';
import UserCallout from '~/user_callout';

const USER_CALLOUT_COOKIE = 'user_callout_dismissed';

describe('UserCallout', function () {
  const fixtureName = 'dashboard/user-callout.html.raw';
  preloadFixtures(fixtureName);

  beforeEach(() => {
    loadFixtures(fixtureName);
    Cookies.remove(USER_CALLOUT_COOKIE);

    this.userCallout = new UserCallout();
    this.closeButton = $('.js-close-callout.close');
    this.userCalloutBtn = $('.js-close-callout:not(.close)');
  });

  it('hides when user clicks on the dismiss-icon', (done) => {
    this.closeButton.click();
    expect(Cookies.get(USER_CALLOUT_COOKIE)).toBe('true');

    setTimeout(() => {
      expect(
        document.querySelector('.user-callout'),
      ).toBeNull();

      done();
    });
  });

  it('hides when user clicks on the "check it out" button', () => {
    this.userCalloutBtn.click();
    expect(Cookies.get(USER_CALLOUT_COOKIE)).toBe('true');
  });

  describe('Sets cookie with setCalloutPerProject', () => {
    beforeEach(() => {
      spyOn(Cookies, 'set').and.callFake(() => {});
      document.querySelector('.user-callout').setAttribute('data-project-path', 'foo/bar');
      this.userCallout = new UserCallout({ setCalloutPerProject: true });
    });

    it('sets a cookie when the user clicks the close button', () => {
      this.userCalloutBtn.click();
      expect(Cookies.set).toHaveBeenCalledWith('user_callout_dismissed', 'true', Object({ expires: 365, path: 'foo/bar' }));
    });
  });
});