summaryrefslogtreecommitdiff
path: root/spec/frontend/gitlab_version_check/components/security_patch_upgrade_alert_spec.js
blob: 665dacd5c47adb57c47203bdd74f94e50498c2f2 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { GlAlert, GlButton, GlLink, GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
import SecurityPatchUpgradeAlert from '~/gitlab_version_check/components/security_patch_upgrade_alert.vue';
import { UPGRADE_DOCS_URL, ABOUT_RELEASES_PAGE } from '~/gitlab_version_check/constants';

describe('SecurityPatchUpgradeAlert', () => {
  let wrapper;
  let trackingSpy;

  const defaultProps = {
    currentVersion: '99.9',
  };

  const createComponent = () => {
    trackingSpy = mockTracking(undefined, undefined, jest.spyOn);

    wrapper = shallowMount(SecurityPatchUpgradeAlert, {
      propsData: {
        ...defaultProps,
      },
      stubs: {
        GlAlert,
        GlSprintf,
      },
    });
  };

  afterEach(() => {
    unmockTracking();
  });

  const findGlAlert = () => wrapper.findComponent(GlAlert);
  const findGlButton = () => wrapper.findComponent(GlButton);
  const findGlLink = () => wrapper.findComponent(GlLink);

  describe('template', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders non-dismissible GlAlert with version information', () => {
      expect(findGlAlert().text()).toContain(
        `You are currently on version ${defaultProps.currentVersion}.`,
      );
      expect(findGlAlert().props('dismissible')).toBe(false);
    });

    it('tracks render security_patch_upgrade_alert correctly', () => {
      expect(trackingSpy).toHaveBeenCalledWith(undefined, 'render', {
        label: 'security_patch_upgrade_alert',
        property: defaultProps.currentVersion,
      });
    });

    it('renders GlLink with correct text and link', () => {
      expect(findGlLink().text()).toBe('Learn more about this critical security release.');
      expect(findGlLink().attributes('href')).toBe(ABOUT_RELEASES_PAGE);
    });

    it('tracks click security_patch_upgrade_alert_learn_more when link is clicked', async () => {
      await findGlLink().vm.$emit('click');

      expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_link', {
        label: 'security_patch_upgrade_alert_learn_more',
        property: defaultProps.currentVersion,
      });
    });

    it('renders GlButton with correct text and link', () => {
      expect(findGlButton().text()).toBe('Upgrade now');
      expect(findGlButton().attributes('href')).toBe(UPGRADE_DOCS_URL);
    });

    it('tracks click security_patch_upgrade_alert_upgrade_now when button is clicked', async () => {
      await findGlButton().vm.$emit('click');

      expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_link', {
        label: 'security_patch_upgrade_alert_upgrade_now',
        property: defaultProps.currentVersion,
      });
    });
  });
});