Commit fa8242cc authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'karma-fixes' into 'master'

Fixed geo_nodes karma spec

See merge request gitlab-org/gitlab-ee!4444
parents 57a43be1 c3c7739a
...@@ -25,13 +25,23 @@ const createComponent = () => { ...@@ -25,13 +25,23 @@ const createComponent = () => {
describe('AppComponent', () => { describe('AppComponent', () => {
let vm; let vm;
let mock;
let statusCode;
let response;
beforeEach(() => { beforeEach(() => {
statusCode = 200;
response = mockNodes;
mock = new MockAdapter(axios);
mock.onGet(/(.*)\/geo_nodes$/).reply(() => [statusCode, response]);
vm = createComponent(); vm = createComponent();
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
mock.restore();
}); });
describe('data', () => { describe('data', () => {
...@@ -51,19 +61,8 @@ describe('AppComponent', () => { ...@@ -51,19 +61,8 @@ describe('AppComponent', () => {
}); });
describe('methods', () => { describe('methods', () => {
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
describe('fetchGeoNodes', () => { describe('fetchGeoNodes', () => {
it('calls service.getGeoNodes and sets response to the store on success', (done) => { it('calls service.getGeoNodes and sets response to the store on success', (done) => {
mock.onGet(vm.store.geoNodesPath).reply(200, mockNodes);
spyOn(vm.store, 'setNodes'); spyOn(vm.store, 'setNodes');
vm.fetchGeoNodes(); vm.fetchGeoNodes();
...@@ -76,14 +75,14 @@ describe('AppComponent', () => { ...@@ -76,14 +75,14 @@ describe('AppComponent', () => {
}); });
it('sets error flag and message on failure', (done) => { it('sets error flag and message on failure', (done) => {
const err = 'Something went wrong'; response = 'Something went wrong';
mock.onGet(vm.store.geoNodesPath).reply(500, err); statusCode = 500;
vm.fetchGeoNodes(); vm.fetchGeoNodes();
expect(vm.hasError).toBeFalsy(); expect(vm.hasError).toBeFalsy();
setTimeout(() => { setTimeout(() => {
expect(vm.hasError).toBeTruthy(); expect(vm.hasError).toBeTruthy();
expect(vm.errorMessage.response.data).toBe(err); expect(vm.errorMessage.response.data).toBe(response);
done(); done();
}, 0); }, 0);
}); });
...@@ -92,11 +91,13 @@ describe('AppComponent', () => { ...@@ -92,11 +91,13 @@ describe('AppComponent', () => {
describe('fetchNodeDetails', () => { describe('fetchNodeDetails', () => {
it('calls service.getGeoNodeDetails and sets response to the store on success', (done) => { it('calls service.getGeoNodeDetails and sets response to the store on success', (done) => {
mock.onGet(`${vm.service.geoNodeDetailsBasePath}/2/status.json`).reply(200, rawMockNodeDetails); mock.onGet(`${vm.service.geoNodeDetailsBasePath}/2/status.json`).reply(200, rawMockNodeDetails);
spyOn(vm.store, 'setNodeDetails'); spyOn(vm.service, 'getGeoNodeDetails').and.callThrough();
vm.fetchNodeDetails(2); vm.fetchNodeDetails(2);
setTimeout(() => { setTimeout(() => {
expect(vm.store.setNodeDetails).toHaveBeenCalled(); expect(vm.service.getGeoNodeDetails).toHaveBeenCalled();
expect(Object.keys(vm.store.state.nodeDetails).length).toBe(1);
expect(vm.store.state.nodeDetails['2']).toBeDefined();
done(); done();
}, 0); }, 0);
}); });
......
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