You are here

protected function DataCollectorTableTest::doTableOperation in Charts 8.4

Same name and namespace in other branches
  1. 5.0.x tests/src/FunctionalJavascript/DataCollectorTableTest.php \Drupal\Tests\charts\FunctionalJavascript\DataCollectorTableTest::doTableOperation()

Do table operation.

Parameters

string $operation: The operation.

string $on: The element.

array $positions: The position.

1 call to DataCollectorTableTest::doTableOperation()
DataCollectorTableTest::testDataCollectorTable in tests/src/FunctionalJavascript/DataCollectorTableTest.php
Tests the data collector table.

File

tests/src/FunctionalJavascript/DataCollectorTableTest.php, line 117

Class

DataCollectorTableTest
Tests the data collector table element.

Namespace

Drupal\Tests\charts\FunctionalJavascript

Code

protected function doTableOperation($operation, $on, array $positions = []) {
  $value = ucfirst($operation) . ' ' . $on;
  if ($operation === 'add') {
    $selector = static::TABLE_SELECTOR . ' input[value="' . $value . '"]';
    $this
      ->pressAjaxButton($selector);
    if ($on === 'row') {
      $this
        ->assertRowsIncreased();
    }
    else {
      $this
        ->assertColumnsIncreased();
    }
  }
  else {
    $on_row = $on === 'row';
    if ($on_row) {
      $counter = DataCollectorTableTestForm::INITIAL_ROWS + 1;
      $locator = static::TABLE_ROW_SELECTOR;
    }
    else {
      $counter = DataCollectorTableTestForm::INITIAL_COLUMNS + 1;
      $locator = static::TABLE_COLUMN_SELECTOR;
    }
    foreach ($positions as $position) {
      if ($on_row) {
        $button_selector = static::TABLE_ROW_SELECTOR . ':nth-child(' . $position . ') .data-collector-table--row--delete input[value="Delete row"]';
      }
      else {
        $button_selector = static::TABLE_SELECTOR . ' .data-collector-table--column-deletes-row';
        $button_selector .= ' .data-collector-table--column--delete:nth-child(' . $position . ') input[value="Delete column"]';
      }
      $this
        ->pressAjaxButton($button_selector);
      $this
        ->assertDeletionOperation($counter, $locator);
    }
  }
}