class OliveroAvoidStorageUsingTest

Same name in this branch
  1. main core/tests/Drupal/FunctionalJavascriptTests/Theme/OliveroAvoidStorageUsingTest.php \Drupal\FunctionalJavascriptTests\Theme\OliveroAvoidStorageUsingTest
Same name and namespace in other branches
  1. 11.x core/tests/Drupal/FunctionalJavascriptTests/Theme/OliveroAvoidStorageUsingTest.php \Drupal\FunctionalJavascriptTests\Theme\OliveroAvoidStorageUsingTest
  2. 11.x core/themes/olivero/tests/src/FunctionalJavascript/OliveroAvoidStorageUsingTest.php \Drupal\Tests\olivero\FunctionalJavascript\OliveroAvoidStorageUsingTest

Tests usage of localStorage.

Attributes

#[Group('olivero')] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of OliveroAvoidStorageUsingTest

File

core/themes/olivero/tests/src/FunctionalJavascript/OliveroAvoidStorageUsingTest.php, line 14

Namespace

Drupal\Tests\olivero\FunctionalJavascript
View source
final class OliveroAvoidStorageUsingTest extends WebDriverTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'block',
    'node',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'olivero';
  
  /**
   * Tests use of localStorage.
   */
  public function testStorageUsing() : void {
    $this->drupalGet('<front>');
    // Check if initial no storage item is written.
    $this->assertJsCondition("localStorage.getItem('Drupal.olivero.stickyHeaderState') === null", 10000, 'Written not strictly necessary Drupal.olivero.stickyHeaderState to localStorage without consent.');
    // Resize and scroll to show stickyHeaderToggleButton.
    $session = $this->getSession();
    $session->resizeWindow(1280, 1024);
    $session->executeScript('window.scrollTo(0, 500);');
    // Click stickyHeaderToggleButton.
    $this->getSession()
      ->getPage()
      ->find('css', '.sticky-header-toggle')
      ->click();
    // Test if localStorage is set now.
    $this->assertJsCondition("localStorage.getItem('Drupal.olivero.stickyHeaderState') !== null");
    // Click stickyHeaderToggleButton again.
    $this->getSession()
      ->getPage()
      ->find('css', '.sticky-header-toggle')
      ->click();
    // Storage item should be removed now.
    $this->assertJsCondition("localStorage.getItem('Drupal.olivero.stickyHeaderState') === null", 10000, 'Storage item Drupal.olivero.stickyHeaderState should be removed.');
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.