mutations_spec.js 3.37 KB
Newer Older
1 2 3
import state from '~/reports/store/state';
import mutations from '~/reports/store/mutations';
import * as types from '~/reports/store/mutation_types';
4
import { issue } from '../mock_data/mock_data';
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

describe('Reports Store Mutations', () => {
  let stateCopy;

  beforeEach(() => {
    stateCopy = state();
  });

  describe('SET_ENDPOINT', () => {
    it('should set endpoint', () => {
      mutations[types.SET_ENDPOINT](stateCopy, 'endpoint.json');
      expect(stateCopy.endpoint).toEqual('endpoint.json');
    });
  });

  describe('REQUEST_REPORTS', () => {
    it('should set isLoading to true', () => {
      mutations[types.REQUEST_REPORTS](stateCopy);
      expect(stateCopy.isLoading).toEqual(true);
    });
  });

  describe('RECEIVE_REPORTS_SUCCESS', () => {
    const mockedResponse = {
      summary: {
        total: 14,
        resolved: 0,
        failed: 7,
      },
      suites: [
        {
          name: 'build:linux',
          summary: {
            total: 2,
            resolved: 0,
            failed: 1,
          },
          new_failures: [
            {
              name: 'StringHelper#concatenate when a is git and b is lab returns summary',
              execution_time: 0.0092435,
Filipa Lacerda's avatar
Filipa Lacerda committed
46
              system_output: "Failure/Error: is_expected.to eq('gitlab')",
47 48 49 50 51 52
            },
          ],
          resolved_failures: [
            {
              name: 'StringHelper#concatenate when a is git and b is lab returns summary',
              execution_time: 0.009235,
Filipa Lacerda's avatar
Filipa Lacerda committed
53
              system_output: "Failure/Error: is_expected.to eq('gitlab')",
54 55 56 57 58 59
            },
          ],
          existing_failures: [
            {
              name: 'StringHelper#concatenate when a is git and b is lab returns summary',
              execution_time: 1232.08,
Filipa Lacerda's avatar
Filipa Lacerda committed
60
              system_output: "Failure/Error: is_expected.to eq('gitlab')",
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
            },
          ],
        },
      ],
    };

    beforeEach(() => {
      mutations[types.RECEIVE_REPORTS_SUCCESS](stateCopy, mockedResponse);
    });

    it('should reset isLoading', () => {
      expect(stateCopy.isLoading).toEqual(false);
    });

    it('should set summary counts', () => {
      expect(stateCopy.summary.total).toEqual(mockedResponse.summary.total);
      expect(stateCopy.summary.resolved).toEqual(mockedResponse.summary.resolved);
      expect(stateCopy.summary.failed).toEqual(mockedResponse.summary.failed);
    });

    it('should set reports', () => {
      expect(stateCopy.reports).toEqual(mockedResponse.suites);
    });
  });

  describe('RECEIVE_REPORTS_ERROR', () => {
    beforeEach(() => {
      mutations[types.RECEIVE_REPORTS_ERROR](stateCopy);
    });
90

91 92 93 94 95 96 97 98
    it('should reset isLoading', () => {
      expect(stateCopy.isLoading).toEqual(false);
    });

    it('should set hasError to true', () => {
      expect(stateCopy.hasError).toEqual(true);
    });

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    it('should reset reports', () => {
      expect(stateCopy.reports).toEqual([]);
    });
  });

  describe('SET_ISSUE_MODAL_DATA', () => {
    beforeEach(() => {
      mutations[types.SET_ISSUE_MODAL_DATA](stateCopy, {
        issue,
      });
    });

    it('should set modal title', () => {
      expect(stateCopy.modal.title).toEqual(issue.name);
    });

    it('should set modal data', () => {
      expect(stateCopy.modal.data.execution_time.value).toEqual(issue.execution_time);
      expect(stateCopy.modal.data.system_output.value).toEqual(issue.system_output);
    });
119 120
  });
});