debian-mirror-gitlab/spec/frontend/jobs/bridge/components/sidebar_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
2.5 KiB
JavaScript
Raw Normal View History

2022-01-26 12:08:38 +05:30
import { GlButton, GlDropdown } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import BridgeSidebar from '~/jobs/bridge/components/sidebar.vue';
2022-03-02 08:16:31 +05:30
import CommitBlock from '~/jobs/components/commit_block.vue';
import { mockCommit, mockJob } from '../mock_data';
2022-01-26 12:08:38 +05:30
describe('Bridge Sidebar', () => {
let wrapper;
2022-03-02 08:16:31 +05:30
const MockHeaderEl = {
getBoundingClientRect() {
return {
bottom: '40',
};
},
};
const createComponent = ({ featureFlag } = {}) => {
2022-01-26 12:08:38 +05:30
wrapper = shallowMount(BridgeSidebar, {
provide: {
2022-03-02 08:16:31 +05:30
glFeatures: {
triggerJobRetryAction: featureFlag,
},
},
propsData: {
bridgeJob: mockJob,
commit: mockCommit,
2022-01-26 12:08:38 +05:30
},
});
};
2022-03-02 08:16:31 +05:30
const findJobTitle = () => wrapper.find('h4');
const findCommitBlock = () => wrapper.findComponent(CommitBlock);
2022-01-26 12:08:38 +05:30
const findRetryDropdown = () => wrapper.find(GlDropdown);
2022-03-02 08:16:31 +05:30
const findToggleBtn = () => wrapper.findComponent(GlButton);
2022-01-26 12:08:38 +05:30
afterEach(() => {
wrapper.destroy();
});
describe('template', () => {
beforeEach(() => {
createComponent();
});
2022-03-02 08:16:31 +05:30
it('renders job name', () => {
expect(findJobTitle().text()).toBe(mockJob.name);
});
it('renders commit information', () => {
expect(findCommitBlock().exists()).toBe(true);
});
});
describe('styles', () => {
beforeEach(async () => {
jest.spyOn(document, 'querySelector').mockReturnValue(MockHeaderEl);
createComponent();
});
it('calculates root styles correctly', () => {
expect(wrapper.attributes('style')).toBe('width: 290px; top: 40px;');
2022-01-26 12:08:38 +05:30
});
});
describe('sidebar expansion', () => {
beforeEach(() => {
createComponent();
});
2022-03-02 08:16:31 +05:30
it('emits toggle sidebar event on button click', async () => {
expect(wrapper.emitted('toggleSidebar')).toBe(undefined);
2022-01-26 12:08:38 +05:30
2022-03-02 08:16:31 +05:30
findToggleBtn().vm.$emit('click');
2022-01-26 12:08:38 +05:30
2022-03-02 08:16:31 +05:30
expect(wrapper.emitted('toggleSidebar')).toHaveLength(1);
2022-01-26 12:08:38 +05:30
});
2022-03-02 08:16:31 +05:30
});
2022-01-26 12:08:38 +05:30
2022-03-02 08:16:31 +05:30
describe('retry action', () => {
describe('when feature flag is ON', () => {
beforeEach(() => {
createComponent({ featureFlag: true });
});
it('renders retry dropdown', () => {
expect(findRetryDropdown().exists()).toBe(true);
});
});
describe('when feature flag is OFF', () => {
it('does not render retry dropdown', () => {
createComponent({ featureFlag: false });
expect(findRetryDropdown().exists()).toBe(false);
});
2022-01-26 12:08:38 +05:30
});
});
});