github.com/hernad/nomad@v1.6.112/ui/tests/integration/components/job-status/failed-or-lost-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 { render } from '@ember/test-helpers';
     9  import { hbs } from 'ember-cli-htmlbars';
    10  import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
    11  
    12  module('Integration | Component | job-status/failed-or-lost', function (hooks) {
    13    setupRenderingTest(hooks);
    14  
    15    test('it renders', async function (assert) {
    16      assert.expect(3);
    17  
    18      let job = {
    19        id: 'job1',
    20      };
    21  
    22      let allocs = [
    23        {
    24          id: 1,
    25          name: 'alloc1',
    26        },
    27        {
    28          id: 2,
    29          name: 'alloc2',
    30        },
    31      ];
    32  
    33      this.set('allocs', allocs);
    34      this.set('job', job);
    35  
    36      await render(hbs`<JobStatus::FailedOrLost
    37        @job={{this.job}}
    38        @restartedAllocs={{this.allocs}}
    39      />`);
    40  
    41      assert.dom('h4').hasText('Replaced Allocations');
    42      assert.dom('.failed-or-lost-links').hasText('2 Restarted');
    43      await componentA11yAudit(this.element, assert);
    44    });
    45  
    46    test('it links or does not link appropriately', async function (assert) {
    47      let job = {
    48        id: 'job1',
    49      };
    50  
    51      let allocs = [
    52        {
    53          id: 1,
    54          name: 'alloc1',
    55        },
    56        {
    57          id: 2,
    58          name: 'alloc2',
    59        },
    60      ];
    61  
    62      this.set('allocs', allocs);
    63      this.set('job', job);
    64  
    65      await render(hbs`<JobStatus::FailedOrLost
    66        @restartedAllocs={{this.allocs}}
    67        @job={{this.job}}
    68      />`);
    69  
    70      // Ensure it's of type a
    71      assert.dom('.failed-or-lost-links > span > *:last-child').hasTagName('a');
    72      this.set('allocs', []);
    73      assert
    74        .dom('.failed-or-lost-links > span > *:last-child')
    75        .doesNotHaveTagName('a');
    76    });
    77  
    78    test('it shows rescheduling as well', async function (assert) {
    79      let job = {
    80        id: 'job1',
    81      };
    82  
    83      let restartedAllocs = [
    84        {
    85          id: 1,
    86          name: 'alloc1',
    87        },
    88        {
    89          id: 2,
    90          name: 'alloc2',
    91        },
    92      ];
    93  
    94      let rescheduledAllocs = [
    95        {
    96          id: 1,
    97          name: 'alloc1',
    98        },
    99        {
   100          id: 2,
   101          name: 'alloc2',
   102        },
   103        {
   104          id: 3,
   105          name: 'alloc3',
   106        },
   107      ];
   108  
   109      this.set('restartedAllocs', restartedAllocs);
   110      this.set('rescheduledAllocs', rescheduledAllocs);
   111      this.set('job', job);
   112      this.set('supportsRescheduling', true);
   113  
   114      await render(hbs`<JobStatus::FailedOrLost
   115        @restartedAllocs={{this.restartedAllocs}}
   116        @rescheduledAllocs={{this.rescheduledAllocs}}
   117        @job={{this.job}}
   118        @supportsRescheduling={{this.supportsRescheduling}}
   119      />`);
   120  
   121      assert.dom('.failed-or-lost-links').containsText('2 Restarted');
   122      assert.dom('.failed-or-lost-links').containsText('3 Rescheduled');
   123      this.set('supportsRescheduling', false);
   124      assert.dom('.failed-or-lost-links').doesNotContainText('Rescheduled');
   125    });
   126  });