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