You are here

public function BlazyJavaScriptTest::testFormatterDisplay in Blazy 8

Test the Blazy element from loading to loaded states.

File

tests/src/FunctionalJavascript/BlazyJavaScriptTest.php, line 54

Class

BlazyJavaScriptTest
Tests the Blazy JavaScript using PhantomJS, or Chromedriver.

Namespace

Drupal\Tests\blazy\FunctionalJavascript

Code

public function testFormatterDisplay() {
  $data['settings']['blazy'] = TRUE;
  $data['settings']['ratio'] = '';
  $data['settings']['image_style'] = 'thumbnail';
  $this
    ->setUpContentTypeTest($this->bundle);
  $this
    ->setUpFormatterDisplay($this->bundle, $data);
  $this
    ->setUpContentWithItems($this->bundle);
  $image_path = $this
    ->getImagePath(TRUE);
  $this
    ->drupalGet('node/' . $this->entity
    ->id());

  // Capture the initial page load moment.
  $this
    ->createScreenshot($image_path . '/' . $this->scriptLoader . '_1_initial.png');
  $this
    ->assertSession()
    ->elementExists('css', '.b-lazy');

  // Trigger Blazy to load images by scrolling down window.
  $this
    ->getSession()
    ->executeScript('window.scrollTo(0, document.body.scrollHeight);');

  // Capture the loading moment after scrolling down the window.
  $this
    ->createScreenshot($image_path . '/' . $this->scriptLoader . '_2_loading.png');

  // Wait a moment.
  $this
    ->getSession()
    ->wait(3000);

  // Verifies that one of the images is there once loaded.
  $this
    ->assertNotEmpty($this
    ->assertSession()
    ->waitForElement('css', '.b-loaded'));

  // Capture the loaded moment.
  // The screenshots are at sites/default/files/simpletest/blazy.
  $this
    ->createScreenshot($image_path . '/' . $this->scriptLoader . '_3_loaded.png');
}