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

project_storage_detail_spec.js « components « storage « usage_quotas « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 364517a474fd04090c702cd691bf5de7c76dda8e (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
import { GlTableLite } from '@gitlab/ui';
import { mount, Wrapper } from '@vue/test-utils'; // eslint-disable-line no-unused-vars
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import ProjectStorageDetail from '~/usage_quotas/storage/components/project_storage_detail.vue';
import { numberToHumanSize } from '~/lib/utils/number_utils';

describe('ProjectStorageDetail', () => {
  /** @type { Wrapper } */
  let wrapper;

  const generateStorageType = (props) => {
    return {
      id: 'id',
      name: 'name',
      description: 'description',
      helpPath: '/help-path',
      detailsPath: '/details-link',
      value: 42,
      ...props,
    };
  };

  const storageTypes = [
    generateStorageType({ id: 'one' }),
    generateStorageType({ id: 'two' }),
    generateStorageType({
      id: 'three',
      warning: {
        content: 'warning message',
      },
    }),
  ];

  const defaultProps = { storageTypes };

  const createComponent = (props = {}) => {
    wrapper = extendedWrapper(
      mount(ProjectStorageDetail, {
        propsData: {
          ...defaultProps,
          ...props,
        },
        provide: {
          containerRegistryPopoverContent: 'Sample popover message',
        },
      }),
    );
  };

  const findTable = () => wrapper.findComponent(GlTableLite);

  beforeEach(() => {
    createComponent();
  });

  describe('with storage types', () => {
    it.each(storageTypes)(
      'renders table row correctly %o',
      ({ id, name, value, description, helpPath, warning }) => {
        expect(wrapper.findByTestId(`${id}-name`).text()).toBe(name);
        expect(wrapper.findByTestId(`${id}-description`).text()).toBe(description);
        expect(wrapper.findByTestId(`${id}-icon`).props('name')).toBe(id);
        expect(wrapper.findByTestId(`${id}-help-link`).attributes('href')).toBe(helpPath);
        expect(wrapper.findByTestId(`${id}-value`).text()).toContain(numberToHumanSize(value, 1));

        expect(wrapper.findByTestId(`${id}-warning-icon`).exists()).toBe(Boolean(warning));
        expect(wrapper.findByTestId(`${id}-popover`).exists()).toBe(Boolean(warning));
      },
    );
  });

  describe('with details links', () => {
    it.each(storageTypes)('each $storageType.id', (item) => {
      const shouldExist = Boolean(item.detailsPath && item.value);
      const detailsLink = wrapper.findByTestId(`${item.id}-details-link`);
      expect(detailsLink.exists()).toBe(shouldExist);
    });
  });

  describe('without storage types', () => {
    beforeEach(() => {
      createComponent({ storageTypes: [] });
    });

    it('should render the table header <th>', () => {
      expect(findTable().find('th').exists()).toBe(true);
    });

    it('should not render any table data <td>', () => {
      expect(findTable().find('td').exists()).toBe(false);
    });
  });
});