github.com/hernad/nomad@v1.6.112/ui/tests/integration/components/app-breadcrumbs-test.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  /* eslint-disable ember-a11y-testing/a11y-audit-called */
     7  import { setComponentTemplate } from '@ember/component';
     8  import templateOnlyComponent from '@ember/component/template-only';
     9  import { module, test } from 'qunit';
    10  import { setupRenderingTest } from 'ember-qunit';
    11  import { findAll, render } from '@ember/test-helpers';
    12  import hbs from 'htmlbars-inline-precompile';
    13  
    14  module('Integration | Component | app breadcrumbs', function (hooks) {
    15    setupRenderingTest(hooks);
    16  
    17    const commonCrumbs = [
    18      { label: 'Jobs', args: ['jobs.index'] },
    19      { label: 'Job', args: ['jobs.job.index'] },
    20    ];
    21  
    22    test('every breadcrumb is rendered correctly', async function (assert) {
    23      assert.expect(3);
    24      this.set('commonCrumbs', commonCrumbs);
    25      await render(hbs`
    26        <AppBreadcrumbs />
    27        {{#each this.commonCrumbs as |crumb|}}
    28          <Breadcrumb @crumb={{hash label=crumb.label args=crumb.args }} />
    29        {{/each}}
    30      `);
    31  
    32      assert
    33        .dom('[data-test-breadcrumb-default]')
    34        .exists(
    35          'We register the default breadcrumb component if no type is specified on the crumb'
    36        );
    37  
    38      const renderedCrumbs = findAll('[data-test-breadcrumb]');
    39  
    40      renderedCrumbs.forEach((crumb, index) => {
    41        assert.equal(
    42          crumb.textContent.trim(),
    43          commonCrumbs[index].label,
    44          `Crumb ${index} is ${commonCrumbs[index].label}`
    45        );
    46      });
    47    });
    48  
    49    test('when we register a crumb with a type property, a dedicated breadcrumb/<type> component renders', async function (assert) {
    50      const crumbs = [
    51        { label: 'Jobs', args: ['jobs.index'] },
    52        { type: 'special', label: 'Job', args: ['jobs.job.index'] },
    53      ];
    54      this.set('crumbs', crumbs);
    55  
    56      this.owner.register(
    57        'component:breadcrumbs/special',
    58        setComponentTemplate(
    59          hbs`
    60          <div data-test-breadcrumb-special>Test</div>
    61        `,
    62          templateOnlyComponent()
    63        )
    64      );
    65  
    66      await render(hbs`
    67      <AppBreadcrumbs />
    68      {{#each this.crumbs as |crumb|}}
    69        <Breadcrumb @crumb={{hash type=crumb.type label=crumb.label args=crumb.args }} />
    70      {{/each}}
    71    `);
    72  
    73      assert
    74        .dom('[data-test-breadcrumb-special]')
    75        .exists(
    76          'We can create a new type of breadcrumb component and AppBreadcrumbs will handle rendering by type'
    77        );
    78  
    79      assert
    80        .dom('[data-test-breadcrumb-default]')
    81        .exists('Default breadcrumb registers if no type is specified');
    82    });
    83  });