Commit e33a71f2 authored by Andrew Fontaine's avatar Andrew Fontaine

Migrate Feature Flags Spec to Jest

Had to also fix the loading icon size to make Jest behave.
parent 8dfbb726
...@@ -247,7 +247,7 @@ export default { ...@@ -247,7 +247,7 @@ export default {
<gl-loading-icon <gl-loading-icon
v-if="isLoading" v-if="isLoading"
:label="s__('FeatureFlags|Loading feature flags')" :label="s__('FeatureFlags|Loading feature flags')"
:size="3" size="md"
class="js-loading-state prepend-top-20" class="js-loading-state prepend-top-20"
/> />
......
...@@ -2,8 +2,8 @@ import Vue from 'vue'; ...@@ -2,8 +2,8 @@ import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import featureFlagsComponent from 'ee/feature_flags/components/feature_flags.vue'; import featureFlagsComponent from 'ee/feature_flags/components/feature_flags.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import { trimText } from 'spec/helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import { getRequestData } from '../mock_data'; import { getRequestData } from '../mock_data';
...@@ -56,9 +56,9 @@ describe('Feature flags', () => { ...@@ -56,9 +56,9 @@ describe('Feature flags', () => {
component = mountComponent(FeatureFlagsComponent, props); component = mountComponent(FeatureFlagsComponent, props);
setTimeout(() => { setImmediate(() => {
done(); done();
}, 0); });
}); });
it('does not render configure button', () => { it('does not render configure button', () => {
...@@ -71,7 +71,7 @@ describe('Feature flags', () => { ...@@ -71,7 +71,7 @@ describe('Feature flags', () => {
}); });
describe('loading state', () => { describe('loading state', () => {
it('renders a loading icon', done => { it('renders a loading icon', () => {
mock mock
.onGet(`${TEST_HOST}/endpoint.json`, { params: { scope: 'all', page: '1' } }) .onGet(`${TEST_HOST}/endpoint.json`, { params: { scope: 'all', page: '1' } })
.replyOnce(200, getRequestData, {}); .replyOnce(200, getRequestData, {});
...@@ -84,10 +84,6 @@ describe('Feature flags', () => { ...@@ -84,10 +84,6 @@ describe('Feature flags', () => {
expect(loadingElement.querySelector('span').getAttribute('aria-label')).toEqual( expect(loadingElement.querySelector('span').getAttribute('aria-label')).toEqual(
'Loading feature flags', 'Loading feature flags',
); );
setTimeout(() => {
done();
}, 0);
}); });
}); });
...@@ -109,9 +105,9 @@ describe('Feature flags', () => { ...@@ -109,9 +105,9 @@ describe('Feature flags', () => {
component = mountComponent(FeatureFlagsComponent, mockData); component = mountComponent(FeatureFlagsComponent, mockData);
setTimeout(() => { setImmediate(() => {
done(); done();
}, 0); });
}); });
it('should render the empty state', () => { it('should render the empty state', () => {
...@@ -175,9 +171,9 @@ describe('Feature flags', () => { ...@@ -175,9 +171,9 @@ describe('Feature flags', () => {
}); });
component = mountComponent(FeatureFlagsComponent, mockData); component = mountComponent(FeatureFlagsComponent, mockData);
setTimeout(() => { setImmediate(() => {
done(); done();
}, 0); });
}); });
it('should render a table with feature flags', () => { it('should render a table with feature flags', () => {
...@@ -204,30 +200,24 @@ describe('Feature flags', () => { ...@@ -204,30 +200,24 @@ describe('Feature flags', () => {
expect(component.$el.querySelectorAll('.gl-pagination')).not.toBeNull(); expect(component.$el.querySelectorAll('.gl-pagination')).not.toBeNull();
}); });
it('should make an API request when page is clicked', done => { it('should make an API request when page is clicked', () => {
spyOn(component, 'updateFeatureFlagOptions'); jest.spyOn(component, 'updateFeatureFlagOptions');
setTimeout(() => { component.$el.querySelector('.gl-pagination li:nth-child(5) .page-link').click();
component.$el.querySelector('.gl-pagination li:nth-child(5) .page-link').click();
expect(component.updateFeatureFlagOptions).toHaveBeenCalledWith({ expect(component.updateFeatureFlagOptions).toHaveBeenCalledWith({
scope: 'all', scope: 'all',
page: '4', page: '4',
}); });
done();
}, 0);
}); });
it('should make an API request when using tabs', done => { it('should make an API request when using tabs', () => {
setTimeout(() => { jest.spyOn(component, 'updateFeatureFlagOptions');
spyOn(component, 'updateFeatureFlagOptions'); component.$el.querySelector('.js-featureflags-tab-enabled').click();
component.$el.querySelector('.js-featureflags-tab-enabled').click();
expect(component.updateFeatureFlagOptions).toHaveBeenCalledWith({ expect(component.updateFeatureFlagOptions).toHaveBeenCalledWith({
scope: 'enabled', scope: 'enabled',
page: '1', page: '1',
}); });
done();
}, 0);
}); });
}); });
}); });
...@@ -239,9 +229,9 @@ describe('Feature flags', () => { ...@@ -239,9 +229,9 @@ describe('Feature flags', () => {
component = mountComponent(FeatureFlagsComponent, mockData); component = mountComponent(FeatureFlagsComponent, mockData);
setTimeout(() => { setImmediate(() => {
done(); done();
}, 0); });
}); });
it('should render error state', () => { it('should render error state', () => {
...@@ -263,13 +253,13 @@ describe('Feature flags', () => { ...@@ -263,13 +253,13 @@ describe('Feature flags', () => {
beforeEach(done => { beforeEach(done => {
component = mountComponent(FeatureFlagsComponent, mockData); component = mountComponent(FeatureFlagsComponent, mockData);
setTimeout(() => { setImmediate(() => {
done(); done();
}, 0); });
}); });
it('should fire the rotate action when a `token` event is received', () => { it('should fire the rotate action when a `token` event is received', () => {
const actionSpy = spyOn(component, 'rotateInstanceId'); const actionSpy = jest.spyOn(component, 'rotateInstanceId');
const [modal] = component.$children; const [modal] = component.$children;
modal.$emit('token'); modal.$emit('token');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment