Repository: hashicorp/vault
File: ui/tests/integration/components/open-api-explorer/swagger-ui-test.js (JavaScript)

Code before:
    });

    this.totalApiPaths = Object.keys(this.openApiResponse.paths).length;

    this.renderComponent = () => render(hbs`<SwaggerUi/>`, { owner: this.engine });
  });

  test('it renders', async function (assert) {
    await this.renderComponent();

    assert.dom(SELECTORS.container).exists('renders component');
    assert.dom(SELECTORS.apiPathBlock).exists({ count: this.totalApiPaths }, 'renders all api paths');
  });

  test('it can search', async function (assert) {
    await this.renderComponent();
    // in testing only the input is not filling correctly except after the second time
    await fillIn(SELECTORS.searchInput, 'moot');
    await typeIn(SELECTORS.searchInput, 'token');
    // for some reason search results are not rendered immediately in tests,
    // so asserting that the search input has the value we expect is the best we can do here
    // if the search fn breaks, this test will fail
    assert.dom(SELECTORS.searchInput).hasValue('token', 'search input has value');
  });

  test('it should render camelized operation ids', async function (assert) {
    const envStub = sinon.stub(config, 'environment').value('development');

    await this.renderComponent();

    const id = this.openApiResponse.paths['/auth/token/create'].post.operationId;
    assert.dom(SELECTORS.operationId).hasText(camelize(id), 'renders camelized operation id');

    envStub.restore();
  });
});


Review comment (suggestion):
Could we do a test to ensure that no IDs show in the production environment? Just in case a future change accidentally changes this. It's also documented that the intended behavior is to _not_ show these outside of development.

Code after:
    });

    this.totalApiPaths = Object.keys(this.openApiResponse.paths).length;

    this.renderComponent = () => render(hbs`<SwaggerUi/>`, { owner: this.engine });
  });

  test('it renders', async function (assert) {
    await this.renderComponent();

    assert.dom(SELECTORS.container).exists('renders component');
    assert.dom(SELECTORS.apiPathBlock).exists({ count: this.totalApiPaths }, 'renders all api paths');
  });

  test('it can search', async function (assert) {
    await this.renderComponent();
    // in testing only the input is not filling correctly except after the second time
    await fillIn(SELECTORS.searchInput, 'moot');
    await typeIn(SELECTORS.searchInput, 'token');
    // for some reason search results are not rendered immediately in tests,
    // so asserting that the search input has the value we expect is the best we can do here
    // if the search fn breaks, this test will fail
    assert.dom(SELECTORS.searchInput).hasValue('token', 'search input has value');
  });

  test('it should render camelized operation ids', async function (assert) {
    const envStub = sinon.stub(config, 'environment').value('development');

    await this.renderComponent();

    const id = this.openApiResponse.paths['/auth/token/create'].post.operationId;
    assert.dom(SELECTORS.operationId).hasText(camelize(id), 'renders camelized operation id');

    envStub.restore();
  });

  test('it should not render operation ids in production', async function (assert) {
    const envStub = sinon.stub(config, 'environment').value('production');

    await this.renderComponent();

    assert.dom(SELECTORS.operationId).doesNotExist('operation ids are hidden in production environment');

    envStub.restore();
  });
});