Welcome to mirror list, hosted at ThFree Co, Russian Federation.

stop_stale_environments_modal_spec.js « environments « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ddf6670db121dbe6d8dc11ea984ac0d5f50d34a4 (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
import MockAdapter from 'axios-mock-adapter';
import { GlModal } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import StopStaleEnvironmentsModal from '~/environments/components/stop_stale_environments_modal.vue';
import axios from '~/lib/utils/axios_utils';
import { getDateInPast } from '~/lib/utils/datetime_utility';
import { STOP_STALE_ENVIRONMENTS_PATH } from '~/api/environments_api';
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';

const DEFAULT_OPTS = {
  provide: { projectId: 1 },
};

const ONE_WEEK_AGO = getDateInPast(new Date(), 7);
const TEN_YEARS_AGO = getDateInPast(new Date(), 3650);

describe('~/environments/components/stop_stale_environments_modal.vue', () => {
  let wrapper;
  let mock;
  let before;

  const createWrapper = (opts = {}) =>
    shallowMount(StopStaleEnvironmentsModal, {
      ...DEFAULT_OPTS,
      ...opts,
      propsData: { modalId: 'stop-stale-environments-modal', visible: true },
    });

  beforeEach(() => {
    window.gon.api_version = 'v4';

    mock = new MockAdapter(axios);
    jest.spyOn(axios, 'post');
    wrapper = createWrapper();
    before = wrapper.find("[data-testid='stop-environments-before']");
  });

  afterEach(() => {
    mock.restore();
    jest.resetAllMocks();
  });

  it('sets the correct min and max dates', async () => {
    expect(before.props().minDate.toISOString()).toBe(TEN_YEARS_AGO.toISOString());
    expect(before.props().maxDate.toISOString()).toBe(ONE_WEEK_AGO.toISOString());
  });

  it('requests cleanup when submit is clicked', async () => {
    mock.onPost().replyOnce(HTTP_STATUS_OK);
    wrapper.findComponent(GlModal).vm.$emit('primary');
    const url = STOP_STALE_ENVIRONMENTS_PATH.replace(':id', 1).replace(':version', 'v4');
    expect(axios.post).toHaveBeenCalledWith(url, null, {
      params: { before: ONE_WEEK_AGO.toISOString() },
    });
  });
});