app_spec.js 2.07 KB
Newer Older
1 2
import Vue from 'vue';

3
import mountComponent from 'helpers/vue_mount_component_helper';
4 5 6

import AppComponent from 'ee/group_member_contributions/components/app.vue';
import GroupMemberStore from 'ee/group_member_contributions/store/group_member_store';
7
import { contributionsPath } from '../mock_data';
8 9 10 11

const createComponent = () => {
  const Component = Vue.extend(AppComponent);

12
  const store = new GroupMemberStore(contributionsPath);
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

  return mountComponent(Component, {
    store,
  });
};

describe('AppComponent', () => {
  let vm;

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

  afterEach(() => {
    vm.$destroy();
  });

  describe('methods', () => {
    describe('handleColumnClick', () => {
      it('calls store.sortMembers with columnName param', () => {
33
        jest.spyOn(vm.store, 'sortMembers').mockImplementation(() => {});
34 35 36

        const columnName = 'fullname';
        vm.handleColumnClick(columnName);
37

38 39 40 41 42 43 44 45 46 47 48 49 50 51
        expect(vm.store.sortMembers).toHaveBeenCalledWith(columnName);
      });
    });
  });

  describe('template', () => {
    it('renders component container element with class `group-member-contributions-container`', () => {
      expect(vm.$el.classList.contains('group-member-contributions-container')).toBe(true);
    });

    it('renders header title element within component containe', () => {
      expect(vm.$el.querySelector('h3').innerText.trim()).toBe('Contributions per group member');
    });

52
    it('shows loading icon when isLoading prop is true', () => {
53
      vm.store.state.isLoading = true;
54 55 56 57 58 59 60 61 62

      return vm.$nextTick().then(() => {
        const loadingEl = vm.$el.querySelector('.loading-animation');

        expect(loadingEl).not.toBeNull();
        expect(loadingEl.querySelector('span').getAttribute('aria-label')).toBe(
          'Loading contribution stats for group members',
        );
      });
63 64
    });

65
    it('renders table container element', () => {
66
      vm.store.state.isLoading = false;
67 68 69 70

      return vm.$nextTick().then(() => {
        expect(vm.$el.querySelector('table.table.gl-sortable')).not.toBeNull();
      });
71 72 73
    });
  });
});