Skip to content
Snippets Groups Projects
Commit 1ed6b544 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Merge branch '3517863-add-e2e-tests' into '0.x'

Issue #3517863: e2e test for path widget

See merge request !867
parents 52bb8276 db1bd70b
No related branches found
No related tags found
No related merge requests found
Pipeline #484808 failed
......@@ -234,15 +234,10 @@ function xb_test_article_fields_install(): void {
'settings' => [],
],
],
'field_xbt_path' => [
'type' => 'path',
'label' => 'XB Path',
'settings' => [],
'widget' => [
'type' => 'path',
'settings' => [],
],
],
// Note we don't have a path widget here because one of those is added
// by default as the 'URL alias' field and because PathItem is a computed
// field it only makes sense to have one path item field on an entity.
// @see \Drupal\path\Hook\PathHooks::entityBaseFieldInfo()
'field_xbt_telephone' => [
'type' => 'telephone',
'label' => 'XB Telephone',
......
......@@ -378,6 +378,7 @@ class XBTestSetup implements TestSetupInterface {
$empty_node = Node::create([
'type' => 'article',
'title' => 'I am an empty node',
'path' => ['alias' => '/i-am-an-empty-node'],
'field_hero' => $image_field_sample_value,
]);
$empty_node->save();
......
......@@ -85,4 +85,63 @@ describe('Entity form field types', () => {
});
});
});
it('Can interact with entity path field', () => {
cy.drupalLogin('xbUser', 'xbUser');
cy.loadURLandWaitForXBLoaded({ url: 'xb/node/2' });
cy.findByTestId('xb-contextual-panel--page-data').should(
'have.attr',
'data-state',
'active',
);
cy.findByTestId('xb-page-data-form').as('entityForm');
// Log all ajax form requests to help with debugging.
cy.intercept('POST', '**/xb/api/form/content-entity/**');
// Make a record of the starting form build ID for the form
cy.get('@entityForm').recordFormBuildId();
cy.intercept({
url: '**/xb/api/layout/node/2',
times: 1,
method: 'POST',
}).as('updatePreview');
const path = '/not-empty-anymore';
cy.findByLabelText('URL alias').as('path');
cy.get('@path').should('have.value', '/i-am-an-empty-node');
cy.get('@path').clear();
cy.get('@path').type(path);
cy.get('@path').should('have.value', path);
// Wait for the preview to finish loading.
cy.wait('@updatePreview');
cy.findByLabelText('Loading Preview').should('not.exist');
cy.findByLabelText('Change to').as('moderation-state');
cy.get('@moderation-state')
.parents('.js-form-wrapper')
.as('moderation-state-wrapper');
cy.get('@moderation-state-wrapper')
.findByRole('combobox', { name: 'Change to', exact: false })
.click();
cy.findByRole('option', { name: 'Published', exact: false }).click();
cy.get('@moderation-state')
.parent()
.find('select')
.should('have.value', 'published');
// Wait for the preview to finish loading.
cy.findByLabelText('Loading Preview').should('not.exist');
// Save changes.
cy.publishAllPendingChanges('I am an empty node');
// Request all articles over JSON:API.
cy.request('/jsonapi/node/article').then((listResponse) => {
expect(listResponse.status).to.eq(200);
const data = listResponse.body.data;
// Filter down to just node 2 which we've been editing.
const nodeData = data
.filter((item) => item.attributes.drupal_internal__nid === 2)
.shift();
expect(nodeData.attributes.path.alias).to.equal(path);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment