diff --git a/assets/js/src/softwareForm.js b/assets/js/src/softwareForm.js index da161f869..3c3821d71 100644 --- a/assets/js/src/softwareForm.js +++ b/assets/js/src/softwareForm.js @@ -436,3 +436,21 @@ function resetFieldsAdmin() { $('#enteam').val(''); $('#frteam').val(''); } + +window.softwareForm_func = { + getsoftwareObject, + // softwareObject, + getSelectedOrgType, + submitSoftwareFormNewAdmin, + getConfigUpdateSoftwareNewAdmin, + getConfigNewSoftwareNewAdmin, + submitFormSoftware, + getConfigUpdate, + getConfigNew, + selectSoftware, + addValueToFieldsSoftware, + resetFieldsSoftware, + selectAdmin, + addValueToFieldsAdmin, + resetFieldsAdmin, +}; diff --git a/assets/js/src/validation.js b/assets/js/src/validation.js index 16f2f6ec3..492604ad7 100644 --- a/assets/js/src/validation.js +++ b/assets/js/src/validation.js @@ -74,3 +74,8 @@ function submitInit() { } return valid; } + +//Allows use of the function for testing so there isn't any real submission happening +window.submit_init = { + submitInit, +}; diff --git a/cypress/integration/unit-tests/open-software/software-common-part.spec.js b/cypress/integration/unit-tests/open-software/software-common-part.spec.js new file mode 100644 index 000000000..3125fba46 --- /dev/null +++ b/cypress/integration/unit-tests/open-software/software-common-part.spec.js @@ -0,0 +1,59 @@ +context('Common parts', () => { + const selectTags = [ + '#dt_govLevel', + '#dt_category', + '#dt_licence', + '#dt_tag' + ]; + // eslint-disable-next-line no-undef + beforeEach(() => { + cy.visit('http://localhost:4000/ore-ero/fr/logiciels-libres.html'); + }); + + it('should reset inputs', function() { + //select first element of the select + //should test if it's null + selectTags.forEach(selectTag => { + cy.get(`${selectTag} > option`) + .eq(1) + .then(element => { + cy.get(selectTag).select(element.val()); + }); + }); + + cy.get('.wb-tables-filter > .row > :nth-child(2) > .btn').click(); + + selectTags.forEach(selectTag => { + cy.get(`${selectTag} > option`) + .eq(0) + .should('be.selected'); + }); + }); + + it('should filter the first element with the right values', () => { + cy.get('.sorting_1') + .first() + .then(projectName => { + cy.get('tbody > :nth-child(1) > :nth-child(2)').then(category => { + cy.get(`#dt_category`).select(category.text().trim()); + }); + cy.get('tbody > :nth-child(1) > :nth-child(4)').then(licence => { + cy.get(`#dt_licence`).select(licence.text().trim()); + }); + cy.get('.wb-tables-filter > .row > :nth-child(1) > .btn').click(); + cy.get(':nth-child(1) > .sorting_1').contains(projectName.text().trim()); + }); + }); + + it('should open the correct modal', () => { + //25, 25 should hit the link no matter the size of the box + cy.get(':nth-child(1) > .sorting_1').click(25, 25); + cy.get(':nth-child(1) > .sorting_1').then(name => { + cy.get('.wb-overlay.open').contains(name.text().trim()); + }); + + // click on the close button + cy.get('.wb-overlay.open .btn').click(); + cy.get('.wb-overlay').should('not.be.visible'); + }); + }); \ No newline at end of file diff --git a/cypress/integration/unit-tests/open-software/software-en-date.spec.js b/cypress/integration/unit-tests/open-software/software-en-date.spec.js new file mode 100644 index 000000000..b5e686dce --- /dev/null +++ b/cypress/integration/unit-tests/open-software/software-en-date.spec.js @@ -0,0 +1,70 @@ +/// +/* global cy, context, it, before, expect */ + +context('date_func.js on English Form page', () => { + const now = new Date(); + const output = (now.getFullYear() + + '-' + + ((now.getMonth() + 1) < 10 ? '0' : '') + + (now.getMonth() + 1) + + '-' + + ((now.getDate()) < 10 ? '0' : '') + + (now.getDate()) + ); + + before(() => { + cy.visit('http://localhost:4000/ore-ero/en/open-source-software-form.html'); + }); + + it('Loads the script', () => { + cy.window().should('have.property', 'Date'); + }); + + it('It should call and return Date.now()', () => { + cy.window().then(win => { + let value = win.date_func.getToday(); + expect(value).to.equal(output); + }); + }); + + it('It should not equal to day time', () => { + cy.window().then(win => { + const outputDate = new Date(Date.now()); + expect(win.date_func.getToday()).not.equal(outputDate); + }); + }); +}); + +context('date_func.js on French Form page', () => { + const now = new Date(); + const output = (now.getFullYear() + + '-' + + ((now.getMonth() + 1) < 10 ? '0' : '') + + (now.getMonth() + 1) + + '-' + + ((now.getDate()) < 10 ? '0' : '') + + (now.getDate()) + ); + + before(() => { + cy.visit('http://localhost:4000/ore-ero/fr/logiciel-libre-formulaire.html'); + }); + + it('Loads the script', () => { + cy.window().should('have.property', 'Date'); + }); + + it('It should call and return Date.now()', () => { + cy.window().then(win => { + let value = win.date_func.getToday(); + expect(value).to.equal(output); + }); + }); + + it('It should not equal to day time', () => { + cy.window().then(win => { + const outputDate = new Date(Date.now()); + expect(win.date_func.getToday()).not.equal(outputDate); + }); + }); +}); \ No newline at end of file diff --git a/cypress/integration/unit-tests/open-software/software-form.spec.js b/cypress/integration/unit-tests/open-software/software-form.spec.js new file mode 100644 index 000000000..4a27688ca --- /dev/null +++ b/cypress/integration/unit-tests/open-software/software-form.spec.js @@ -0,0 +1,15 @@ +/// +/* global cy, context, it, date_func */ + +context('softwareForm.js', () => { + let softwareObject = []; + + before(() => { + cy.visit('http://localhost:4000/ore-ero/en/open-source-software-form.html'); + }); + + it('Loads the script', () => { + cy.window().should('have.property', 'getsoftwareObject'); + }); + +}); diff --git a/cypress/integration/unit-tests/open-software/software.spec.js b/cypress/integration/unit-tests/open-software/software.spec.js new file mode 100644 index 000000000..823349476 --- /dev/null +++ b/cypress/integration/unit-tests/open-software/software.spec.js @@ -0,0 +1,225 @@ +/// +/* global cy, context, it */ +context('Open Source Software on the English page', () => { + before(() => { + cy.visit('http://localhost:4000/ore-ero/en/open-source-softwares.html'); + }); + + it('Loads the English page', () => { + cy.get('#wb-cont').contains('Open Source Software'); + }); + + it('Dynamically filters on the English page', () => { + cy.get('#dataset-filter_filter') + .find('input') + .type('jekyll'); + + cy.get('#dataset-filter') + .find('tbody>tr') + .first() + .find('td>a') + .first() + .contains('Jekyll'); + }); + + it('Dynamically filters on the English page', () => { + cy.get('#dataset-filter_filter') + .find('input') + .type('cypress'); + + cy.get('#dataset-filter') + .find('tbody>tr') + .should('not.contain', 'cypress'); + }); + + it('Can filter for an existing element on the English page', () => { + cy.get('#dataset-filter') + .find('tbody') + .get('td') + .eq(0) + .invoke('text') + .then((expected) => { + cy.get('#dataset-filter_filter') + .find('input') + .type(expected); + + cy.get('#dataset-filter') + .find('tbody>tr') + .should('contain', expected); + }); + }); +}); + +context('Open Source Software on the French page', () => { + before(() => { + cy.visit('http://localhost:4000/ore-ero/fr/logiciels-libres.html'); + }); + + it('Loads the French page', () => { + cy.get('#wb-cont').contains('Logiciels libres'); + }); + + it('Dynamically filters on the French page', () => { + cy.get('#dataset-filter_filter') + .find('input') + .type('jekyll'); + + cy.get('#dataset-filter') + .find('tbody>tr') + .first() + .find('td>a') + .first() + .contains('Jekyll'); + }); + + it('Dynamically filters on the English page', () => { + cy.get('#dataset-filter_filter') + .find('input') + .type('cypress'); + + cy.get('#dataset-filter') + .find('tbody>tr') + .should('not.contain', 'cypress'); + }); + + it('Can filter for an existing element on the French page', () => { + cy.get('#dataset-filter') + .find('tbody') + .get('td') + .eq(0) + .invoke('text') + .then((expected) => { + cy.get('#dataset-filter_filter') + .find('input') + .type(expected); + + cy.get('#dataset-filter') + .find('tbody>tr') + .should('contain', expected); + }); + }); +}); + +context('Open Source Software on the English Form page', () => { + before(() => { + cy.visit('http://localhost:4000/ore-ero/en/open-source-software-form.html'); + }); + + it('Loads the English Form page', () => { + cy.get('#wb-cont').contains('Open Source Software Form'); + }); + + it('Should return dynamicall filled of existing data information on the English page', () => { + cy.get('#nameselect').children().eq(1).invoke('text').then((name) => { + cy.get('#nameselect').select(name); + cy.get('#enname').should('have.value', name); + cy.get('#frname').should('not.have.value', ''); + cy.get('#endescriptionwhatItDoes').should('not.have.value', ''); + cy.get('#frdescriptionwhatItDoes').should('not.have.value', ''); + cy.get('#enhomepageURL').should('not.have.value', ''); + cy.get('#frhomepageURL').should('not.have.value', ''); + cy.get('#category').children().first().should('not.be.selected'); + cy.get('#entags').should('not.have.value', ''); + cy.get('#frtags').should('not.have.value', ''); + cy.get('#addMorelicences').find('ul > li').each(($li, id) => { + let i = id == 0 ? '' : id; + cy.get('#enlicencesURL' + i).should('not.have.value', ''); + cy.get('#frlicencesURL' + i).should('not.have.value', ''); + cy.get('#licencesspdxID' + i).children().first().should('not.be.selected'); + }); + }); + }); + + it('Should submit form on the English page', () => { + cy.get('select') + .as('option') + .invoke('val', 'net-core') + .first() + .trigger('change') + .contains('.NET Core'); + cy.get('select#adminCode') + .as('option') + .invoke('val', 'asc-csa') + .first() + .trigger('change') + .contains('Canadian Space Agency'); + cy.get('input#contactemail') + .type('jekyll@ymail.com') + .should('have.value','jekyll@ymail.com'); + cy.get('input#date') + .type("1959-09-13") + .should('have.value','1959-09-13'); + cy.get('input#submitterusername') + .type('test name') + .should('have.value','test name'); + cy.get('input#submitteremail') + .type('xyz@ymail.com') + .should('have.value','xyz@ymail.com'); + cy.window().then(win => { + win.submit_init.submitInit(); + }); + cy.get('#prbotSubmitAlertInProgress').should('be.visible'); + }); +}); + +context('Open Source Software on the French Form page', () => { + before(() => { + cy.visit('http://localhost:4000/ore-ero/fr/logiciel-libre-formulaire.html'); + }); + + it('Loads the French Form page', () => { + cy.get('#wb-cont').contains('Formulaire du logiciel libre'); + }); + + it('Should return dynamicall filled of existing data information on the French page', () => { + cy.get('#nameselect').children().eq(1).invoke('text').then((name) => { + cy.get('#nameselect').select(name); + cy.get('#enname').should('have.value', name); + cy.get('#frname').should('not.have.value', ''); + cy.get('#endescriptionwhatItDoes').should('not.have.value', ''); + cy.get('#frdescriptionwhatItDoes').should('not.have.value', ''); + cy.get('#enhomepageURL').should('not.have.value', ''); + cy.get('#frhomepageURL').should('not.have.value', ''); + cy.get('#category').children().first().should('not.be.selected'); + cy.get('#entags').should('not.have.value', ''); + cy.get('#frtags').should('not.have.value', ''); + cy.get('#addMorelicences').find('ul > li').each(($li, id) => { + let i = id == 0 ? '' : id; + cy.get('#enlicencesURL' + i).should('not.have.value', ''); + cy.get('#frlicencesURL' + i).should('not.have.value', ''); + cy.get('#licencesspdxID' + i).children().first().should('not.be.selected'); + }); + }); + }); + + it('Should submit form on the French page', () => { + cy.get('select') + .as('option') + .invoke('val', 'net-core') + .first() + .trigger('change') + .contains('.NET Core'); + cy.get('select#adminCode') + .as('option') + .invoke('val', 'asc-csa') + .first() + .trigger('change') + .contains('Agence spatiale canadienne'); + cy.get('input#contactemail') + .type('jekyll@ymail.com') + .should('have.value','jekyll@ymail.com'); + cy.get('input#date') + .type("1959-09-13") + .should('have.value','1959-09-13'); + cy.get('input#submitterusername') + .type('test name') + .should('have.value','test name'); + cy.get('input#submitteremail') + .type('xyz@ymail.com') + .should('have.value','xyz@ymail.com'); + cy.window().then(win => { + win.submit_init.submitInit(); + }); + cy.get('#prbotSubmitAlertInProgress').should('be.visible'); + }); +}); diff --git a/cypress/integration/unit-tests/software-en-date.spec.js b/cypress/integration/unit-tests/software-en-date.spec.js deleted file mode 100644 index e97613eef..000000000 --- a/cypress/integration/unit-tests/software-en-date.spec.js +++ /dev/null @@ -1,36 +0,0 @@ -/// -/* global cy, context, it, before, expect */ - -context('date_func.js', () => { - const now = new Date(); - const output = (now.getFullYear() + - '-' + - ((now.getMonth() + 1) < 10 ? '0' : '') + - (now.getMonth() + 1) + - '-' + - ((now.getDate()) < 10 ? '0' : '') + - (now.getDate()) - ); - - before(() => { - cy.visit('http://localhost:4000/ore-ero/en/open-source-software-form.html'); - }); - - it('Loads the script', () => { - cy.window().should('have.property', 'Date'); - }); - - it('It should call and return Date.now()', () => { - cy.window().then(win => { - let value = win.date_func.getToday(); - expect(value).to.equal(output); - }); - }); - - it('It should not equal to day time', () => { - cy.window().then(win => { - const outputDate = new Date(Date.now()); - expect(win.date_func.getToday()).not.equal(outputDate); - }); - }); -}); \ No newline at end of file diff --git a/cypress/integration/unit-tests/software.spec.js b/cypress/integration/unit-tests/software.spec.js deleted file mode 100644 index 76609f5db..000000000 --- a/cypress/integration/unit-tests/software.spec.js +++ /dev/null @@ -1,64 +0,0 @@ -/// -/* global cy, context, it */ - -context('Open Source Software', () => { - it('Loads the English page', () => { - cy.visit('http://localhost:4000/ore-ero/en/open-source-softwares.html'); - cy.get('#wb-cont').contains('Open Source Software'); - }); - - it('Dynamically filters on the English page', () => { - cy.visit('http://localhost:4000/ore-ero/en/open-source-softwares.html'); - cy.get('#dataset-filter_filter') - .find('input') - .type('jekyll'); - - cy.get('#dataset-filter') - .find('tbody>tr') - .first() - .find('td>a') - .first() - .contains('Jekyll'); - }); - - it('Dynamically filters on the English page', () => { - cy.visit('http://localhost:4000/ore-ero/en/open-source-softwares.html'); - cy.get('#dataset-filter_filter') - .find('input') - .type('cypress'); - - cy.get('#dataset-filter') - .find('tbody>tr') - .should('not.contain', 'cypress'); - }); - - it('Loads the French page', () => { - cy.visit('http://localhost:4000/ore-ero/fr/logiciels-libres.html'); - cy.get('#wb-cont').contains('Logiciels libres'); - }); - - it('Dynamically filters on the French page', () => { - cy.visit('http://localhost:4000/ore-ero/fr/logiciels-libres.html'); - cy.get('#dataset-filter_filter') - .find('input') - .type('jekyll'); - - cy.get('#dataset-filter') - .find('tbody>tr') - .first() - .find('td>a') - .first() - .contains('Jekyll'); - }); - - it('Dynamically filters on the English page', () => { - cy.visit('http://localhost:4000/ore-ero/fr/logiciels-libres.html'); - cy.get('#dataset-filter_filter') - .find('input') - .type('cypress'); - - cy.get('#dataset-filter') - .find('tbody>tr') - .should('not.contain', 'cypress'); - }); -}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bd52cd11b..a2055f2e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -597,7 +597,6 @@ "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", - "dev": true, "requires": { "nice-try": "^1.0.4", "path-key": "^2.0.1", @@ -2069,8 +2068,7 @@ "nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", - "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", - "dev": true + "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" }, "normalize-package-data": { "version": "2.5.0", @@ -2240,8 +2238,7 @@ "path-key": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", - "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", - "dev": true + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" }, "path-parse": { "version": "1.0.6", @@ -2493,14 +2490,12 @@ "semver": { "version": "5.7.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", - "dev": true + "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==" }, "shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", - "dev": true, "requires": { "shebang-regex": "^1.0.0" } @@ -2508,8 +2503,7 @@ "shebang-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", - "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", - "dev": true + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" }, "signal-exit": { "version": "3.0.2", @@ -2940,7 +2934,6 @@ "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "dev": true, "requires": { "isexe": "^2.0.0" }