summaryrefslogtreecommitdiff
path: root/spec/frontend/releases/components/app_show_spec.js
blob: 181fa0150f1759766907a5a3c08123f35611eeca (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
import Vuex from 'vuex';
import { shallowMount } from '@vue/test-utils';
import { getJSONFixture } from 'helpers/fixtures';
import ReleaseShowApp from '~/releases/components/app_show.vue';
import ReleaseSkeletonLoader from '~/releases/components/release_skeleton_loader.vue';
import ReleaseBlock from '~/releases/components/release_block.vue';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';

const originalRelease = getJSONFixture('api/releases/release.json');

describe('Release show component', () => {
  let wrapper;
  let release;
  let actions;

  beforeEach(() => {
    release = convertObjectPropsToCamelCase(originalRelease);
  });

  const factory = state => {
    actions = {
      fetchRelease: jest.fn(),
    };

    const store = new Vuex.Store({
      modules: {
        detail: {
          namespaced: true,
          actions,
          state,
        },
      },
    });

    wrapper = shallowMount(ReleaseShowApp, { store });
  };

  const findLoadingSkeleton = () => wrapper.find(ReleaseSkeletonLoader);
  const findReleaseBlock = () => wrapper.find(ReleaseBlock);

  it('calls fetchRelease when the component is created', () => {
    factory({ release });
    expect(actions.fetchRelease).toHaveBeenCalledTimes(1);
  });

  it('shows a loading skeleton and hides the release block while the API call is in progress', () => {
    factory({ isFetchingRelease: true });
    expect(findLoadingSkeleton().exists()).toBe(true);
    expect(findReleaseBlock().exists()).toBe(false);
  });

  it('hides the loading skeleton and shows the release block when the API call finishes successfully', () => {
    factory({ isFetchingRelease: false });
    expect(findLoadingSkeleton().exists()).toBe(false);
    expect(findReleaseBlock().exists()).toBe(true);
  });

  it('hides both the loading skeleton and the release block when the API call fails', () => {
    factory({ fetchError: new Error('Uh oh') });
    expect(findLoadingSkeleton().exists()).toBe(false);
    expect(findReleaseBlock().exists()).toBe(false);
  });
});