{"size": 2014, "ext": "js", "max_stars_repo_path": "spec/frontend/ide/stores/modules/terminal_sync/mutations_spec.js", "max_stars_repo_name": "maxiko/gitlabhq", "max_stars_repo_stars_event_min_datetime": "2020-10-10T05:58:12.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T09:30:57.000Z", "max_issues_repo_path": "spec/frontend/ide/stores/modules/terminal_sync/mutations_spec.js", "max_issues_repo_name": "maxiko/gitlabhq", "max_issues_repo_issues_event_min_datetime": "2020-11-13T01:44:43.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-17T22:44:42.000Z", "max_forks_repo_path": "spec/frontend/ide/stores/modules/terminal_sync/mutations_spec.js", "max_forks_repo_name": "C28NGO37/gitlabhq", "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:28:36.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-06T04:49:03.000Z"}
{"max_stars_count": 2, "max_issues_count": 60, "max_forks_count": 3, "avg_line_length": 22.3777777778, "max_line_length": 75, "alphanum_fraction": 0.5506454816}
import createState from '~/ide/stores/modules/terminal_sync/state';
import * as types from '~/ide/stores/modules/terminal_sync/mutation_types';
import mutations from '~/ide/stores/modules/terminal_sync/mutations';

const TEST_MESSAGE = 'lorem ipsum dolar sit';

describe('ide/stores/modules/terminal_sync/mutations', () => {
  let state;

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

  describe(types.START_LOADING, () => {
    it('sets isLoading and resets error', () => {
      Object.assign(state, {
        isLoading: false,
        isError: true,
      });

      mutations[types.START_LOADING](state);

      expect(state).toEqual(
        expect.objectContaining({
          isLoading: true,
          isError: false,
        }),
      );
    });
  });

  describe(types.SET_ERROR, () => {
    it('sets isLoading and error message', () => {
      Object.assign(state, {
        isLoading: true,
        isError: false,
        message: '',
      });

      mutations[types.SET_ERROR](state, { message: TEST_MESSAGE });

      expect(state).toEqual(
        expect.objectContaining({
          isLoading: false,
          isError: true,
          message: TEST_MESSAGE,
        }),
      );
    });
  });

  describe(types.SET_SUCCESS, () => {
    it('sets isLoading and resets error and is started', () => {
      Object.assign(state, {
        isLoading: true,
        isError: true,
        isStarted: false,
      });

      mutations[types.SET_SUCCESS](state);

      expect(state).toEqual(
        expect.objectContaining({
          isLoading: false,
          isError: false,
          isStarted: true,
        }),
      );
    });
  });

  describe(types.STOP, () => {
    it('sets stop values', () => {
      Object.assign(state, {
        isLoading: true,
        isStarted: true,
      });

      mutations[types.STOP](state);

      expect(state).toEqual(
        expect.objectContaining({
          isLoading: false,
          isStarted: false,
        }),
      );
    });
  });
});
