summaryrefslogtreecommitdiff
path: root/spec/frontend/environments/environment_pin_spec.js
blob: a9a58071e12b1b148e7be6ab57ed5cc7480c2c08 (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
import { GlDropdownItem } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import PinComponent from '~/environments/components/environment_pin.vue';
import eventHub from '~/environments/event_hub';

describe('Pin Component', () => {
  let wrapper;

  const factory = (options = {}) => {
    // This destroys any wrappers created before a nested call to factory reassigns it
    if (wrapper && wrapper.destroy) {
      wrapper.destroy();
    }
    wrapper = shallowMount(PinComponent, {
      ...options,
    });
  };

  const autoStopUrl = '/root/auto-stop-env-test/-/environments/38/cancel_auto_stop';

  beforeEach(() => {
    factory({
      propsData: {
        autoStopUrl,
      },
    });
  });

  afterEach(() => {
    wrapper.destroy();
  });

  it('should render the component with descriptive text', () => {
    expect(wrapper.text()).toBe('Prevent auto-stopping');
  });

  it('should emit onPinClick when clicked', () => {
    const eventHubSpy = jest.spyOn(eventHub, '$emit');
    const item = wrapper.find(GlDropdownItem);

    item.vm.$emit('click');

    expect(eventHubSpy).toHaveBeenCalledWith('cancelAutoStop', autoStopUrl);
  });
});