summaryrefslogtreecommitdiff
path: root/spec/javascripts/user_callout_spec.js.es6
blob: c4b7a8ccca228fd06e45fb703f471d9006c8cfde (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
50
51
52
53
54
55
56
57
const UserCallout = require('~/user_callout');

const USER_CALLOUT_COOKIE = 'user_callout_dismissed';
const Cookie = window.Cookies;

describe('UserCallout', function() {
  const fixtureName = 'static/user_callout.html.raw';
  preloadFixtures(fixtureName);

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

    this.userCallout = new UserCallout();
    this.closeButton = $('.close-user-callout');
    this.userCalloutBtn = $('.user-callout-btn');
    this.userCalloutContainer = $('.user-callout');
  });

  it('does not show when cookie is set not defined', () => {
    expect(Cookie.get(USER_CALLOUT_COOKIE)).toBeUndefined();
    expect(this.userCalloutContainer.is(':visible')).toBe(true);
  });

  it('shows when cookie is set to false', () => {
    Cookie.set(USER_CALLOUT_COOKIE, 'false');

    expect(Cookie.get(USER_CALLOUT_COOKIE)).toBeDefined();
    expect(this.userCalloutContainer.is(':visible')).toBe(true);
  });

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

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

describe('UserCallout when cookie is present', function () {
  const fixtureName = 'static/user_callout.html.raw';
  preloadFixtures(fixtureName);

  beforeEach(() => {
    loadFixtures(fixtureName);
    Cookie.set(USER_CALLOUT_COOKIE, 'true');
    this.userCallout = new UserCallout();
    this.userCalloutContainer = $('.user-callout');
  });

  it('removes the DOM element', () => {
    expect(this.userCalloutContainer.length).toBe(0);
  });
});