Skip Android health-checks when the "Android Developer" option is disabled in Flipper settings

Summary:
Skip Android health-checks when the "Android Developer" option is disabled in Flipper settings.

Also made some refactoring to use immer for healthcheck reducer.

Reviewed By: mweststrate

Differential Revision: D19088322

fbshipit-source-id: 801d874b6e7e5af80802b4bf4313d98f1cee13f6
This commit is contained in:
Anton Nikolaev
2019-12-16 16:35:49 -08:00
committed by Facebook Github Bot
parent be53990613
commit d32774f439
6 changed files with 256 additions and 188 deletions

View File

@@ -14,7 +14,8 @@ import {
HealthcheckReportCategory,
HealthcheckReportItem,
finishHealthchecks,
updateHealthcheckReportItem,
updateHealthcheckReportItemStatus,
updateHealthcheckReportCategoryStatus,
} from '../healthchecks';
const HEALTHCHECK_ITEM: HealthcheckReportItem = {
@@ -70,14 +71,14 @@ test('updateHealthcheck', () => {
let res = reducer(undefined, initHealthcheckReport(report));
res = reducer(
res,
updateHealthcheckReportItem(0, 0, {
label: 'Updated Test Item',
updateHealthcheckReportItemStatus(0, 0, {
message: 'Updated Test Message',
status: 'SUCCESS',
}),
);
expect(res.healthcheckReport.isHealthcheckInProgress).toBeTruthy();
expect(res.healthcheckReport.categories[0].checks[0].label).toEqual(
'Updated Test Item',
expect(res.healthcheckReport.categories[0].checks[0].message).toEqual(
'Updated Test Message',
);
expect(res.healthcheckReport.categories[0].checks[0].status).toEqual(
'SUCCESS',
@@ -89,3 +90,24 @@ test('updateHealthcheck', () => {
'WARNING',
);
});
test('updateHealthcheckCategoryStatus', () => {
const report = {
isHealthcheckInProgress: true,
categories: [HEALTHCHECK_CATEGORY, HEALTHCHECK_CATEGORY],
};
let res = reducer(undefined, initHealthcheckReport(report));
res = reducer(
res,
updateHealthcheckReportCategoryStatus(1, {
status: 'FAILED',
message: 'Error message',
}),
);
expect(res.healthcheckReport.isHealthcheckInProgress).toBeTruthy();
expect(res.healthcheckReport.categories[0].label).toEqual('Test Category');
expect(res.healthcheckReport.categories[0].status).toEqual('WARNING');
expect(res.healthcheckReport.categories[1].label).toEqual('Test Category');
expect(res.healthcheckReport.categories[1].status).toEqual('FAILED');
expect(res.healthcheckReport.categories[1].message).toEqual('Error message');
});

View File

@@ -8,6 +8,7 @@
*/
import {Actions} from './';
import {produce} from 'flipper';
export type State = {
healthcheckReport: HealthcheckReport;
@@ -19,11 +20,18 @@ export type Action =
payload: HealthcheckReport;
}
| {
type: 'UPDATE_HEALTHCHECK_REPORT_ITEM';
type: 'UPDATE_HEALTHCHECK_REPORT_ITEM_STATUS';
payload: {
categoryIdx: number;
itemIdx: number;
item: HealthcheckReportItem;
status: HealthcheckResult;
};
}
| {
type: 'UPDATE_HEALTHCHECK_REPORT_CATEGORY_STATUS';
payload: {
categoryIdx: number;
status: HealthcheckResult;
};
}
| {
@@ -44,6 +52,7 @@ export type HealthcheckStatus =
| 'IN_PROGRESS'
| 'SUCCESS'
| 'FAILED'
| 'SKIPPED'
| 'WARNING';
export type HealthcheckResult = {
@@ -58,73 +67,64 @@ export type HealthcheckReportItem = {
export type HealthcheckReportCategory = {
label: string;
status: HealthcheckStatus;
checks: Array<HealthcheckReportItem>;
};
} & HealthcheckResult;
export type HealthcheckReport = {
isHealthcheckInProgress: boolean;
categories: Array<HealthcheckReportCategory>;
};
const updateReportItem = produce(
(
draft: State,
payload: {
categoryIdx: number;
itemIdx: number;
status: HealthcheckResult;
},
) => {
Object.assign(
draft.healthcheckReport.categories[payload.categoryIdx].checks[
payload.itemIdx
],
payload.status,
);
},
);
const updateCategoryStatus = produce(
(draft: State, payload: {categoryIdx: number; status: HealthcheckResult}) => {
Object.assign(
draft.healthcheckReport.categories[payload.categoryIdx],
payload.status,
);
},
);
const initReport = produce((draft: State, report: HealthcheckReport) => {
draft.healthcheckReport = report;
});
const setIsInProgress = produce((draft: State, isInProgress: boolean) => {
draft.healthcheckReport.isHealthcheckInProgress = isInProgress;
});
export default function reducer(
state: State | undefined = INITIAL_STATE,
draft: State | undefined = INITIAL_STATE,
action: Actions,
): State {
if (action.type === 'INIT_HEALTHCHECK_REPORT') {
return {
...state,
healthcheckReport: action.payload,
};
} else if (action.type === 'START_HEALTHCHECKS') {
return {
...state,
healthcheckReport: {
...state.healthcheckReport,
isHealthcheckInProgress: true,
},
};
} else if (action.type === 'FINISH_HEALTHCHECKS') {
return {
...state,
healthcheckReport: {
...state.healthcheckReport,
isHealthcheckInProgress: false,
},
};
} else if (action.type === 'UPDATE_HEALTHCHECK_REPORT_ITEM') {
return {
...state,
healthcheckReport: {
...state.healthcheckReport,
categories: [
...state.healthcheckReport.categories.slice(
0,
action.payload.categoryIdx,
),
{
...state.healthcheckReport.categories[action.payload.categoryIdx],
checks: [
...state.healthcheckReport.categories[
action.payload.categoryIdx
].checks.slice(0, action.payload.itemIdx),
{
...action.payload.item,
},
...state.healthcheckReport.categories[
action.payload.categoryIdx
].checks.slice(action.payload.itemIdx + 1),
],
},
...state.healthcheckReport.categories.slice(
action.payload.categoryIdx + 1,
),
],
},
};
} else {
return state;
}
return action.type === 'INIT_HEALTHCHECK_REPORT'
? initReport(draft, action.payload)
: action.type === 'START_HEALTHCHECKS'
? setIsInProgress(draft, true)
: action.type === 'FINISH_HEALTHCHECKS'
? setIsInProgress(draft, false)
: action.type === 'UPDATE_HEALTHCHECK_REPORT_ITEM_STATUS'
? updateReportItem(draft, action.payload)
: action.type === 'UPDATE_HEALTHCHECK_REPORT_CATEGORY_STATUS'
? updateCategoryStatus(draft, action.payload)
: draft;
}
export const initHealthcheckReport = (report: HealthcheckReport): Action => ({
@@ -132,16 +132,27 @@ export const initHealthcheckReport = (report: HealthcheckReport): Action => ({
payload: report,
});
export const updateHealthcheckReportItem = (
export const updateHealthcheckReportItemStatus = (
categoryIdx: number,
itemIdx: number,
item: HealthcheckReportItem,
status: HealthcheckResult,
): Action => ({
type: 'UPDATE_HEALTHCHECK_REPORT_ITEM',
type: 'UPDATE_HEALTHCHECK_REPORT_ITEM_STATUS',
payload: {
categoryIdx,
itemIdx,
item,
status,
},
});
export const updateHealthcheckReportCategoryStatus = (
categoryIdx: number,
status: HealthcheckResult,
): Action => ({
type: 'UPDATE_HEALTHCHECK_REPORT_CATEGORY_STATUS',
payload: {
categoryIdx,
status,
},
});