Skip to content

Commit

Permalink
refactor(Timestamp): use timestamps instead of dates in ecotag (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilian-delouvy authored Feb 14, 2022
1 parent aa83933 commit 77e4f9d
Show file tree
Hide file tree
Showing 33 changed files with 213 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {NAME, TYPE, CLASSIFICATION, MSG_REQUIRED, MSG_DATASET_NAME_ALREADY_EXIST
import React, { useReducer } from 'react';
import {fetchCreateDataset, fetchDatasets} from "../../Dataset.service";
import {resilienceStatus, withResilience} from "../../../shared/Resilience";
import {convertStringDateToDateObject} from "../../../date";
import withCustomFetch from "../../../withCustomFetch";
import compose from "../../../compose";

Expand Down Expand Up @@ -77,8 +76,8 @@ export const init = (fetch, dispatch) => async () => {
if(response.status >= 500) {
data = { datasets: [], status: resilienceStatus.ERROR };
} else {
const items = await response.json()
data = { datasets: convertStringDateToDateObject(items), status: resilienceStatus.SUCCESS };
const datasets = await response.json()
data = { datasets, status: resilienceStatus.SUCCESS };
}
dispatch( {type: 'init', data});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {fetchDataset, fetchLockDataset} from "../Dataset.service";
import {resilienceStatus, withResilience} from "../../shared/Resilience";
import {useParams} from "react-router-dom";
import withCustomFetch from "../../withCustomFetch";
import {convertStringDateToDateObject} from "../../date";


export const init = (fetch, setState) => async (id, state) => {
const response = await fetchDataset(fetch)(id);
Expand All @@ -20,12 +18,12 @@ export const init = (fetch, setState) => async (id, state) => {
data = { status: resilienceStatus.ERROR };
} else {
const dataset = await response.json()
const datasetData = convertStringDateToDateObject({ name: dataset.name,
const datasetData = { name: dataset.name,
id: dataset.id,
createDate: dataset.createDate,
isLock: dataset.isLocked,
type: dataset.type
});
};
const filesSend= dataset.files.map( f => { return { file: { id: f.id, type: f.contentType, size: f.size, name: f.fileName } }})
data = { status: resilienceStatus.SUCCESS, dataset:datasetData, files : {...state.files, filesSend} };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Action from "@axa-fr/react-toolkit-action";
import Tabs from "@axa-fr/react-toolkit-tabs/dist";
import '@axa-fr/react-toolkit-tabs/dist/tabs.scss';
import {computeNumberPages, filterPaging} from "../../shared/filtersUtils";
import {formatDateToString} from "../../date";
import {formatTimestampToString} from "../../date";

const bytesToSize=(bytes) => {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
Expand Down Expand Up @@ -61,7 +61,7 @@ const FileList = ({state, setState}) => {
<SectionRestitutionRow title="">
<SectionRestitutionColumn>
<Restitution label="Nom" value={state.dataset.name} />
<Restitution label="Date de création" value={formatDateToString(state.dataset.createDate)} />
<Restitution label="Date de création" value={formatTimestampToString(state.dataset.createDate)} />
<Restitution label="Type" value={state.dataset.type} />
</SectionRestitutionColumn>
<SectionRestitutionColumn>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Home from './Home';
import fetchDatasets from '../Dataset.service';
import { convertStringDateToDateObject } from '../../date';
import React, { useEffect, useReducer } from 'react';
import withCustomFetch from '../../withCustomFetch';
import {computeNumberPages, filterPaging, getItemsFiltered} from '../../shared/Home/Home.filters';
import { resilienceStatus, withResilience } from '../../shared/Resilience';
import fetchDatasets from "../Dataset.service";

const HomeWithResilience = withResilience(Home);

Expand All @@ -15,7 +14,7 @@ const init = (fetch, dispatch) => async () => {
data = { items: [], status: resilienceStatus.ERROR };
} else {
const items = await response.json()
data = { items: convertStringDateToDateObject(items), status: resilienceStatus.SUCCESS };
data = { items, status: resilienceStatus.SUCCESS };
}
dispatch( {type: 'init', data});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const fetch = async (url, config) => {
"type": "Image",
"classification": "Publique",
"numberFiles": 300,
"createDate": "30/10/2019"
"createDate": new Date("10-30-2019").getTime()
}])};
};

Expand All @@ -28,4 +28,3 @@ describe('Home.container', () => {
});

});

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Loader from '@axa-fr/react-toolkit-loader';
import HeaderColumnCell from "../../Project/List/ColumnHeader";
import Action from "@axa-fr/react-toolkit-action";
import {useHistory} from "react-router-dom";
import {formatTimestampToString} from "../../date";

const ItemsTable = ({items, filters, loaderMode, onChangePaging}) => {

Expand All @@ -13,7 +14,6 @@ const ItemsTable = ({items, filters, loaderMode, onChangePaging}) => {
const path = `datasets/${id}`
history.push(path);
};
const formatDateToString = createDate => (createDate && createDate instanceof Date) ? `${createDate.getDay().toString().padStart(2, '0')}/${createDate.getMonth().toString().padStart(2, '0')}/${createDate.getFullYear()}` : ``;

return(
<>
Expand All @@ -38,7 +38,7 @@ const ItemsTable = ({items, filters, loaderMode, onChangePaging}) => {
<Table.Header>
<Table.Tr>
<Table.Th>
<span className="af-table__th-content">Vérouiller</span>
<span className="af-table__th-content">Verrouiller</span>
</Table.Th>
<Table.Th>
<span className="af-table__th-content">Nom</span>
Expand All @@ -47,7 +47,7 @@ const ItemsTable = ({items, filters, loaderMode, onChangePaging}) => {
<span className="af-table__th-content">Classification</span>
</Table.Th>
<Table.Th>
<span className="af-table__th-content">Nombre de fichier</span>
<span className="af-table__th-content">Nombre de fichiers</span>
</Table.Th>
<Table.Th>
<span className="af-table__th-content">Type</span>
Expand All @@ -74,7 +74,7 @@ const ItemsTable = ({items, filters, loaderMode, onChangePaging}) => {
<Table.Td>{classification}</Table.Td>
<Table.Td>{numberFiles}</Table.Td>
<Table.Td>{type}</Table.Td>
<Table.Td>{formatDateToString(createDate)}</Table.Td>
<Table.Td>{formatTimestampToString(createDate)}</Table.Td>
<Table.Td>
<Action id="id" icon="edit" title="Editer" onClick={() => {editDatasetButton(id)}} />
</Table.Td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const items = [{
type: "Image",
classification: "Publique",
numberFiles: 300,
createDate: "30/10/2019"
createDate: new Date("01-28-2022").getTime()
}];

const filters = {
Expand Down Expand Up @@ -40,4 +40,4 @@ describe("Check Dataset ItemsTable behaviour", () => {
expect(asFragment()).toMatchSnapshot();
});

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ exports[`Home.container HomeContainer render correctly 1`] = `
<span
class="af-table__th-content"
>
Vérouiller
Verrouiller
</span>
</th>
<th
Expand All @@ -137,7 +137,7 @@ exports[`Home.container HomeContainer render correctly 1`] = `
<span
class="af-table__th-content"
>
Nombre de fichier
Nombre de fichiers
</span>
</th>
<th
Expand Down Expand Up @@ -214,7 +214,7 @@ exports[`Home.container HomeContainer render correctly 1`] = `
<td
class="af-table__cell"
>
NaN/NaN/NaN
30/10/2019
</td>
<td
class="af-table__cell"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports[`Check Dataset ItemsTable behaviour Should render correctly 1`] = `
<span
class="af-table__th-content"
>
Vérouiller
Verrouiller
</span>
</th>
<th
Expand All @@ -92,7 +92,7 @@ exports[`Check Dataset ItemsTable behaviour Should render correctly 1`] = `
<span
class="af-table__th-content"
>
Nombre de fichier
Nombre de fichiers
</span>
</th>
<th
Expand Down Expand Up @@ -168,7 +168,9 @@ exports[`Check Dataset ItemsTable behaviour Should render correctly 1`] = `
</td>
<td
class="af-table__cell"
/>
>
28/01/2022
</td>
<td
class="af-table__cell"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const items = [{
type: "Image",
classification: "Publique",
numberFiles: 300,
createDate: "30/10/2019"
createDate: new Date("10-30-2019").getTime()
}];

const filters = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const fetch = () => {
"dataSetId": "0004",
"classification": "Publique",
"numberTagToDo": 10,
"createDate": "04/04/2011",
"createDate": new Date("04-04-2011").getTime(),
"typeAnnotation": "NER",
"text": "Enim ad ex voluptate culpa non cillum eu mollit nulla ex pariatur duis. Commodo officia deserunt elit sint officia consequat elit laboris tempor qui est ex. Laborum magna id deserunt ut fugiat aute nulla in Lorem pariatur. Nostrud elit consectetur exercitation exercitation incididunt consequat occaecat velit voluptate nostrud sunt. Consectetur velit eu amet minim quis sunt in.",
"labels": [{"name": "Recto", "color": "#212121", "id": "0"}, {"name": "Verso", "color": "#ffbb00", "id": "1"}, {"name": "Signature", "color": "#f20713", "id": "2"}],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { fetchDatasets } from '../../../Dataset/Dataset.service';
import { fetchGroups } from '../../../Group/Group.service';
import { fetchProjects } from "../../Project.service";
import {convertStringDateToDateObject} from "../../../date";
import { resilienceStatus } from '../../../shared/Resilience';
import fetchDatasets from "../../../Dataset/Dataset.service";
import {fetchGroups} from "../../../Group/Group.service";
import {fetchProjects} from "../../Project.service";

export const init = (fetch, dispatch) => async () => {
const datasetsPromise = fetchDatasets(fetch)(true);
Expand All @@ -19,7 +18,7 @@ export const init = (fetch, dispatch) => async () => {
data = {
groups,
datasets,
projects: convertStringDateToDateObject(projects),
projects,
status: resilienceStatus.SUCCESS};
}
dispatch({ type: 'init', data});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import '@testing-library/jest-dom/extend-expect';
import React from 'react';
import {resilienceStatus} from "../../shared/Resilience";
import {init, initialState} from "./Annotation.hook";
import {reducer} from "./Annotation.reducer";

const fetch = () => Promise.resolve({
"id": "0001",
"name": "Relevé d'information",
"dataSetId": "0004",
"classification": "Publique",
"numberTagToDo": 10,
"createDate": "04/04/2011",
"typeAnnotation": "NER",
"text": "Enim ad ex voluptate culpa non cillum eu mollit nulla ex pariatur duis. Commodo officia deserunt elit sint officia consequat elit laboris tempor qui est ex. Laborum magna id deserunt ut fugiat aute nulla in Lorem pariatur. Nostrud elit consectetur exercitation exercitation incididunt consequat occaecat velit voluptate nostrud sunt. Consectetur velit eu amet minim quis sunt in.",
"labels": [{"name": "Recto", "color": "#212121", "id": 0}, {"name": "Verso", "color": "#ffbb00", "id": 1}, {"name": "Signature", "color": "#f20713", "id": 2}],
"users": [
{"annotationCounter": 10,
"annotationToBeVerified": 1,
"email": "[email protected]"},
{"annotationCounter": 24,
"annotationToBeVerified": 5,
"email": "[email protected]"},
{"annotationCounter": 35,
"annotationToBeVerified": 15,
"email": "[email protected]"}
]
});

describe('AnnotationDispatch.container', () => {
const givenUser = {};
const givenDataset = {
"id": "0001",
"name": "Carte verte",
"type": "Image",
"classification": "Publique",
"numberFiles": 300,
"createDate": "30/10/2019"
};
const givenProject = {
"id": "0001",
"name": "Relevé d'information",
"dataSetId": "0004",
"classification": "Publique",
"numberTagToDo": 10,
"createDate": new Date("04-04-2011").getTime(),
"typeAnnotation": "NER",
"text": "Enim ad ex voluptate culpa non cillum eu mollit nulla ex pariatur duis. Commodo officia deserunt elit sint officia consequat elit laboris tempor qui est ex. Laborum magna id deserunt ut fugiat aute nulla in Lorem pariatur. Nostrud elit consectetur exercitation exercitation incididunt consequat occaecat velit voluptate nostrud sunt. Consectetur velit eu amet minim quis sunt in.",
"labels": [{"name": "Recto", "color": "#212121", "id": 0}, {"name": "Verso", "color": "#ffbb00", "id": 1}, {"name": "Signature", "color": "#f20713", "id": 2}],
"users": [
{"annotationCounter": 10,
"annotationToBeVerified": 1,
"email": "[email protected]"},
{"annotationCounter": 24,
"annotationToBeVerified": 5,
"email": "[email protected]"},
{"annotationCounter": 35,
"annotationToBeVerified": 15,
"email": "[email protected]"}
]
};

function fail(message = "The fail function was called") {
throw new Error(message);
}

/*it('AnnotationDispatchContainer render correctly', async () => {
const { getByText } = render(<Router><AnnotationDispatchContainer fetch={fetch} user={givenUser}/></Router>);
const messageEl = await waitFor(() => getByText('Soumettre l\'annotation'));
expect(messageEl).toHaveTextContent(
'Soumettre l\'annotation'
);
});*/

describe('.reducer()', () => {
it('should set the new fields with asked values after onChange action', () => {
const givenState = {...initialState};
const givenAction = {
type: 'init',
data: {
project : givenProject,
status: resilienceStatus.LOADING
}
}

const actualState = reducer(givenState, givenAction);

expect(actualState).toMatchObject({
...givenState,
project : givenProject,
});
});
it('should throw an error by default', (done) => {
const givenState = {};
const givenAction = {
type: 'unknown',
}

try {
reducer(givenState, givenAction);
fail(error);
} catch (error) {
done();
}
});
});

describe('.init()', () => {
let givenFetch;
let givenDispatch;
let givenFetchRejected;

beforeEach(() => {
givenFetch = jest.fn(() => Promise.resolve({ok: true, json: () => Promise.resolve(givenProject)}));
givenDispatch = jest.fn();
givenFetchRejected = jest.fn(() => Promise.reject("ERROR"));
});
afterEach(() => {
jest.clearAllMocks();
});

it('should call init and dispatch', async () => {
try {
await init(givenFetch, givenDispatch)(givenProject.id);
expect(givenDispatch).toHaveBeenCalledWith( { type: "init", data: { project: givenProject, status: resilienceStatus.SUCCESS } });
} catch (error) {
fail(error);
}
});

it('should fail because of error during init', async () => {
try {
await init(givenFetch, givenDispatch);
fail(error);
} catch (error) {
expect(givenFetch).toHaveBeenCalledTimes(0);
}
});
});
});

Loading

0 comments on commit 77e4f9d

Please sign in to comment.