summaryrefslogtreecommitdiff
path: root/spec/frontend/registry/explorer/stores/getters_spec.js
blob: cd053ea8edca5c212a4ad5ba3facac4510a94e0f (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
import * as getters from '~/registry/explorer/stores/getters';

describe('Getters RegistryExplorer  store', () => {
  let state;
  const tags = ['foo', 'bar'];

  describe('tags', () => {
    describe('when isLoading is false', () => {
      beforeEach(() => {
        state = {
          tags,
          isLoading: false,
        };
      });

      it('returns tags', () => {
        expect(getters.tags(state)).toEqual(state.tags);
      });
    });

    describe('when isLoading is true', () => {
      beforeEach(() => {
        state = {
          tags,
          isLoading: true,
        };
      });

      it('returns empty array', () => {
        expect(getters.tags(state)).toEqual([]);
      });
    });
  });

  describe.each`
    getter                  | prefix               | configParameter              | suffix
    ${'dockerBuildCommand'} | ${'docker build -t'} | ${'repositoryUrl'}           | ${'.'}
    ${'dockerPushCommand'}  | ${'docker push'}     | ${'repositoryUrl'}           | ${null}
    ${'dockerLoginCommand'} | ${'docker login'}    | ${'registryHostUrlWithPort'} | ${null}
  `('$getter', ({ getter, prefix, configParameter, suffix }) => {
    beforeEach(() => {
      state = {
        config: { repositoryUrl: 'foo', registryHostUrlWithPort: 'bar' },
      };
    });

    it(`returns ${prefix} concatenated with ${configParameter} and optionally suffixed with ${suffix}`, () => {
      const expectedPieces = [prefix, state.config[configParameter], suffix].filter(p => p);
      expect(getters[getter](state)).toBe(expectedPieces.join(' '));
    });
  });

  describe('showGarbageCollection', () => {
    it.each`
      result   | showGarbageCollectionTip | isAdmin
      ${true}  | ${true}                  | ${true}
      ${false} | ${true}                  | ${false}
      ${false} | ${false}                 | ${true}
    `(
      'return $result when showGarbageCollectionTip $showGarbageCollectionTip and isAdmin is $isAdmin',
      ({ result, showGarbageCollectionTip, isAdmin }) => {
        state = {
          config: { isAdmin },
          showGarbageCollectionTip,
        };
        expect(getters.showGarbageCollection(state)).toBe(result);
      },
    );
  });
});