debian-mirror-gitlab/spec/javascripts/releases/components/app_index_spec.js

185 lines
5.4 KiB
JavaScript
Raw Normal View History

2020-04-08 14:13:33 +05:30
import { range as rge } from 'lodash';
2019-02-15 15:39:39 +05:30
import Vue from 'vue';
2020-01-01 13:55:28 +05:30
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
2020-03-09 13:42:32 +05:30
import app from '~/releases/components/app_index.vue';
import createStore from '~/releases/stores';
import listModule from '~/releases/stores/modules/list';
2019-02-15 15:39:39 +05:30
import api from '~/api';
2020-03-09 13:42:32 +05:30
import { resetStore } from '../stores/modules/list/helpers';
2020-01-01 13:55:28 +05:30
import {
pageInfoHeadersWithoutPagination,
pageInfoHeadersWithPagination,
release,
releases,
2020-03-09 13:42:32 +05:30
} from '../mock_data';
2020-04-08 14:13:33 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import waitForPromises from 'spec/helpers/wait_for_promises';
2019-02-15 15:39:39 +05:30
describe('Releases App ', () => {
const Component = Vue.extend(app);
let store;
let vm;
2020-01-01 13:55:28 +05:30
let releasesPagination;
2019-02-15 15:39:39 +05:30
const props = {
projectId: 'gitlab-ce',
2020-04-08 14:13:33 +05:30
documentationPath: 'help/releases',
2019-02-15 15:39:39 +05:30
illustrationPath: 'illustration/path',
};
beforeEach(() => {
2020-04-08 14:13:33 +05:30
store = createStore({ modules: { list: listModule } });
releasesPagination = rge(21).map(index => ({
...convertObjectPropsToCamelCase(release, { deep: true }),
tagName: `${index}.00`,
}));
2019-02-15 15:39:39 +05:30
});
afterEach(() => {
resetStore(store);
vm.$destroy();
});
describe('while loading', () => {
beforeEach(() => {
2020-01-01 13:55:28 +05:30
spyOn(api, 'releases').and.returnValue(Promise.resolve({ data: [], headers: {} }));
2019-02-15 15:39:39 +05:30
vm = mountComponentWithStore(Component, { props, store });
});
it('renders loading icon', done => {
expect(vm.$el.querySelector('.js-loading')).not.toBeNull();
expect(vm.$el.querySelector('.js-empty-state')).toBeNull();
expect(vm.$el.querySelector('.js-success-state')).toBeNull();
2020-01-01 13:55:28 +05:30
expect(vm.$el.querySelector('.gl-pagination')).toBeNull();
2019-02-15 15:39:39 +05:30
2020-04-08 14:13:33 +05:30
waitForPromises()
.then(done)
.catch(done.fail);
2019-02-15 15:39:39 +05:30
});
});
describe('with successful request', () => {
beforeEach(() => {
2020-01-01 13:55:28 +05:30
spyOn(api, 'releases').and.returnValue(
Promise.resolve({ data: releases, headers: pageInfoHeadersWithoutPagination }),
);
vm = mountComponentWithStore(Component, { props, store });
});
it('renders success state', done => {
2020-04-08 14:13:33 +05:30
waitForPromises()
.then(() => {
expect(vm.$el.querySelector('.js-loading')).toBeNull();
expect(vm.$el.querySelector('.js-empty-state')).toBeNull();
expect(vm.$el.querySelector('.js-success-state')).not.toBeNull();
expect(vm.$el.querySelector('.gl-pagination')).toBeNull();
done();
})
.catch(done.fail);
2020-01-01 13:55:28 +05:30
});
});
describe('with successful request and pagination', () => {
beforeEach(() => {
spyOn(api, 'releases').and.returnValue(
Promise.resolve({ data: releasesPagination, headers: pageInfoHeadersWithPagination }),
);
2019-02-15 15:39:39 +05:30
vm = mountComponentWithStore(Component, { props, store });
});
it('renders success state', done => {
2020-04-08 14:13:33 +05:30
waitForPromises()
.then(() => {
expect(vm.$el.querySelector('.js-loading')).toBeNull();
expect(vm.$el.querySelector('.js-empty-state')).toBeNull();
expect(vm.$el.querySelector('.js-success-state')).not.toBeNull();
expect(vm.$el.querySelector('.gl-pagination')).not.toBeNull();
done();
})
.catch(done.fail);
2019-02-15 15:39:39 +05:30
});
});
describe('with empty request', () => {
beforeEach(() => {
2020-01-01 13:55:28 +05:30
spyOn(api, 'releases').and.returnValue(Promise.resolve({ data: [], headers: {} }));
2019-02-15 15:39:39 +05:30
vm = mountComponentWithStore(Component, { props, store });
});
it('renders empty state', done => {
2020-04-08 14:13:33 +05:30
waitForPromises()
.then(() => {
expect(vm.$el.querySelector('.js-loading')).toBeNull();
expect(vm.$el.querySelector('.js-empty-state')).not.toBeNull();
expect(vm.$el.querySelector('.js-success-state')).toBeNull();
expect(vm.$el.querySelector('.gl-pagination')).toBeNull();
done();
})
.catch(done.fail);
});
});
describe('"New release" button', () => {
const findNewReleaseButton = () => vm.$el.querySelector('.js-new-release-btn');
beforeEach(() => {
spyOn(api, 'releases').and.returnValue(Promise.resolve({ data: [], headers: {} }));
});
const factory = additionalProps => {
vm = mountComponentWithStore(Component, {
props: {
...props,
...additionalProps,
},
store,
});
};
describe('when the user is allowed to create a new Release', () => {
const newReleasePath = 'path/to/new/release';
beforeEach(() => {
factory({ newReleasePath });
});
it('renders the "New release" button', done => {
waitForPromises()
.then(() => {
expect(findNewReleaseButton()).not.toBeNull();
done();
})
.catch(done.fail);
});
it('renders the "New release" button with the correct href', done => {
waitForPromises()
.then(() => {
expect(findNewReleaseButton().getAttribute('href')).toBe(newReleasePath);
done();
})
.catch(done.fail);
});
});
describe('when the user is not allowed to create a new Release', () => {
beforeEach(() => factory());
it('does not render the "New release" button', done => {
waitForPromises()
.then(() => {
expect(findNewReleaseButton()).toBeNull();
done();
})
.catch(done.fail);
});
2019-02-15 15:39:39 +05:30
});
});
});