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

index_spec.js « pages « explorer « registry « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f52e7d67866e93843b57752972f245365e701e38 (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
import { shallowMount } from '@vue/test-utils';
import { GlAlert, GlSprintf, GlLink } from '@gitlab/ui';
import component from '~/registry/explorer/pages/index.vue';
import store from '~/registry/explorer/stores/';

describe('List Page', () => {
  let wrapper;
  let dispatchSpy;

  const findRouterView = () => wrapper.find({ ref: 'router-view' });
  const findAlert = () => wrapper.find(GlAlert);
  const findLink = () => wrapper.find(GlLink);

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

  beforeEach(() => {
    dispatchSpy = jest.spyOn(store, 'dispatch');
    mountComponent();
  });

  it('has a router view', () => {
    expect(findRouterView().exists()).toBe(true);
  });

  describe('garbageCollectionTip alert', () => {
    beforeEach(() => {
      store.dispatch('setInitialState', { isAdmin: true, garbageCollectionHelpPagePath: 'foo' });
      store.dispatch('setShowGarbageCollectionTip', true);
    });

    afterEach(() => {
      store.dispatch('setInitialState', {});
      store.dispatch('setShowGarbageCollectionTip', false);
    });

    it('is visible when the user is an admin and the user performed a delete action', () => {
      expect(findAlert().exists()).toBe(true);
    });

    it('on dismiss disappears ', () => {
      findAlert().vm.$emit('dismiss');
      expect(dispatchSpy).toHaveBeenCalledWith('setShowGarbageCollectionTip', false);
      return wrapper.vm.$nextTick().then(() => {
        expect(findAlert().exists()).toBe(false);
      });
    });

    it('contains a link to the docs', () => {
      const link = findLink();
      expect(link.exists()).toBe(true);
      expect(link.attributes('href')).toBe(store.state.config.garbageCollectionHelpPagePath);
    });
  });
});