Welcome to mirror list, hosted at ThFree Co, Russian Federation.

delete_alert_spec.js « details_page « components « explorer « container_registry « packages_and_registries « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9680e273add27c8646ffdfe93fb53172d81099b0 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { GlAlert, GlSprintf, GlLink } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import component from '~/packages_and_registries/container_registry/explorer/components/details_page/delete_alert.vue';
import {
  DELETE_TAG_SUCCESS_MESSAGE,
  DELETE_TAG_ERROR_MESSAGE,
  DELETE_TAGS_SUCCESS_MESSAGE,
  DELETE_TAGS_ERROR_MESSAGE,
  DETAILS_IMPORTING_ERROR_MESSAGE,
  ADMIN_GARBAGE_COLLECTION_TIP,
} from '~/packages_and_registries/container_registry/explorer/constants';

describe('Delete alert', () => {
  let wrapper;

  const findAlert = () => wrapper.find(GlAlert);
  const findLink = () => wrapper.find(GlLink);

  const mountComponent = (propsData) => {
    wrapper = shallowMount(component, { stubs: { GlSprintf }, propsData });
  };

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;
  });

  describe('when deleteAlertType is null', () => {
    it('does not show the alert', () => {
      mountComponent();
      expect(findAlert().exists()).toBe(false);
    });
  });

  describe('when deleteAlertType is not null', () => {
    describe('success states', () => {
      describe.each`
        deleteAlertType   | message
        ${'success_tag'}  | ${DELETE_TAG_SUCCESS_MESSAGE}
        ${'success_tags'} | ${DELETE_TAGS_SUCCESS_MESSAGE}
      `('when deleteAlertType is $deleteAlertType', ({ deleteAlertType, message }) => {
        it('alert exists', () => {
          mountComponent({ deleteAlertType });
          expect(findAlert().exists()).toBe(true);
        });

        describe('when the user is an admin', () => {
          beforeEach(() => {
            mountComponent({
              deleteAlertType,
              isAdmin: true,
              garbageCollectionHelpPagePath: 'foo',
            });
          });

          it(`alert title is ${message}`, () => {
            expect(findAlert().attributes('title')).toBe(message);
          });

          it('alert body contains admin tip', () => {
            expect(findAlert().text()).toMatchInterpolatedText(ADMIN_GARBAGE_COLLECTION_TIP);
          });

          it('alert body contains link', () => {
            const alertLink = findLink();
            expect(alertLink.exists()).toBe(true);
            expect(alertLink.attributes('href')).toBe('foo');
          });
        });

        describe('when the user is not an admin', () => {
          it('alert exist and text is appropriate', () => {
            mountComponent({ deleteAlertType });
            expect(findAlert().exists()).toBe(true);
            expect(findAlert().text()).toBe(message);
          });
        });
      });
    });

    describe('error states', () => {
      describe.each`
        deleteAlertType  | message
        ${'danger_tag'}  | ${DELETE_TAG_ERROR_MESSAGE}
        ${'danger_tags'} | ${DELETE_TAGS_ERROR_MESSAGE}
      `('when deleteAlertType is $deleteAlertType', ({ deleteAlertType, message }) => {
        it('alert exists', () => {
          mountComponent({ deleteAlertType });
          expect(findAlert().exists()).toBe(true);
        });

        describe('when the user is an admin', () => {
          it('alert exist and text is appropriate', () => {
            mountComponent({ deleteAlertType });
            expect(findAlert().exists()).toBe(true);
            expect(findAlert().text()).toBe(message);
          });
        });

        describe('when the user is not an admin', () => {
          it('alert exist and text is appropriate', () => {
            mountComponent({ deleteAlertType });
            expect(findAlert().exists()).toBe(true);
            expect(findAlert().text()).toBe(message);
          });
        });
      });
    });

    describe('importing repository error state', () => {
      beforeEach(() => {
        mountComponent({
          deleteAlertType: 'danger_importing',
          containerRegistryImportingHelpPagePath: 'https://foobar',
        });
      });

      it('alert exist and text is appropriate', () => {
        expect(findAlert().text()).toMatchInterpolatedText(DETAILS_IMPORTING_ERROR_MESSAGE);
      });

      it('alert body contains link', () => {
        const alertLink = findLink();
        expect(alertLink.exists()).toBe(true);
        expect(alertLink.attributes('href')).toBe('https://foobar');
      });
    });

    describe('dismissing alert', () => {
      it('GlAlert dismiss event triggers a change event', () => {
        mountComponent({ deleteAlertType: 'success_tags' });
        findAlert().vm.$emit('dismiss');
        expect(wrapper.emitted('change')).toEqual([[null]]);
      });
    });
  });
});