github.com/hernad/nomad@v1.6.112/ui/tests/integration/components/scale-events-accordion-test.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { module, test } from 'qunit'; 7 import { setupRenderingTest } from 'ember-qunit'; 8 import { click, find, findAll, render } from '@ember/test-helpers'; 9 import hbs from 'htmlbars-inline-precompile'; 10 import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; 11 import setupCodeMirror from 'nomad-ui/tests/helpers/codemirror'; 12 import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer'; 13 import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; 14 15 module('Integration | Component | scale-events-accordion', function (hooks) { 16 setupRenderingTest(hooks); 17 setupCodeMirror(hooks); 18 19 hooks.beforeEach(function () { 20 fragmentSerializerInitializer(this.owner); 21 this.store = this.owner.lookup('service:store'); 22 this.server = startMirage(); 23 this.server.create('node-pool'); 24 this.server.create('node'); 25 this.taskGroupWithEvents = async function (events) { 26 const job = this.server.create('job', { createAllocations: false }); 27 const group = job.taskGroups.models[0]; 28 job.jobScale.taskGroupScales.models 29 .findBy('name', group.name) 30 .update({ events }); 31 32 const jobModel = await this.store.find( 33 'job', 34 JSON.stringify([job.id, 'default']) 35 ); 36 await jobModel.get('scaleState'); 37 return jobModel.taskGroups.findBy('name', group.name); 38 }; 39 }); 40 41 hooks.afterEach(function () { 42 this.server.shutdown(); 43 }); 44 45 const commonTemplate = hbs`<ScaleEventsAccordion @events={{this.events}} />`; 46 47 test('it shows an accordion with an entry for each event', async function (assert) { 48 assert.expect(2); 49 50 const eventCount = 5; 51 const taskGroup = await this.taskGroupWithEvents( 52 server.createList('scale-event', eventCount) 53 ); 54 this.set('events', taskGroup.scaleState.events); 55 56 await render(commonTemplate); 57 58 assert.equal( 59 findAll('[data-test-scale-events] [data-test-accordion-head]').length, 60 eventCount 61 ); 62 await componentA11yAudit(this.element, assert); 63 }); 64 65 test('when an event is an error, an error icon is shown', async function (assert) { 66 assert.expect(2); 67 68 const taskGroup = await this.taskGroupWithEvents( 69 server.createList('scale-event', 1, { error: true }) 70 ); 71 this.set('events', taskGroup.scaleState.events); 72 73 await render(commonTemplate); 74 75 assert.ok(find('[data-test-error]')); 76 await componentA11yAudit(this.element, assert); 77 }); 78 79 test('when an event has a count higher than previous count, a danger up arrow is shown', async function (assert) { 80 assert.expect(4); 81 82 const count = 5; 83 const taskGroup = await this.taskGroupWithEvents( 84 server.createList('scale-event', 1, { 85 count, 86 previousCount: count - 1, 87 error: false, 88 }) 89 ); 90 this.set('events', taskGroup.scaleState.events); 91 92 await render(commonTemplate); 93 94 assert.notOk(find('[data-test-error]')); 95 assert.equal(find('[data-test-count]').textContent, count); 96 assert.ok( 97 find('[data-test-count-icon]') 98 .querySelector('.icon') 99 .classList.contains('is-danger') 100 ); 101 await componentA11yAudit(this.element, assert); 102 }); 103 104 test('when an event has a count lower than previous count, a primary down arrow is shown', async function (assert) { 105 const count = 5; 106 const taskGroup = await this.taskGroupWithEvents( 107 server.createList('scale-event', 1, { 108 count, 109 previousCount: count + 1, 110 error: false, 111 }) 112 ); 113 this.set('events', taskGroup.scaleState.events); 114 115 await render(commonTemplate); 116 117 assert.notOk(find('[data-test-error]')); 118 assert.equal(find('[data-test-count]').textContent, count); 119 assert.ok( 120 find('[data-test-count-icon]') 121 .querySelector('.icon') 122 .classList.contains('is-primary') 123 ); 124 }); 125 126 test('when an event has no count, the count is omitted', async function (assert) { 127 const taskGroup = await this.taskGroupWithEvents( 128 server.createList('scale-event', 1, { count: null }) 129 ); 130 this.set('events', taskGroup.scaleState.events); 131 132 await render(commonTemplate); 133 134 assert.notOk(find('[data-test-count]')); 135 assert.notOk(find('[data-test-count-icon]')); 136 }); 137 138 test('when an event has no meta properties, the accordion entry is not expandable', async function (assert) { 139 assert.expect(2); 140 141 const taskGroup = await this.taskGroupWithEvents( 142 server.createList('scale-event', 1, { meta: {} }) 143 ); 144 this.set('events', taskGroup.scaleState.events); 145 146 await render(commonTemplate); 147 148 assert.ok( 149 find('[data-test-accordion-toggle]').classList.contains('is-invisible') 150 ); 151 await componentA11yAudit(this.element, assert); 152 }); 153 154 test('when an event has meta properties, the accordion entry is expanding, presenting the meta properties in a json viewer', async function (assert) { 155 assert.expect(4); 156 157 const meta = { 158 prop: 'one', 159 prop2: 'two', 160 deep: { 161 prop: 'here', 162 'dot.separate.prop': 12, 163 }, 164 }; 165 const taskGroup = await this.taskGroupWithEvents( 166 server.createList('scale-event', 1, { meta }) 167 ); 168 this.set('events', taskGroup.scaleState.events); 169 170 await render(commonTemplate); 171 assert.notOk(find('[data-test-accordion-body]')); 172 173 await click('[data-test-accordion-toggle]'); 174 assert.ok(find('[data-test-accordion-body]')); 175 176 assert.equal( 177 getCodeMirrorInstance('[data-test-json-viewer]').getValue(), 178 JSON.stringify(meta, null, 2) 179 ); 180 await componentA11yAudit(this.element, assert); 181 }); 182 });