Skip to content

Commit

Permalink
Merge pull request #42 from EmmanuelDemey/master
Browse files Browse the repository at this point in the history
zenika
  • Loading branch information
alicela authored May 10, 2019
2 parents f4c2f53 + 5c13827 commit 22f228d
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 134 deletions.
4 changes: 2 additions & 2 deletions cypress/fixtures/sims.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"uri": "uri1-bis",
"url": "http://google.fr?q=url-1",
"updatedDate": "01/01/2019",
"lastRefresh": "01/01/2019",
"labelLg1": "labelLg1-0",
"labelLg2": "labelLg2-0",
"lang": "fr",
Expand All @@ -27,7 +27,7 @@
{
"uri": "uri2-bis",
"url": "http://google.fr?q=url-2",
"updatedDate": "01/02/2019",
"lastRefresh": "01/02/2019",
"labelLg1": "labelLg1-1",
"labelLg2": "labelLg2-1",
"descriptionLg1": "descriptionLg1-2",
Expand Down
17 changes: 7 additions & 10 deletions cypress/integration/home.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
describe('Home Page', function() {
it(`Should go to the Concepts page and come back`, function() {
cy.server().visit(`/`);
cy.get('.img-block a:nth-child(1)')
.first()
.click();
cy.get('li:nth-child(1) a').click();

cy.url().should('match', /\/concepts$/);
cy.go('back');
Expand All @@ -14,10 +12,7 @@ describe('Home Page', function() {

it(`Should go to the Nomenclatures page and come back`, function() {
cy.server().visit(`/`);
//cy.get('a[href="/classifications"]');
cy.get('.img-block a:nth-child(2)')
.first()
.click();
cy.get('li:nth-child(2) a').click();
cy.url().should('match', /\/classifications$/);
cy.go('back');
cy.get('.page-title').contains(
Expand All @@ -26,13 +21,15 @@ describe('Home Page', function() {
});
it(`Should go to the Operations page and come back`, function() {
cy.server().visit(`/`);
cy.get('.img-block a:nth-child(3)')
.first()
.click();
cy.get('li:nth-child(3) a').click();
cy.url().should('match', /\/operations\/series$/);
cy.go('back');
cy.get('.page-title').contains(
'Application de gestion des métadonnées de référence'
);
});
it(`Should contain a footer`, function() {
cy.server().visit(`/`);
cy.get('footer').should('exist');
});
});
58 changes: 2 additions & 56 deletions src/js/actions/operations/documents/list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import api from 'js/remote-api/operations-api';
import api from 'js/remote-api/api';
import * as A from 'js/actions/constants';
import { sortArray } from 'js/utils/array-utils';

Expand All @@ -16,64 +16,10 @@ export default () => dispatch => {
payload: { results: sortByLabel(results) },
}),
err => {
const results = [
{
uri: 'uri1-bis',
url: 'http://google.fr?q=url-1',
updatedDate: '01/01/2019',
lang: 'fr',
labelLg1: 'Document 1 - label en Langue 1',
labelLg2: 'Document 1 - label en Langue 2',
descriptionLg1: 'Description 1 en Langue 1',
descriptionLg2: 'Description 1 en Langue 2',
},
{
uri: 'uri2-bis',
url: 'http://google.fr?q=url-2',
updatedDate: '01/02/2019',
labelLg1: 'Document 2 - label en Langue 1',
labelLg2: 'Document 2 - label en Langue 2',
descriptionLg1: 'Description 2 en Langue 1',
descriptionLg2: 'Description 2 en Langue 2',
},
{
uri: 'uri3-bis',
url: 'http://google.fr?q=url-2',
labelLg1: 'Document 3 - label en Langue 1',
labelLg2: 'Document 3 - label en Langue 2',
descriptionLg1: 'Description 3 en Langue 1',
descriptionLg2: 'Description 3 en Langue 2',
lang: 'fr',
},

{
uri: 'uri5-bis',
url: 'http://google.fr?q=url-2',
labelLg1: 'Document 5 - label en Langue 1',
labelLg2: 'Document 5 - label en Langue 2',
descriptionLg1: 'Description 5 en Langue 1',
descriptionLg2: 'Description 5 en Langue 2',
lang: 'fr',
},
{
uri: 'uri4-bis',
url: 'http://google.fr?q=url-2',
updatedDate: '01/02/2019',
labelLg1: 'Document 4 - label en Langue 1',
labelLg2: 'Document 4 - label en Langue 2',
descriptionLg1: 'Description 4 en Langue 1',
descriptionLg2: 'Description 4 en Langue 2',
},
];
dispatch({
type: A.LOAD_OPERATIONS_DOCUMENTS_SUCCESS,
payload: { results: sortByLabel(results) },
});

/*dispatch({
type: A.LOAD_OPERATIONS_DOCUMENTS_FAILURE,
payload: { err },
})*/
})
}
);
};
2 changes: 1 addition & 1 deletion src/js/actions/operations/series/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const saveSerie = (series, callback) => dispatch => {
type: A.SAVE_OPERATIONS_SERIE_SUCCESS,
payload: {
...series,
id
id,
},
});
callback(id);
Expand Down
4 changes: 2 additions & 2 deletions src/js/actions/operations/sims/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default id => (dispatch, getState) => {
{
uri: 'uri1-bis',
url: 'http://google.fr?q=url-1',
updatedDate: '01/01/2019',
lastRefresh: '01/01/2019',
lang: 'fr',
labelLg1: 'Document 1 - label en Langue 1',
labelLg2: 'Document 1 - label en Langue 2',
Expand All @@ -119,7 +119,7 @@ export default id => (dispatch, getState) => {
{
uri: 'uri2-bis',
url: 'http://google.fr?q=url-2',
updatedDate: '01/02/2019',
lastRefresh: '01/02/2019',
labelLg1: 'Document 2 - label en Langue 1',
labelLg2: 'Document 2 - label en Langue 2',
descriptionLg1: 'Description 2 en Langue 1',
Expand Down
60 changes: 32 additions & 28 deletions src/js/components/operations/msd/documents/documents-bloc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import D from 'js/i18n';
import loadDocuments from 'js/actions/operations/documents/list';
import './style.scss';
import { getLang } from 'js/i18n/build-dictionary';
import { LOADED, NOT_LOADED } from 'js/constants';
import { NOT_LOADED } from 'js/constants';
import {
getOperationsDocumentsStatus,
getOperationsDocuments,
} from 'js/reducers/operations/selector';
/**
* @typedef {Object} DocumentsBlocProps
* @property {import('js/actions/operations/sims/item').SimsDocuments[]=} documents
* @property {import('js/types').SimsDocuments[]=} documents
* @property {String=} localPrefix
* @property {Boolean=} editMode
* @property {(string) => void } deleteHandler
* @property {(string) => void } addHandler
* @property {import('js/actions/operations/sims/item').SimsDocuments[]} documentStores
* @property {import('js/types').SimsDocuments[]} documentStores
*/

/**
Expand All @@ -32,6 +36,7 @@ export function DocumentsBloc({
}) {
const currentDocuments = sortArray(`label${localPrefix}`)(documents);
const currentDocumentsIds = currentDocuments.map(doc => doc.uri);

const otherDocuments = sortArray(`label${localPrefix}`)(
documentStores.filter(
document => !currentDocumentsIds.includes(document.uri)
Expand All @@ -41,13 +46,13 @@ export function DocumentsBloc({
const [panelStatus, setPanelStatus] = useState(false);

function addAsideToTheDocument(document) {
let updatedDate;
if (document.updatedDate) {
updatedDate = new Intl.DateTimeFormat(getLang()).format(
new Date(document.updatedDate)
let lastRefresh;
if (document.lastRefresh) {
lastRefresh = new Intl.DateTimeFormat(getLang()).format(
new Date(document.lastRefresh)
);
}
const aside = [document.lang, updatedDate].filter(val => !!val).join('-');
const aside = [document.lang, lastRefresh].filter(val => !!val).join('-');
return {
...document,
aside,
Expand All @@ -69,17 +74,21 @@ export function DocumentsBloc({
document,
btnBlocFunction = defaultBtnBlocFunction
) {
const label =
document[`label${localPrefix}`] || document.labelLg1 || document.labelLg2;
return (
<li className="list-group-item" key={document.uri}>
<a
target="_blank"
rel="noopener noreferrer"
href={document.url}
title={document[`description${localPrefix}`]}
>
{document[`label${localPrefix}`]}
</a>
<i>({document.aside})</i>
<li className="list-group-item documentbloc__item" key={document.uri}>
<span>
<a
target="_blank"
rel="noopener noreferrer"
href={document.url}
title={document[`description${localPrefix}`]}
>
{label}
</a>
<i>({document.aside})</i>
</span>
{editMode && !isSecondLang && btnBlocFunction(document)}
</li>
);
Expand All @@ -93,8 +102,7 @@ export function DocumentsBloc({
.map(document => displayHTMLForDocument(document))}
</ul>
)}

{editMode && !isSecondLang && otherDocuments.length > 0 && (
{editMode && !isSecondLang && (
<div className="panel panel-default">
<div className="panel-heading">
<button
Expand All @@ -109,7 +117,7 @@ export function DocumentsBloc({
}`}
aria-hidden="true"
/>
{D.addDocument}
{D.addDocument} ({otherDocuments.length})
</button>
</div>
{panelStatus && (
Expand Down Expand Up @@ -146,11 +154,7 @@ class DocumentsBlocContainer extends Component {
}
}
render() {
return (
this.props.documentStoresStatus === LOADED && (
<DocumentsBloc {...this.props} />
)
);
return <DocumentsBloc {...this.props} />;
}
}

Expand All @@ -160,8 +164,8 @@ const mapDispatchToProps = {

const mapStateToProps = state => {
return {
documentStoresStatus: state.operationsDocuments.status,
documentStores: state.operationsDocuments.results,
documentStoresStatus: getOperationsDocumentsStatus(state),
documentStores: getOperationsDocuments(state),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const documents = [
{
uri: 'uri1-bis',
url: 'http://google.fr?q=url-1',
updatedDate: '2019-03-04T10:00:00.000Z',
lastRefresh: '2019-03-04T10:00:00.000Z',
labelLg1: 'B labelLg1-0',
labelLg2: 'B labelLg2-0',
lang: 'fr',
Expand All @@ -23,7 +23,7 @@ const documents = [
{
uri: 'uri2-bis',
url: 'http://google.fr?q=url-2',
updatedDate: '2019-04-04T10:00:00.000Z',
lastRefresh: '2019-04-04T10:00:00.000Z',
labelLg1: 'A labelLg1-1',
labelLg2: 'A labelLg2-1',
descriptionLg1: 'descriptionLg1-2',
Expand Down Expand Up @@ -69,11 +69,11 @@ describe('DocumentsBloc', () => {

general.find('li').forEach((li, i) => {
expect(li.html()).toEqual(
`<li class="list-group-item"><a target="_blank" rel="noopener noreferrer" href="${
`<li class="list-group-item documentbloc__item"><span><a target="_blank" rel="noopener noreferrer" href="${
orderedList[i].url
}" title="${orderedList[i].descriptionLg1}">${
orderedList[i].labelLg1
}</a><i>(${orderedList[i].aside})</i></li>`
}</a><i>(${orderedList[i].aside})</i></span></li>`
);
});
});
Expand All @@ -89,11 +89,11 @@ describe('DocumentsBloc', () => {

general.find('li').forEach((li, i) => {
expect(li.html()).toEqual(
`<li class="list-group-item"><a target="_blank" rel="noopener noreferrer" href="${
`<li class="list-group-item documentbloc__item"><span><a target="_blank" rel="noopener noreferrer" href="${
orderedList[i].url
}" title="${orderedList[i].descriptionLg2}">${
orderedList[i].labelLg2
}</a><i>(${orderedList[i].aside})</i></li>`
}</a><i>(${orderedList[i].aside})</i></span></li>`
);
});
});
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('DocumentsBloc', () => {
});
});

it('should not display the Add Document button if there is not more document to add', () => {
it('should display the Add Document button if there is not more document to add', () => {
const general = shallow(
<DocumentsBloc
documents={documents}
Expand All @@ -140,7 +140,7 @@ describe('DocumentsBloc', () => {
/>
);

expect(general.find('.documentsbloc__add')).toHaveLength(0);
expect(general.find('.documentsbloc__add')).toHaveLength(1);
});
it('should display the Add Document button if there is more than on document available', () => {
const general = shallow(
Expand All @@ -158,7 +158,7 @@ describe('DocumentsBloc', () => {
/>
);

expect(general.find('.documentsbloc__add')).toHaveLength(0);
expect(general.find('.documentsbloc__add')).toHaveLength(1);
});

it('should not display the Add Document button for Lg2', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@
padding-left: 0;
}
}

.documentbloc__item {
display: flex;

span {
flex: 2 1 auto;
}
}
Loading

0 comments on commit 22f228d

Please sign in to comment.