Jordan Reimer 712d3338b7
[UI] Ember Data Migration - Sync Overview/Destinations (#30524)
* improves path handling in capabilities service

* converts has-capability to class helper and adds pathKey and params args

* adds api service to sync engine

* updates sync types

* improves typings in paginate-list util

* adds api client error handling to error page component

* adds api utils for sync

* updates sync overview route and page component to use api service

* updates sync destinations route and page component to use api service

* adds missing copyright header

* fixes paginate-list regression

* fixes return type for has-capability helper

* Apply suggestions from code review

Co-authored-by: Angel Garbarino <Monkeychip@users.noreply.github.com>

* fixes page error tests

* resolves suggestions from review

* fixes has-capability usage errors

* fixes comment in capabilities service

* more test fixes

---------

Co-authored-by: Angel Garbarino <Monkeychip@users.noreply.github.com>
2025-05-07 10:53:56 -06:00

86 lines
2.9 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupRenderingTest } from 'vault/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { getErrorResponse } from 'vault/tests/helpers/api/error-response';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
module('Integration | Component | page/error', function (hooks) {
setupRenderingTest(hooks);
test('it should render 404 error', async function (assert) {
this.error = {
httpStatus: 404,
path: '/v1/kubernetes/config',
};
await render(hbs`<Page::Error @error={{this.error}} />`);
assert.dom('h1').hasText('404 Not Found', 'Error title renders');
assert
.dom('p')
.hasText(`Sorry, we were unable to find any content at ${this.error.path}.`, 'Error message renders');
});
test('it should render 403 error', async function (assert) {
this.error = {
httpStatus: 403,
path: '/v1/kubernetes/config',
};
await render(hbs`<Page::Error @error={{this.error}} />`);
assert.dom('h1').hasText('Not authorized', 'Error title renders');
assert
.dom('p')
.hasText(`You are not authorized to access content at ${this.error.path}.`, 'Error message renders');
});
test('it should render general error', async function (assert) {
this.error = {
message: 'An unexpected error occurred',
errors: ['This is one thing that went wrong', 'Unfortunately something else went wrong too'],
};
await render(hbs`<Page::Error @error={{this.error}} />`);
assert.dom('h1').hasText('Error', 'Error title renders');
assert.dom('[data-test-page-error-message]').hasText(this.error.message, 'Error message renders');
this.error.errors.forEach((error, index) => {
assert
.dom(`[data-test-page-error-details="${index}"]`)
.hasText(this.error.errors[index], 'Error detail renders');
});
});
test('it should handle api client errors', async function (assert) {
this.error = getErrorResponse();
await render(hbs`<Page::Error @error={{this.error}} />`);
assert
.dom(GENERAL.pageError.errorTitle('404'))
.hasText('404 Not Found', 'Error title renders based on status');
assert
.dom(GENERAL.pageError.errorSubtitle)
.hasText(
'Sorry, we were unable to find any content at /v1/test/error/parsing.',
'Error subtitle renders'
);
const error = { errors: ['something bad happened'], message: 'bad things occurred' };
this.error = getErrorResponse(error, 400);
await render(hbs`<Page::Error @error={{this.error}} />`);
assert.dom(GENERAL.pageError.errorTitle('400')).hasText('Error', 'Error title renders');
assert.dom(GENERAL.pageError.errorMessage).hasText(error.message, 'Error message renders');
assert.dom(GENERAL.pageError.errorDetails).hasText(error.errors[0], 'Error details render');
});
});