diff --git a/src/js/components/operations/document/edition/edition.js b/src/js/components/operations/document/edition/edition.js
index 7067d3270..aab262ec6 100644
--- a/src/js/components/operations/document/edition/edition.js
+++ b/src/js/components/operations/document/edition/edition.js
@@ -267,7 +267,6 @@ class OperationsDocumentationEdition extends Component {
event.stopPropagation(),
})}
>
} files
+ * @returns {{errorMessage: string, fields: { file: boolean}}}
+ */
+function verifyFile(files = []) {
+ const regexp = /^[a-zA-Z1-9-_\.]*$/;
+ let errorMessage = '';
+
+ if (files.length === 0) {
+ errorMessage = D.requiredFile;
+ } else {
+ const wrongFile = files
+ .map(file => file.name)
+ .find(fileName => !regexp.test(fileName));
+ if (wrongFile) {
+ errorMessage = D.wrongFileName;
+ }
+ }
+ return {
+ errorMessage,
+ fields: { file: errorMessage !== '' },
+ };
+}
+
export function validate(document, type, files) {
- console.log(files);
const fields = {};
let errorMessage = '';
if (!document.labelLg1 || !document.labelLg2) {
@@ -15,12 +43,11 @@ export function validate(document, type, files) {
} else if (type === LINK && !/https*\:\/\//.test(document.url)) {
errorMessage = D.badUrl;
fields.url = true;
- } else if (type === DOCUMENT && files.length === 0) {
- errorMessage = D.requiredFile;
- fields.file = true;
} else if (!document.lang) {
errorMessage = D.requiredLang;
fields.lang = true;
+ } else if (type === DOCUMENT) {
+ return verifyFile(files);
}
return {
fields,
diff --git a/src/js/components/operations/document/edition/validation.spec.js b/src/js/components/operations/document/edition/validation.spec.js
new file mode 100644
index 000000000..77186cf4d
--- /dev/null
+++ b/src/js/components/operations/document/edition/validation.spec.js
@@ -0,0 +1,39 @@
+import { validate } from './validation';
+import { DOCUMENT } from '../utils';
+
+describe('validate', () => {
+ describe('documents', () => {
+ const type = DOCUMENT;
+ const document = {
+ labelLg1: '1',
+ labelLg2: '2',
+ lang: 'fr',
+ };
+ it('should return an error if the files is undefined', () => {
+ expect(validate(document, type)).toEqual({
+ errorMessage: 'The file is required',
+ fields: { file: true },
+ });
+ });
+ it('should return an error if the files is an empty array', () => {
+ expect(validate(document, type, [])).toEqual({
+ errorMessage: 'The file is required',
+ fields: { file: true },
+ });
+ });
+ it('should return an error if ta name is not valid', () => {
+ expect(validate(document, type, [{ name: 'name with space' }])).toEqual({
+ errorMessage: 'The name of the file incorrect',
+ fields: { file: true },
+ });
+ });
+ it('should not return any error', () => {
+ expect(
+ validate(document, type, [{ name: 'name_without_space' }])
+ ).toEqual({
+ errorMessage: '',
+ fields: { file: false },
+ });
+ });
+ });
+});
diff --git a/src/js/components/shared/pagination/index.js b/src/js/components/shared/pagination/index.js
index 3700521dd..dad0cf49d 100644
--- a/src/js/components/shared/pagination/index.js
+++ b/src/js/components/shared/pagination/index.js
@@ -12,8 +12,20 @@ function checkInvalidPage(targetPage, listSize) {
* context: The context of the page. Used for theming
*/
class Pagination extends Component {
- constructor() {
- super();
+ static propTypes = {
+ itemEls: PropTypes.arrayOf(PropTypes.element).isRequired,
+ itemsPerPage: PropTypes.string.isRequired,
+ context: PropTypes.oneOf([
+ '',
+ 'concepts',
+ 'collections',
+ 'classifications',
+ 'operations',
+ ]),
+ };
+
+ constructor(props) {
+ super(props);
this.state = {
currentPage: 1,
};
@@ -46,20 +58,18 @@ class Pagination extends Component {
pageNumbers.push(i);
}
- function activePage(page) {
- return page === currentPage ? 'page-item active' : 'page-item';
+ function isActivePage(page) {
+ return page === currentPage;
}
function isDisabled(targetPage) {
- return checkInvalidPage(targetPage, pageNumbers.length)
- ? 'page-item disabled'
- : 'page-item';
+ return checkInvalidPage(targetPage, pageNumbers.length);
}
const renderPageNumbers = pageNumbers
.filter(number => number - 3 < currentPage && number + 3 > currentPage)
.map(number => {
return (
-
+