github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/components/allocation-service-sidebar-test.js (about)

     1  import { module, test } from 'qunit';
     2  import { setupRenderingTest } from 'ember-qunit';
     3  import { click, render } from '@ember/test-helpers';
     4  import { hbs } from 'ember-cli-htmlbars';
     5  import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
     6  import Service from '@ember/service';
     7  import EmberObject from '@ember/object';
     8  
     9  module(
    10    'Integration | Component | allocation-service-sidebar',
    11    function (hooks) {
    12      setupRenderingTest(hooks);
    13      hooks.beforeEach(function () {
    14        const mockSystem = Service.extend({
    15          agent: EmberObject.create({
    16            config: {
    17              UI: {
    18                Consul: {
    19                  BaseUIURL: '',
    20                },
    21              },
    22            },
    23          }),
    24        });
    25        this.owner.register('service:system', mockSystem);
    26        this.system = this.owner.lookup('service:system');
    27      });
    28  
    29      test('it supports basic open/close states', async function (assert) {
    30        assert.expect(7);
    31        await componentA11yAudit(this.element, assert);
    32  
    33        this.set('closeSidebar', () => this.set('service', null));
    34  
    35        this.set('service', { name: 'Funky Service' });
    36        await render(
    37          hbs`<AllocationServiceSidebar @service={{this.service}} @fns={{hash closeSidebar=this.closeSidebar}} />`
    38        );
    39        assert.dom('h1').includesText('Funky Service');
    40        assert.dom('.sidebar').hasClass('open');
    41  
    42        this.set('service', null);
    43        await render(
    44          hbs`<AllocationServiceSidebar @service={{this.service}} @fns={{hash closeSidebar=this.closeSidebar}} />`
    45        );
    46        assert.dom(this.element).hasText('');
    47        assert.dom('.sidebar').doesNotHaveClass('open');
    48  
    49        this.set('service', { name: 'Funky Service' });
    50        await click('[data-test-close-service-sidebar]');
    51        assert.dom(this.element).hasText('');
    52        assert.dom('.sidebar').doesNotHaveClass('open');
    53      });
    54  
    55      test('it correctly aggregates service health', async function (assert) {
    56        const healthyService = {
    57          name: 'Funky Service',
    58          provider: 'nomad',
    59          healthChecks: [
    60            { Check: 'one', Status: 'success', Alloc: 'myAlloc' },
    61            { Check: 'two', Status: 'success', Alloc: 'myAlloc' },
    62          ],
    63        };
    64        const unhealthyService = {
    65          name: 'Funky Service',
    66          provider: 'nomad',
    67          healthChecks: [
    68            { Check: 'one', Status: 'failure', Alloc: 'myAlloc' },
    69            { Check: 'two', Status: 'success', Alloc: 'myAlloc' },
    70          ],
    71        };
    72  
    73        this.set('closeSidebar', () => this.set('service', null));
    74        this.set('allocation', { id: 'myAlloc' });
    75        this.set('service', healthyService);
    76        await render(
    77          hbs`<AllocationServiceSidebar @service={{this.service}} @allocation={{this.allocation}} @fns={{hash closeSidebar=this.closeSidebar}} />`
    78        );
    79        assert.dom('h1 .aggregate-status').includesText('Healthy');
    80        assert
    81          .dom('table.health-checks tbody tr:not(.service-status-indicators)')
    82          .exists({ count: 2 }, 'has two rows');
    83  
    84        this.set('service', unhealthyService);
    85        await render(
    86          hbs`<AllocationServiceSidebar @service={{this.service}} @allocation={{this.allocation}} @fns={{hash closeSidebar=this.closeSidebar}} />`
    87        );
    88        assert.dom('h1 .aggregate-status').includesText('Unhealthy');
    89      });
    90  
    91      test('it handles Consul services with reduced functionality', async function (assert) {
    92        const consulService = {
    93          name: 'Consul Service',
    94          provider: 'consul',
    95          healthChecks: [],
    96        };
    97  
    98        this.set('closeSidebar', () => this.set('service', null));
    99        this.set('service', consulService);
   100        await render(
   101          hbs`<AllocationServiceSidebar @service={{this.service}} @fns={{hash closeSidebar=this.closeSidebar}} />`
   102        );
   103        assert.dom('h1 .aggregate-status').doesNotExist();
   104        assert.dom('table.health-checks').doesNotExist();
   105        assert.dom('[data-test-consul-link-notice]').doesNotExist();
   106  
   107        this.system.agent.config.UI.Consul.BaseUIURL = 'http://localhost:8500';
   108  
   109        await render(
   110          hbs`<AllocationServiceSidebar @service={{this.service}} @fns={{hash closeSidebar=this.closeSidebar}} />`
   111        );
   112  
   113        assert.dom('[data-test-consul-link-notice]').exists();
   114      });
   115    }
   116  );