diff --git a/bootstrap-config-sample.php b/bootstrap-config-sample.php new file mode 100644 index 000000000..cfb8a21bf --- /dev/null +++ b/bootstrap-config-sample.php @@ -0,0 +1,7 @@ + '/tmp/wordpress-tests-lib', +]; + + ?> \ No newline at end of file diff --git a/cypress.json b/cypress.json index 53e59b20c..4c18055d3 100644 --- a/cypress.json +++ b/cypress.json @@ -1,4 +1,6 @@ { "projectId": "tubzok", - "videoRecording": false + "videoRecording": false, + "viewportWidth": 1920, + "viewportHeight": 1080 } diff --git a/cypress/integration/config_tainacan_spec.js b/cypress/integration/config_tainacan_spec.js new file mode 100644 index 000000000..6939c6c54 --- /dev/null +++ b/cypress/integration/config_tainacan_spec.js @@ -0,0 +1,23 @@ +describe('Configuration Plugin Test', function () { + + beforeEach(() => { + cy.loginByUI() + }) + + context ('Configuration', function(){ + it('plugins active', function () { + cy.visit('wp-admin/plugins.php') + cy.get('.subsubsub > .active > a').click() + cy.get('.wp-list-table').should('contain', 'Tainacan').and('contain', 'WP Cypress DB Cleaner') + }) + + it('WPress configuration', function(){ + cy.contains('WPress').click() + cy.get('#default-api-namespace').clear() + cy.get('#default-api-namespace').type('tainacan/v2') + cy.get('#default-db-prefix').clear() + cy.get('#default-db-prefix').type('wptests_') + cy.get('#submit').click() + }) + }) +}) diff --git a/cypress/integration/tainacan_collection_fields_spec.js b/cypress/integration/tainacan_collection_fields_spec.js new file mode 100644 index 000000000..0cce3743f --- /dev/null +++ b/cypress/integration/tainacan_collection_fields_spec.js @@ -0,0 +1,123 @@ +describe('Tainacan Plugin Test', function () { + beforeEach(() => { + cy.loginByUI() + }) + + context('text-type fields', function(){ + it('clear DB', function(){ + cy.clearDB() + }) + + it('create collection for fields', function(){ + cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') + cy.get('h1').should('contain', 'Collections Page') + cy.contains('New Collection').click() + cy.get('#tainacan-text-name').type('Book Fields') + cy.get('#tainacan-text-description').type('Descrição book Fields') + cy.get('#tainacan-select-status').select('Publish').should('have.value', 'publish') + cy.get('#button-submit-collection-creation').click() + cy.get('#primary-menu > .menu > .menu-header > .menu-list > li > .router-link-active > .icon > .mdi').click() + cy.get('.b-table').should('contain', 'Book Fields') + }) + + it('canceled create text field public', function(){ + cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') + cy.get('h1').should('contain', 'Collections Page') + cy.get('[data-label="Name"] > :nth-child(1) > .clickable-row').click() + cy.get(':nth-child(4) > .router-link-active').should('contain', 'Items') + cy.get('.menu > :nth-child(2) > :nth-child(5) > a').click() + cy.get('h1').should('contain', 'Collection Fields Edition Page') + cy.get('.field > :nth-child(2) > :nth-child(1)').click() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').clear() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').type('Book name canceled') + cy.get('.textarea').type('name book canceled description') + cy.get('#tainacan-select-status-publish > .check').click() + cy.get(':nth-child(1) > .button').click() + cy.get('.active-fields-area >').should('not.contain', 'Book name canceled') + cy.get('.active-fields-area >').should('not.contain', 'Text') + }) + + it('create text field public', function(){ + cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') + cy.get('h1').should('contain', 'Collections Page') + cy.get('[data-label="Name"] > :nth-child(1) > .clickable-row').click() + cy.get(':nth-child(4) > .router-link-active').should('contain', 'Items') + cy.get('.menu > :nth-child(2) > :nth-child(5) > a').click() + cy.get('h1').should('contain', 'Collection Fields Edition Page') + cy.get('.field > :nth-child(2) > :nth-child(1)').click() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').clear() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').type('Book name public') + cy.get('.textarea').type('name book description') + cy.get('#tainacan-select-status-publish > .check').click() + cy.get(':nth-child(2) > .button').click() + cy.get('.active-fields-area >').should('contain', 'Book name public') + }) + + it('create text field private', function(){ + cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') + cy.get('h1').should('contain', 'Collections Page') + cy.get('[data-label="Name"] > :nth-child(1) > .clickable-row').click() + cy.get(':nth-child(4) > .router-link-active').should('contain', 'Items') + cy.get('.menu > :nth-child(2) > :nth-child(5) > a').click() + cy.get('h1').should('contain', 'Collection Fields Edition Page') + cy.get('.field > :nth-child(2) > :nth-child(1)').click() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').clear() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').type('Book name private') + cy.get('.textarea').type('name book description') + cy.get('#tainacan-select-status-private > .check').click() + cy.get(':nth-child(2) > .button').click() + cy.get('.active-fields-area >').should('contain', 'Book name private') + }) + + it('create text field public required', function(){ + cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') + cy.get('h1').should('contain', 'Collections Page') + cy.get('[data-label="Name"] > :nth-child(1) > .clickable-row').click() + cy.get(':nth-child(4) > .router-link-active').should('contain', 'Items') + cy.get('.menu > :nth-child(2) > :nth-child(5) > a').click() + cy.get('h1').should('contain', 'Collection Fields Edition Page') + cy.get('.field > :nth-child(2) > :nth-child(1)').click() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').clear() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').type('Book name public required') + cy.get('.textarea').type('name book description required') + cy.get('#tainacan-select-status-publish > .check').click() + cy.get(':nth-child(2) > .b-checkbox > .check').click() + cy.get(':nth-child(2) > .button').click() + cy.get('.active-fields-area >').should('contain', 'Book name public required') + }) + + it('create text field public multiple values', function(){ + cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') + cy.get('h1').should('contain', 'Collections Page') + cy.get('[data-label="Name"] > :nth-child(1) > .clickable-row').click() + cy.get(':nth-child(4) > .router-link-active').should('contain', 'Items') + cy.get('.menu > :nth-child(2) > :nth-child(5) > a').click() + cy.get('h1').should('contain', 'Collection Fields Edition Page') + cy.get('.field > :nth-child(2) > :nth-child(1)').click() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').clear() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').type('Book name public multiple values') + cy.get('.textarea').type('name book description multiple values') + cy.get('#tainacan-select-status-publish > .check').click() + cy.get(':nth-child(3) > .b-checkbox > .check').click() + cy.get(':nth-child(2) > .button').click() + cy.get('.active-fields-area >').should('contain', 'Book name public multiple values') + }) + + it('create text field public unique values', function(){ + cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') + cy.get('h1').should('contain', 'Collections Page') + cy.get('[data-label="Name"] > :nth-child(1) > .clickable-row').click() + cy.get(':nth-child(4) > .router-link-active').should('contain', 'Items') + cy.get('.menu > :nth-child(2) > :nth-child(5) > a').click() + cy.get('h1').should('contain', 'Collection Fields Edition Page') + cy.get('.field > :nth-child(2) > :nth-child(1)').click() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').clear() + cy.get('#fieldEditForm > :nth-child(1) > .control > .input').type('Book name public unique values') + cy.get('.textarea').type('name book description multiple values') + cy.get('#tainacan-select-status-publish > .check').click() + cy.get(':nth-child(4) > .b-checkbox > .check').click() + cy.get(':nth-child(2) > .button').click() + cy.get('.active-fields-area >').should('contain', 'Book name public unique values') + }) + }) +}) diff --git a/cypress/integration/tainacan_collection_spec.js b/cypress/integration/tainacan_collection_spec.js index c0fc14dec..1450aa904 100644 --- a/cypress/integration/tainacan_collection_spec.js +++ b/cypress/integration/tainacan_collection_spec.js @@ -1,46 +1,114 @@ describe('Tainacan Plugin Test', function () { - beforeEach(() => { cy.loginByUI() }) context('Collections', function(){ + it('clear DB', function(){ + cy.clearDB() + }) + it('canceled collection', function(){ cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') cy.get('h1').should('contain', 'Collections Page') cy.contains('New Collection').click() - cy.get('[id=tainacan-text-name]').type('Book cancelado') - cy.get('[id=button-cancel-collection-creation]').click() + cy.get('#tainacan-text-name').type('Book cancelado') + cy.get('#tainacan-text-description').type('Descrição book cancelado') + cy.get('#button-cancel-collection-creation').click() cy.url().should('contain', '/wp-admin/admin.php?page=tainacan_admin#/collections/') cy.get('h1').should('contain', 'Collections Page') cy.get('td').should('not.contain', 'Book cancelado') }) - it('status field blank collection', function(){ - cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') - cy.get('h1').should('contain', 'Collections Page') - cy.contains('New Collection').click() - cy.get('[id=tainacan-text-name]').type('Ebook status em branco') - cy.get('[id=tainacan-text-description]').type('Importante a organização dos livros para estimular a leitura pelos usuários da biblioteca') - cy.get('[id=button-submit-collection-creation]').click() - cy.get('td').should('contain', 'New Item') - cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') - cy.get('h1').should('contain', 'Collections Page') - cy.get('td').should('not.contain', 'Book cancelado') - - }) - it('create collection', function(){ cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') cy.get('h1').should('contain', 'Collections Page') cy.contains('New Collection').click() - cy.get('[id=tainacan-text-name]').type('Ebook 1') - cy.get('[id=tainacan-text-description]').type('Importante a organização dos livros para estimular a leitura pelos usuários da biblioteca') - cy.get('[id=tainacan-select-status]').select('Publish').should('have.value', 'publish') - cy.get('[id=button-submit-collection-creation]').click() - cy.get('td').should('contain', 'New Item') + cy.get('#tainacan-text-name').type('Book 1') + cy.get('#tainacan-text-description').type('Descrição book 1') + cy.get('#tainacan-select-status').select('Publish').should('have.value', 'publish') + cy.get('#button-submit-collection-creation').click() + cy.get('#primary-menu > .menu > .menu-header > .menu-list > li > .router-link-active > .icon > .mdi').click() + cy.get('.b-table').should('contain', 'Book 1') + }) + + it('delete collection', function(){ cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') - cy.get('td').should('contain', 'Ebook 1') + cy.get('h1').should('contain', 'Collections Page') + cy.contains('New Collection').click() + cy.get('#tainacan-text-name').type('Book deletado') + cy.get('#tainacan-text-description').type('Descrição book deletado') + cy.get('#tainacan-select-status').select('Publish').should('have.value', 'publish') + cy.get('#button-submit-collection-creation').click() + cy.get('#primary-menu > .menu > .menu-header > .menu-list > li > .router-link-active > .icon > .mdi').click() + cy.get('.b-table').should('contain', 'Book deletado') + cy.get(':nth-child(1) > [data-label="Actions"] > :nth-child(1) > #button-delete > .icon > .mdi').click() + cy.get('.modal-card-body').should('contain', 'Do you really want to delete this collection?') + cy.get('.is-primary').click() + cy.get('.b-table').should('not.contain', 'Book deletado') + }) + }) + + context('Items', function(){ + it('canceled create item', function(){ + cy.clearDB() + cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') + cy.get('h1').should('contain', 'Collections Page') + cy.contains('New Collection').click() + cy.get('#tainacan-text-name').type('Book com items') + cy.get('#tainacan-text-description').type('Descrição book com items') + cy.get('#tainacan-select-status').select('Publish').should('have.value', 'publish') + cy.get('#button-submit-collection-creation').click() + cy.get('.b-table').should('contain', 'New Item') + cy.contains('New Item').click() + cy.get('#tainacan-text-title').type('Item cancelado') + cy.get('#tainacan-textarea-description').type('Item cancelado descrição') + cy.get('#status-select').select('Publish').should('have.value', 'publish') + cy.get('#button-cancel-item-creation').click() + cy.get('.b-table').should('not.contain', 'Item cancelado') + }) + + it('create item', function(){ + cy.clearDB() + cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') + cy.get('h1').should('contain', 'Collections Page') + cy.contains('New Collection').click() + cy.get('#tainacan-text-name').type('Book com items') + cy.get('#tainacan-text-description').type('Descrição book com items') + cy.get('#tainacan-select-status').select('Publish').should('have.value', 'publish') + cy.get('#button-submit-collection-creation').click() + cy.get('.b-table').should('contain', 'New Item') + cy.contains('New Item').click() + cy.get('#tainacan-text-title').type('Item 1') + cy.get('#tainacan-textarea-description').type('Item 1 descrição') + cy.get('#status-select').select('Publish').should('have.value', 'publish') + cy.get('#button-submit-item-creation').click() + cy.get('h1').should('contain', 'Item Page') + cy.get('.page-container').should('contain', 'Item 1') + }) + + it('delete item', function(){ + cy.clearDB() + cy.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') + cy.get('h1').should('contain', 'Collections Page') + cy.contains('New Collection').click() + cy.get('#tainacan-text-name').type('Book 2') + cy.get('#tainacan-text-description').type('Descrição book 2') + cy.get('#tainacan-select-status').select('Publish').should('have.value', 'publish') + cy.get('#button-submit-collection-creation').click() + cy.get('.b-table').should('contain', 'New Item') + cy.contains('New Item').click() + cy.get('#tainacan-text-title').type('Item 1') + cy.get('#tainacan-textarea-description').type('Item 1 descrição') + cy.get('#status-select').select('Publish').should('have.value', 'publish') + cy.get('#button-submit-item-creation').click() + cy.get('h1').should('contain', 'Item Page') + cy.get('#secondary-menu > .menu > :nth-child(2) > :nth-child(3) > .router-link-active').click() + cy.get('.b-table').should('contain', 'Item 1') + cy.get(':nth-child(1) > [data-label="Actions"] > :nth-child(1) > #button-delete > .icon > .mdi').click() + cy.get('.modal-card-body').should('contain', 'Do you really want to delete this item?') + cy.get('.is-primary').click() + cy.get('.b-table').should('not.contain', 'Item 1') }) }) }) diff --git a/cypress/integration/tainacan_config_spec.js b/cypress/integration/tainacan_config_spec.js deleted file mode 100644 index 047596a7a..000000000 --- a/cypress/integration/tainacan_config_spec.js +++ /dev/null @@ -1,18 +0,0 @@ -describe('Configuration Plugin Test', function () { - - beforeEach(() => { - cy.loginByUI() - }) - - context ('Configuration', function(){ - it('plugins page', function(){ - cy.visit('wp-admin/plugins.php') - cy.get('h1').should('contain', 'Plugins') - }) - - it('plugin active', function () { - cy.contains('Tainacan').click() - cy.get('h1').should('contain', 'Collections Page') - }) - }) -}) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 83b80d238..7f3a1b565 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -80,3 +80,7 @@ Cypress.Commands.add('loginByUI', () => { cy.url().should('include', '/wp-admin') cy.get('h1').should('contain', 'Dashboard') }) + +Cypress.Commands.add('clearDB', () => { + cy.request('POST', '/wp-json/tainacan/v2/database') +}) diff --git a/run-cypress.sh b/run-cypress.sh index 7d2fe9f0b..8a4a754d1 100755 --- a/run-cypress.sh +++ b/run-cypress.sh @@ -11,7 +11,9 @@ source build-config.cfg ./build.sh -plugin_name=`basename $wp_plugin_dir` +plugin_tainacan=`basename $wp_plugin_dir` +plugin_wpclear='wpress-db-cleaner' + test_db_prefix='wptests_' cy_record_key='a15e6599-d240-4d98-b582-dea93a3008c0' @@ -26,7 +28,7 @@ echo "Installing WordPress..." wp core install --url=$wp_url --title=Test --admin_user=admin --admin_password=admin --admin_email=admin@admin.com # Activate Tainacan -wp plugin activate $plugin_name +wp plugin activate $plugin_tainacan $plugin_wpclear # back to tainacan dev directory cd -