You are here

public function InspectorJsTest::testShowDebug in Acquia Lift Connector 8.4

Same name and namespace in other branches
  1. 8.3 modules/acquia_lift_inspector/tests/src/FunctionalJavascript/InspectorJsTest.php \Drupal\Tests\acquia_lift_inspector\FunctionalJavascript\InspectorJsTest::testShowDebug()

Tests JS interactions in the admin UI.

File

modules/acquia_lift_inspector/tests/src/FunctionalJavascript/InspectorJsTest.php, line 68

Class

InspectorJsTest
Tests for the JS that transforms widgets into form elements.

Namespace

Drupal\Tests\acquia_lift_inspector\FunctionalJavascript

Code

public function testShowDebug() {

  // Create the users used for the tests.
  $admin_user = $this
    ->drupalCreateUser([
    'administer acquia lift',
  ]);
  $this
    ->drupalLogin($admin_user);

  // Set valid settings.
  $this
    ->setValidSettings();

  // Set an actual JS lift.js file in the settings for the inspector to work.
  $settings = $this
    ->config('acquia_lift.settings');
  $settings
    ->set('credential', $this
    ->getActualJSCredentialSettings());
  $settings
    ->save();

  // Check if Acquia Lift Link is available on the node that we created.
  $node = $this
    ->createNode([
    'type' => 'article',
  ]);

  // Assert that the Acquia Lift link ID is present in the HTML.
  // This also verifies if the specific render cache is cleared.
  $this
    ->drupalGet($node
    ->toUrl()
    ->toString());

  // Confirm that AcquiaLift loaded.
  $javascript = <<<JS
  (function(){
    return Object.keys(window.AcquiaLift).length > 0;
  }());
JS;
  $this
    ->assertJsCondition($javascript);

  // Should not show the inspector.
  $page = $this
    ->getSession()
    ->getPage();
  $inspector = $page
    ->findById('lift-inspector');
  $this
    ->assertEmpty($inspector);

  // Open the inspector.
  $this
    ->getSession()
    ->wait(6000, "Drupal.acquiaLiftInspector.showModal();");
  $page = $this
    ->getSession()
    ->getPage();

  // Should show the inspector.
  $inspector = $page
    ->findById('lift-inspector');
  $this
    ->assertNotEmpty($inspector);
  $accountId = $inspector
    ->find('css', '#account-id a')
    ->getText();
  $this
    ->assertEquals($accountId, 'AccountId1');
  $accountLink = $inspector
    ->find('css', '#account-id a')
    ->getAttribute('href');
  $this
    ->assertEquals($accountLink, 'https://us-east-1.lift.acquia.com#person:accountId=AccountId1');
  $siteId = $inspector
    ->find('css', '#site-id')
    ->getText();
  $this
    ->assertEquals($siteId, 'SiteId1');
  $identity = $inspector
    ->find('css', '#identity')
    ->getText();
  $this
    ->assertEquals($identity, 'No tracking id available.');
  $identity = $inspector
    ->find('css', '#user-segments p')
    ->getText();
  $this
    ->assertEquals($identity, 'No segment(s) available.');
  $identity = $inspector
    ->find('css', '#decisions p')
    ->getText();
  $this
    ->assertEquals($identity, 'No decision(s) made.');
  $identity = $inspector
    ->find('css', '#captures p')
    ->getText();
  $this
    ->assertEquals($identity, 'No recent captures.');
}