2020-01-01 13:55:28 +05:30
|
|
|
import _ from 'underscore';
|
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-13 15:44:24 +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-13 15:44:24 +05:30
|
|
|
import { resetStore } from '../stores/modules/list/helpers';
|
2020-01-01 13:55:28 +05:30
|
|
|
import {
|
|
|
|
pageInfoHeadersWithoutPagination,
|
|
|
|
pageInfoHeadersWithPagination,
|
|
|
|
release,
|
|
|
|
releases,
|
2020-03-13 15:44:24 +05:30
|
|
|
} from '../mock_data';
|
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',
|
|
|
|
documentationLink: 'help/releases',
|
|
|
|
illustrationPath: 'illustration/path',
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-03-13 15:44:24 +05:30
|
|
|
store = createStore({ list: listModule });
|
2020-01-01 13:55:28 +05:30
|
|
|
releasesPagination = _.range(21).map(index => ({ ...release, tag_name: `${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
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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 => {
|
|
|
|
setTimeout(() => {
|
|
|
|
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();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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 => {
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.$el.querySelector('.js-loading')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-empty-state')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-success-state')).not.toBeNull();
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(vm.$el.querySelector('.gl-pagination')).not.toBeNull();
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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 => {
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.$el.querySelector('.js-loading')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-empty-state')).not.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
|
|
|
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|