Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
swaterkamp committed Oct 16, 2019
1 parent 3a7fb5c commit 2219310
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 69 deletions.
11 changes: 5 additions & 6 deletions gsa/src/web/pages/reports/scaninfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -89,18 +88,18 @@ 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 =
isDefined(task.isContainer) && task.isContainer()
? _('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 (
Expand Down
96 changes: 38 additions & 58 deletions gsa/src/web/store/entities/__tests__/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
});
});
Expand All @@ -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]: {
Expand All @@ -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,
});
});
});

Expand All @@ -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]: {
Expand All @@ -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]: {
Expand All @@ -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,
});
});
});

Expand All @@ -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]: {
Expand All @@ -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]: {
Expand Down
6 changes: 1 addition & 5 deletions gsa/src/web/store/entities/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 2219310

Please sign in to comment.