github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/pages/components/recommendation-card.js (about)

     1  import { attribute, collection, hasClass, isPresent, text } from 'ember-cli-page-object';
     2  import { getter } from 'ember-cli-page-object/macros';
     3  
     4  import toggle from 'nomad-ui/tests/pages/components/toggle';
     5  
     6  export default {
     7    scope: '[data-test-task-group-recommendations]',
     8  
     9    slug: {
    10      jobName: text('[data-test-job-name]'),
    11      groupName: text('[data-test-task-group-name]'),
    12    },
    13  
    14    namespace: text('[data-test-namespace]'),
    15  
    16    copyButton: {
    17      scope: '[data-test-copy-button]',
    18      clipboardText: attribute('data-clipboard-text', 'button'),
    19    },
    20  
    21    totalsTable: totalsTableComponent('[data-test-group-totals]'),
    22  
    23    narrative: text('[data-test-narrative]'),
    24  
    25    togglesTable: {
    26      scope: '[data-test-toggles-table]',
    27  
    28      toggleAllIsPresent: isPresent('[data-test-toggle-all]'),
    29      toggleAllCPU: toggle('[data-test-tasks-head] [data-test-cpu-toggle]'),
    30      toggleAllMemory: toggle('[data-test-tasks-head] [data-test-memory-toggle]'),
    31  
    32      tasks: collection('[data-test-task-toggles]', {
    33        name: text('[data-test-name]'),
    34        cpu: toggle('[data-test-cpu-toggle]'),
    35        memory: toggle('[data-test-memory-toggle]'),
    36  
    37        isActive: hasClass('active'),
    38      }),
    39    },
    40  
    41    activeTask: {
    42      scope: '[data-test-active-task]',
    43  
    44      name: text('[data-test-task-name]'),
    45      totalsTable: totalsTableComponent(''),
    46  
    47      charts: collection('[data-test-chart-for]', {
    48        resource: text('text.resource'),
    49      }),
    50  
    51      cpuChart: resourceChartComponent('[data-test-chart-for=CPU]'),
    52      memoryChart: resourceChartComponent('[data-test-chart-for=MemoryMB]'),
    53    },
    54  
    55    acceptButton: {
    56      scope: '[data-test-accept]',
    57      isDisabled: attribute('disabled'),
    58    },
    59  
    60    dismissButton: {
    61      scope: '[data-test-dismiss]',
    62    },
    63  };
    64  
    65  function totalsTableCell(scope) {
    66    return {
    67      scope,
    68      isIncrease: hasClass('increase'),
    69      isDecrease: hasClass('decrease'),
    70      isNeutral: getter(function() {
    71        return !this.isIncrease && !this.isDecrease;
    72      }),
    73    };
    74  }
    75  
    76  function totalsTableComponent(scope) {
    77    return {
    78      scope,
    79  
    80      current: {
    81        scope: '[data-test-current]',
    82        cpu: totalsTableCell('[data-test-cpu]'),
    83        memory: totalsTableCell('[data-test-memory]'),
    84      },
    85  
    86      recommended: {
    87        scope: '[data-test-recommended]',
    88        cpu: totalsTableCell('[data-test-cpu]'),
    89        memory: totalsTableCell('[data-test-memory]'),
    90      },
    91  
    92      unitDiff: {
    93        cpu: text('[data-test-cpu-unit-diff]'),
    94        memory: text('[data-test-memory-unit-diff]'),
    95      },
    96  
    97      percentDiff: {
    98        cpu: text('[data-test-cpu-percent-diff]'),
    99        memory: text('[data-test-memory-percent-diff]'),
   100      },
   101    };
   102  }
   103  
   104  function resourceChartComponent(scope) {
   105    return {
   106      scope,
   107  
   108      isIncrease: hasClass('increase'),
   109      isDecrease: hasClass('decrease'),
   110      isDisabled: hasClass('disabled'),
   111    };
   112  }