debian-mirror-gitlab/spec/frontend/environments/environment_actions_spec.js

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

109 lines
3.3 KiB
JavaScript
Raw Normal View History

2023-06-20 00:43:36 +05:30
import { GlDisclosureDropdown, GlDisclosureDropdownItem, GlIcon } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
2020-03-13 15:44:24 +05:30
import { TEST_HOST } from 'helpers/test_constants';
import EnvironmentActions from '~/environments/components/environment_actions.vue';
2022-05-07 20:08:51 +05:30
import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal';
2020-03-13 15:44:24 +05:30
2023-01-13 00:05:48 +05:30
jest.mock('~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal');
2022-05-07 20:08:51 +05:30
2021-02-22 17:27:13 +05:30
const scheduledJobAction = {
name: 'scheduled action',
playPath: `${TEST_HOST}/scheduled/job/action`,
playable: true,
scheduledAt: '2063-04-05T00:42:00Z',
};
const expiredJobAction = {
name: 'expired action',
playPath: `${TEST_HOST}/expired/job/action`,
playable: true,
scheduledAt: '2018-10-05T08:23:00Z',
};
2020-03-13 15:44:24 +05:30
describe('EnvironmentActions Component', () => {
2021-02-22 17:27:13 +05:30
let wrapper;
2020-03-13 15:44:24 +05:30
2023-06-20 00:43:36 +05:30
function createComponent(props, { options = {} } = {}) {
wrapper = mount(EnvironmentActions, {
2021-02-22 17:27:13 +05:30
propsData: { actions: [], ...props },
2022-03-02 08:16:31 +05:30
...options,
2021-01-03 14:25:43 +05:30
});
2021-02-22 17:27:13 +05:30
}
function createComponentWithScheduledJobs(opts = {}) {
return createComponent({ actions: [scheduledJobAction, expiredJobAction] }, opts);
}
2023-06-20 00:43:36 +05:30
const findDropdownItems = () => wrapper.findAllComponents(GlDisclosureDropdownItem);
2021-03-08 18:12:59 +05:30
const findDropdownItem = (action) => {
2023-06-20 00:43:36 +05:30
const items = findDropdownItems();
return items.filter((item) => item.text().startsWith(action.name)).at(0);
2021-02-22 17:27:13 +05:30
};
2020-03-13 15:44:24 +05:30
afterEach(() => {
2022-05-07 20:08:51 +05:30
confirmAction.mockReset();
2020-03-13 15:44:24 +05:30
});
it('should render a dropdown button with 2 icons', () => {
2021-02-22 17:27:13 +05:30
createComponent();
2023-06-20 00:43:36 +05:30
expect(wrapper.findComponent(GlDisclosureDropdown).findAllComponents(GlIcon).length).toBe(2);
2020-03-13 15:44:24 +05:30
});
2023-06-20 00:43:36 +05:30
it('should render a dropdown button with aria-label description', () => {
2021-02-22 17:27:13 +05:30
createComponent();
2023-06-20 00:43:36 +05:30
expect(wrapper.findComponent(GlDisclosureDropdown).attributes('aria-label')).toBe(
'Deploy to...',
);
2021-01-03 14:25:43 +05:30
});
2020-03-13 15:44:24 +05:30
describe('manual actions', () => {
const actions = [
{
name: 'bar',
play_path: 'https://gitlab.com/play',
},
{
name: 'foo',
play_path: '#',
},
{
name: 'foo bar',
play_path: 'url',
playable: false,
},
];
beforeEach(() => {
2021-02-22 17:27:13 +05:30
createComponent({ actions });
2020-03-13 15:44:24 +05:30
});
it('should render a dropdown with the provided list of actions', () => {
2023-06-20 00:43:36 +05:30
expect(findDropdownItems()).toHaveLength(actions.length);
2020-03-13 15:44:24 +05:30
});
it("should render a disabled action when it's not playable", () => {
2023-06-20 00:43:36 +05:30
const dropdownItems = findDropdownItems();
2021-02-22 17:27:13 +05:30
const lastDropdownItem = dropdownItems.at(dropdownItems.length - 1);
2023-07-09 08:55:56 +05:30
expect(lastDropdownItem.find('button').attributes('disabled')).toBeDefined();
2020-03-13 15:44:24 +05:30
});
});
describe('scheduled jobs', () => {
beforeEach(() => {
jest.spyOn(Date, 'now').mockImplementation(() => new Date('2063-04-04T00:42:00Z').getTime());
});
it('displays the remaining time in the dropdown', () => {
2023-06-20 00:43:36 +05:30
confirmAction.mockResolvedValueOnce(true);
2021-02-22 17:27:13 +05:30
createComponentWithScheduledJobs();
2020-03-13 15:44:24 +05:30
expect(findDropdownItem(scheduledJobAction).text()).toContain('24:00:00');
});
it('displays 00:00:00 for expired jobs in the dropdown', () => {
2023-06-20 00:43:36 +05:30
confirmAction.mockResolvedValueOnce(true);
2021-02-22 17:27:13 +05:30
createComponentWithScheduledJobs();
2020-03-13 15:44:24 +05:30
expect(findDropdownItem(expiredJobAction).text()).toContain('00:00:00');
});
});
});