diff --git a/cypress/integration/login_in_html_form_spec.js b/cypress/integration/login_in_html_form_spec.js deleted file mode 100644 index 68e1d05ab..000000000 --- a/cypress/integration/login_in_html_form_spec.js +++ /dev/null @@ -1,82 +0,0 @@ - context('HTML form submission', function(){ - beforeEach(function(){ - cy.visit('/login') - }) - - it('displays errors on login', function(){ - cy.get('input[name=log]').type('admin') - cy.get('input[name=pwd]').type('senhaerrada{enter}') - - // and still be on the same URL - cy.url().should('include', '/wp-login.php') - }) - - it('redirects to /dashboard on success', function(){ - cy.get('input[name=log]').type('admin') - cy.get('input[name=pwd]').type('admin{enter}') - - // we should be redirected to /wp-admin - cy.url().should('include', '/wp-admin') - cy.get('h1').should('contain', 'Dashboard') - }) - }) - - context('HTML form submission with cy.request', function(){ - it('can bypass the UI and yet still test log in', function(){ - // oftentimes once we have a proper e2e test around logging in - // there is NO more reason to actually use our UI to log in users - // doing so wastes is slow because our entire page has to load, - // all associated resources have to load, we have to fill in the - // form, wait for the form submission and redirection process - // - // with cy.request we can bypass this because it automatically gets - // and sets cookies under the hood. This acts exactly as if the requests - // came from the browser - cy.request({ - method: 'POST', - url: '/login', // baseUrl will be prepended to this url - form: true, // indicates the body should be form urlencoded and sets Content-Type: application/x-www-form-urlencoded headers - body: { - log: 'admin', - pwd: 'admin' - } - }) - - // just to prove we have a session - cy.getCookie('cypress-session-cookie').should('null') - }) - }) - - context('Reusable "login" custom command', function(){ - // typically we'd put this in cypress/support/commands.js - // but because this custom command is specific to this example - // we'll keep it here - Cypress.Commands.add('loginByForm', (username, password) => { - - Cypress.log({ - name: 'loginByForm', - message: username + ' | ' + password - }) - - return cy.request({ - method: 'POST', - url: '/login', - form: true, - body: { - log: username, - pwd: password - } - }) - - // we should be redirected to /wp-admin - cy.url().should('include', '/wp-admin') - cy.get('h1').should('contain', 'Dashboard') - }) - - it('test loginByForm', function() { - cy.url().should('include', '/wp-admin') - cy.get('h1').should('contain', 'Dashboard') - // login before each test - cy.loginByForm('admin', 'admin') - }) - }) diff --git a/cypress/integration/tainacan_collection_spec.js b/cypress/integration/tainacan_collection_spec.js new file mode 100644 index 000000000..c0fc14dec --- /dev/null +++ b/cypress/integration/tainacan_collection_spec.js @@ -0,0 +1,46 @@ +describe('Tainacan Plugin Test', function () { + + beforeEach(() => { + cy.loginByUI() + }) + + context('Collections', function(){ + 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.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.visit('/wp-admin/admin.php?page=tainacan_admin#/collections') + cy.get('td').should('contain', 'Ebook 1') + }) + }) +}) diff --git a/cypress/integration/tainacan_config_spec.js b/cypress/integration/tainacan_config_spec.js new file mode 100644 index 000000000..047596a7a --- /dev/null +++ b/cypress/integration/tainacan_config_spec.js @@ -0,0 +1,18 @@ +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/integration/tainacan_spec.js b/cypress/integration/tainacan_spec.js deleted file mode 100644 index 5679e061e..000000000 --- a/cypress/integration/tainacan_spec.js +++ /dev/null @@ -1,13 +0,0 @@ -describe('Plugin active Test', function () { - beforeEach(() => { - cy.loginByForm('admin', 'admin') - }) - - it('plugin active', function () { - cy.get('h1').should('contain', 'Dashboard') - cy.get('div').should('contain', 'Tainacan') - cy.contains('Tainacan').click() - cy.title().contains('Collections Page') - cy.get('h1').should('contain', 'Collections Page') - }) -}) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 8fde00ff6..83b80d238 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -23,24 +23,60 @@ // // -- This is will overwrite an existing command -- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) - Cypress.Commands.add('loginByForm', (username, password) => { Cypress.log({ - name: 'loginByForm', + name: 'loginByRequest', message: username + ' | ' + password }) + cy.request('/wp-admin') + cy.get('title').should('contain', 'Log In ‹ Test — WordPress') + + cy.request({ + method: 'POST', + url: '/wp-login.php', + form: true, + body: { + log: username, + pwd: password + } + }) + + cy.get('h1').should('contain', 'Dashboard') + + cy.getCookie('cypress-session-cookie').should('exist') +}) + +Cypress.Commands.add('loginByRequest', () => { + + Cypress.log({ + name: 'loginByRequest', + message: 'admin' + ' | ' + 'admin' + }) + cy.request({ method: 'POST', url: '/login', form: true, body: { - log: username, - pwd: password + log: 'admin', + pwd: 'admin' } }) + // we should be redirected to /wp-admin cy.url().should('include', '/wp-admin') cy.get('h1').should('contain', 'Dashboard') + + cy.getCookie('cypress-session-cookie').should('exist') }) + +Cypress.Commands.add('loginByUI', () => { + cy.visit('/wp-admin') + cy.get('input[name=log]').type('admin') + cy.get('input[name=pwd]').type('admin{enter}') + // we should be redirected to /wp-admin + cy.url().should('include', '/wp-admin') + cy.get('h1').should('contain', 'Dashboard') + }) diff --git a/src/admin/js/main.js b/src/admin/js/main.js index f641e86f4..3c23c1860 100644 --- a/src/admin/js/main.js +++ b/src/admin/js/main.js @@ -14,6 +14,7 @@ import Relationship from '../../classes/field-types/relationship/Relationship.vu import FormRelationship from '../../classes/field-types/relationship/FormRelationship.vue'; import FormCategory from '../../classes/field-types/category/FormCategory.vue'; +import FormSelectbox from '../../classes/field-types/selectbox/FormSelectbox.vue'; import TaincanFormItem from '../../classes/field-types/tainacan-form-item.vue'; @@ -43,8 +44,10 @@ Vue.component('tainacan-radio', Radio); Vue.component('tainacan-numeric', Numeric); Vue.component('tainacan-date', Date); Vue.component('tainacan-relationship', Relationship); + Vue.component('tainacan-form-relationship', FormRelationship); Vue.component('tainacan-form-category', FormCategory); +Vue.component('tainacan-form-selectbox', FormSelectbox); Vue.component('tainacan-form-item', TaincanFormItem); Vue.component('draggable', draggable); diff --git a/src/admin/tainacan-admin-i18n.php b/src/admin/tainacan-admin-i18n.php index e4543e387..ca9813db4 100644 --- a/src/admin/tainacan-admin-i18n.php +++ b/src/admin/tainacan-admin-i18n.php @@ -85,6 +85,12 @@ return [ 'label_collection_related' => __('Collection Related', 'tainacan'), 'label_fields_for_search' => __('Fields for search', 'tainacan'), 'label_allow_repeated_items' => __('Allow repeated items', 'tainacan'), + 'label_select_category' => __('Select category', 'tainacan'), + 'label_select_category_input_type' => __('Input type', 'tainacan'), + 'label_category_allow_new_terms' => __('Allow new terms', 'tainacan'), + 'label_selectbox_init' => __('Select', 'tainacan'), + 'label_options' => __('Insert options', 'tainacan'), + 'label_attachments' => __('Attachments', 'tainacan'), // Instructions. More complex sentences to guide user and placeholders 'instruction_dragndrop_fields_collection' => __('Drag and drop Fields here to add them to Collection.', 'tainacan'), diff --git a/src/classes/field-types/category/FormCategory.vue b/src/classes/field-types/category/FormCategory.vue index f7698e0ad..c804e5733 100644 --- a/src/classes/field-types/category/FormCategory.vue +++ b/src/classes/field-types/category/FormCategory.vue @@ -1,13 +1,19 @@ + + \ No newline at end of file diff --git a/src/classes/field-types/selectbox/class-tainacan-selectbox.php b/src/classes/field-types/selectbox/class-tainacan-selectbox.php index 297e9da21..9e05ebf1c 100644 --- a/src/classes/field-types/selectbox/class-tainacan-selectbox.php +++ b/src/classes/field-types/selectbox/class-tainacan-selectbox.php @@ -14,6 +14,7 @@ class Selectbox extends Field_Type { parent::__construct(); parent::set_primitive_type('string'); $this->component = 'tainacan-selectbox'; + $this->form_component = 'tainacan-form-selectbox'; } /** @@ -47,4 +48,21 @@ class Selectbox extends Field_Type { get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) ) + return true; + + if ( empty($this->get_option('options')) ) { + return [ + 'options' => __('Options is required','tainacan') + ]; + } + + return true; + } } \ No newline at end of file diff --git a/src/classes/tainacan-creator.php b/src/classes/tainacan-creator.php index 5baaee579..f7655c663 100644 --- a/src/classes/tainacan-creator.php +++ b/src/classes/tainacan-creator.php @@ -87,7 +87,6 @@ $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Date'); $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Numeric'); $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Selectbox'); $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Relationship'); -$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Radio'); $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Category'); global $Tainacan_Filters; diff --git a/src/js/axios/axios.js b/src/js/axios/axios.js index 07602a6b6..7568594c1 100644 --- a/src/js/axios/axios.js +++ b/src/js/axios/axios.js @@ -1,12 +1,12 @@ import axios from 'axios'; -const tainacan = axios.create({ +export const tainacan = axios.create({ baseURL: tainacan_plugin.root }); tainacan.defaults.headers.common['X-WP-Nonce'] = tainacan_plugin.nonce; -const wp = axios.create({ +export const wp = axios.create({ baseURL: tainacan_plugin.root_wp_api }); diff --git a/tests/test-fields.php b/tests/test-fields.php index ec185c0ca..bb7691122 100644 --- a/tests/test-fields.php +++ b/tests/test-fields.php @@ -194,7 +194,7 @@ class Fields extends TAINACAN_UnitTestCase { */ function test_metadata_field_type(){ global $Tainacan_Fields; - $this->assertEquals( 8, sizeof( $Tainacan_Fields->fetch_field_types() ) ); + $this->assertEquals( 7, sizeof( $Tainacan_Fields->fetch_field_types() ) ); } @@ -354,6 +354,7 @@ class Fields extends TAINACAN_UnitTestCase { $invalidField->set_name('test'); $invalidField->set_description('test'); $invalidField->set_collection($collection); + $invalidField->set_status('publish'); $invalidField->set_field_type('Tainacan\Field_Types\Relationship'); $invalidField->set_field_type_options(['collection_id' => 'string']);