2021-11-08 07:12:07 -05:00
|
|
|
import { GlBadge } from '@gitlab/ui';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-12-06 19:14:07 -05:00
|
|
|
import RunnerStatusBadge from '~/runner/components/runner_status_badge.vue';
|
2021-11-08 07:12:07 -05:00
|
|
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
|
2021-12-06 19:14:07 -05:00
|
|
|
import {
|
|
|
|
STATUS_ONLINE,
|
|
|
|
STATUS_OFFLINE,
|
|
|
|
STATUS_STALE,
|
2021-12-10 13:14:42 -05:00
|
|
|
STATUS_NEVER_CONTACTED,
|
2022-03-23 14:08:47 -04:00
|
|
|
I18N_NEVER_CONTACTED_TOOLTIP,
|
|
|
|
I18N_STALE_NEVER_CONTACTED_TOOLTIP,
|
2021-12-06 19:14:07 -05:00
|
|
|
} from '~/runner/constants';
|
2021-11-08 07:12:07 -05:00
|
|
|
|
|
|
|
describe('RunnerTypeBadge', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findBadge = () => wrapper.findComponent(GlBadge);
|
|
|
|
const getTooltip = () => getBinding(findBadge().element, 'gl-tooltip');
|
|
|
|
|
2021-12-06 19:14:07 -05:00
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapper = shallowMount(RunnerStatusBadge, {
|
2021-11-08 07:12:07 -05:00
|
|
|
propsData: {
|
|
|
|
runner: {
|
2021-12-06 19:14:07 -05:00
|
|
|
contactedAt: '2020-12-31T23:59:00Z',
|
2021-11-08 07:12:07 -05:00
|
|
|
status: STATUS_ONLINE,
|
|
|
|
},
|
2021-12-06 19:14:07 -05:00
|
|
|
...props,
|
2021-11-08 07:12:07 -05:00
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlTooltip: createMockDirective(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.useFakeTimers('modern');
|
2021-12-06 19:14:07 -05:00
|
|
|
jest.setSystemTime(new Date('2021-01-01T00:00:00Z'));
|
2021-11-08 07:12:07 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jest.useFakeTimers('legacy');
|
|
|
|
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders online state', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(wrapper.text()).toBe('online');
|
|
|
|
expect(findBadge().props('variant')).toBe('success');
|
|
|
|
expect(getTooltip().value).toBe('Runner is online; last contact was 1 minute ago');
|
|
|
|
});
|
|
|
|
|
2022-01-04 13:14:20 -05:00
|
|
|
it('renders never contacted state', () => {
|
2021-12-10 13:14:42 -05:00
|
|
|
createComponent({
|
|
|
|
runner: {
|
|
|
|
contactedAt: null,
|
|
|
|
status: STATUS_NEVER_CONTACTED,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-01-04 13:14:20 -05:00
|
|
|
expect(wrapper.text()).toBe('never contacted');
|
2021-12-10 13:14:42 -05:00
|
|
|
expect(findBadge().props('variant')).toBe('muted');
|
2022-03-23 14:08:47 -04:00
|
|
|
expect(getTooltip().value).toBe(I18N_NEVER_CONTACTED_TOOLTIP);
|
2021-12-10 13:14:42 -05:00
|
|
|
});
|
|
|
|
|
2021-12-06 19:14:07 -05:00
|
|
|
it('renders offline state', () => {
|
2021-11-08 07:12:07 -05:00
|
|
|
createComponent({
|
|
|
|
runner: {
|
2021-12-06 19:14:07 -05:00
|
|
|
contactedAt: '2020-12-31T00:00:00Z',
|
2021-11-08 07:12:07 -05:00
|
|
|
status: STATUS_OFFLINE,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.text()).toBe('offline');
|
|
|
|
expect(findBadge().props('variant')).toBe('muted');
|
2022-03-23 14:08:47 -04:00
|
|
|
expect(getTooltip().value).toBe('Runner is offline; last contact was 1 day ago');
|
2021-11-08 07:12:07 -05:00
|
|
|
});
|
|
|
|
|
2021-12-06 19:14:07 -05:00
|
|
|
it('renders stale state', () => {
|
2021-11-08 07:12:07 -05:00
|
|
|
createComponent({
|
|
|
|
runner: {
|
2021-12-06 19:14:07 -05:00
|
|
|
contactedAt: '2020-01-01T00:00:00Z',
|
|
|
|
status: STATUS_STALE,
|
2021-11-08 07:12:07 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-12-06 19:14:07 -05:00
|
|
|
expect(wrapper.text()).toBe('stale');
|
|
|
|
expect(findBadge().props('variant')).toBe('warning');
|
2022-03-23 14:08:47 -04:00
|
|
|
expect(getTooltip().value).toBe('Runner is stale; last contact was 1 year ago');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders stale state with no contact time', () => {
|
|
|
|
createComponent({
|
|
|
|
runner: {
|
|
|
|
contactedAt: null,
|
|
|
|
status: STATUS_STALE,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.text()).toBe('stale');
|
|
|
|
expect(findBadge().props('variant')).toBe('warning');
|
|
|
|
expect(getTooltip().value).toBe(I18N_STALE_NEVER_CONTACTED_TOOLTIP);
|
2021-11-08 07:12:07 -05:00
|
|
|
});
|
|
|
|
|
2021-12-06 19:14:07 -05:00
|
|
|
describe('does not fail when data is missing', () => {
|
|
|
|
it('contacted_at is missing', () => {
|
|
|
|
createComponent({
|
|
|
|
runner: {
|
|
|
|
contactedAt: null,
|
|
|
|
status: STATUS_ONLINE,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.text()).toBe('online');
|
2022-03-23 14:08:47 -04:00
|
|
|
expect(getTooltip().value).toBe('Runner is online; last contact was never');
|
2021-11-08 07:12:07 -05:00
|
|
|
});
|
|
|
|
|
2021-12-06 19:14:07 -05:00
|
|
|
it('status is missing', () => {
|
|
|
|
createComponent({
|
|
|
|
runner: {
|
|
|
|
status: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.text()).toBe('');
|
|
|
|
});
|
2021-11-08 07:12:07 -05:00
|
|
|
});
|
|
|
|
});
|