diff --git a/gsa/src/web/pages/reports/scaninfo.js b/gsa/src/web/pages/reports/scaninfo.js index 7a8d1e690a..cc201777ae 100644 --- a/gsa/src/web/pages/reports/scaninfo.js +++ b/gsa/src/web/pages/reports/scaninfo.js @@ -22,7 +22,6 @@ import React from 'react'; import _ from 'gmp/locale'; import {duration as createDuration} from 'gmp/models/date'; -import Report from 'gmp/models/report'; import {isDefined} from 'gmp/utils/identity'; @@ -89,10 +88,8 @@ const ReportScanInfoTable = ({filterString, links = true, report}) => { const hosts_count = isDefined(hosts) && isDefined(hosts.counts) ? hosts.counts.all : 0; - if (isDefined(filter)) { - if (!isDefined(filterString)) { - filterString = filter.simple().toFilterString(); - } + if (isDefined(filter) && !isDefined(filterString)) { + filterString = filter.simple().toFilterString(); } const status = @@ -100,7 +97,9 @@ const ReportScanInfoTable = ({filterString, links = true, report}) => { ? _('Container') : scan_run_status; - const delta = report instanceof Report ? report.isDeltaReport() : false; + const delta = isDefined(report.isDeltaReport) + ? report.isDeltaReport() + : false; const is_ended = isDefined(scan_end) && scan_end.isValid(); return ( diff --git a/gsa/src/web/store/entities/__tests__/reports.js b/gsa/src/web/store/entities/__tests__/reports.js index f475f332ca..d23f6972a7 100644 --- a/gsa/src/web/store/entities/__tests__/reports.js +++ b/gsa/src/web/store/entities/__tests__/reports.js @@ -202,21 +202,17 @@ describe('report loadEntity function tests', () => { expect(getState).toBeCalled(); expect(get).toBeCalledWith({id}, {details: 1, filter: undefined}); expect(dispatch).toHaveBeenCalledTimes(2); - expect(dispatch.mock.calls[0]).toEqual([ - { - type: types.ENTITY_LOADING_REQUEST, - entityType, - id, - }, - ]); - expect(dispatch.mock.calls[1]).toEqual([ - { - type: types.ENTITY_LOADING_ERROR, - entityType, - error: 'An Error', - id, - }, - ]); + expect(dispatch).toHaveBeenNthCalledWith(1, { + type: types.ENTITY_LOADING_REQUEST, + entityType, + id, + }); + expect(dispatch).toHaveBeenNthCalledWith(2, { + type: types.ENTITY_LOADING_ERROR, + entityType, + error: 'An Error', + id, + }); }); }); }); @@ -233,11 +229,7 @@ describe('report loadEntityIfNeeded function tests', () => { const dispatch = jest.fn(); - const get = jest.fn().mockReturnValue( - Promise.resolve({ - data: {foo: 'bar'}, - }), - ); + const get = jest.fn().mockResolvedValue({data: {foo: 'bar'}}); const gmp = { [entityType]: { @@ -252,21 +244,17 @@ describe('report loadEntityIfNeeded function tests', () => { expect(getState).toBeCalled(); expect(get).toBeCalledWith({id}, {details: 0, filter: undefined}); expect(dispatch).toHaveBeenCalledTimes(2); - expect(dispatch.mock.calls[0]).toEqual([ - { - type: types.ENTITY_LOADING_REQUEST, - entityType, - id, - }, - ]); - expect(dispatch.mock.calls[1]).toEqual([ - { - type: types.ENTITY_LOADING_SUCCESS, - entityType, - data: {foo: 'bar'}, - id, - }, - ]); + expect(dispatch).toHaveBeenNthCalledWith(1, { + type: types.ENTITY_LOADING_REQUEST, + entityType, + id, + }); + expect(dispatch).toHaveBeenNthCalledWith(2, { + type: types.ENTITY_LOADING_SUCCESS, + entityType, + data: {foo: 'bar'}, + id, + }); }); }); @@ -285,7 +273,7 @@ describe('report loadEntityIfNeeded function tests', () => { const dispatch = jest.fn(); - const get = jest.fn().mockReturnValue(Promise.resolve([{id: 'foo'}])); + const get = jest.fn().mockResolvedValue([{id: 'foo'}]); const gmp = { [entityType]: { @@ -311,11 +299,7 @@ describe('report loadEntityIfNeeded function tests', () => { const dispatch = jest.fn(); - const get = jest.fn().mockReturnValue( - Promise.resolve({ - data: {foo: 'bar'}, - }), - ); + const get = jest.fn().mockResolvedValue({data: {foo: 'bar'}}); const gmp = { [entityType]: { @@ -332,21 +316,17 @@ describe('report loadEntityIfNeeded function tests', () => { expect(getState).toBeCalled(); expect(get).toBeCalledWith({id}, {details: 0, filter}); expect(dispatch).toHaveBeenCalledTimes(2); - expect(dispatch.mock.calls[0]).toEqual([ - { - type: types.ENTITY_LOADING_REQUEST, - entityType, - id, - }, - ]); - expect(dispatch.mock.calls[1]).toEqual([ - { - type: types.ENTITY_LOADING_SUCCESS, - entityType, - data: {foo: 'bar'}, - id, - }, - ]); + expect(dispatch).toHaveBeenNthCalledWith(1, { + type: types.ENTITY_LOADING_REQUEST, + entityType, + id, + }); + expect(dispatch).toHaveBeenNthCalledWith(2, { + type: types.ENTITY_LOADING_SUCCESS, + entityType, + data: {foo: 'bar'}, + id, + }); }); }); @@ -362,7 +342,7 @@ describe('report loadEntityIfNeeded function tests', () => { const dispatch = jest.fn(); - const get = jest.fn().mockReturnValue(Promise.resolve([{id: 'foo'}])); + const get = jest.fn().mockResolvedValue([{id: 'foo'}]); const gmp = { [entityType]: { @@ -389,7 +369,7 @@ describe('report loadEntityIfNeeded function tests', () => { const dispatch = jest.fn(); - const get = jest.fn().mockReturnValue(Promise.reject('An Error')); + const get = jest.fn().mockRejectedValue('An Error'); const gmp = { [entityType]: { diff --git a/gsa/src/web/store/entities/reports.js b/gsa/src/web/store/entities/reports.js index 2a73c11187..0f43e08f79 100644 --- a/gsa/src/web/store/entities/reports.js +++ b/gsa/src/web/store/entities/reports.js @@ -91,12 +91,8 @@ const loadEntityIfNeeded = gmp => (id, filter) => (dispatch, getState) => { // yet in the store. resolve() otherwise const rootState = getState(); const state = selector(rootState); - const reportsState = state.state; - if ( - state.isLoadingEntity(id) || - (isDefined(reportsState.byId) && isDefined(reportsState.byId[id])) - ) { + if (state.isLoadingEntity(id) || isDefined(state.getEntity(id))) { // we are already loading data or have it in the store return Promise.resolve(); }