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

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