mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-12 03:07:05 +00:00
88 lines
2.9 KiB
TypeScript
88 lines
2.9 KiB
TypeScript
![]() |
import { module, test } from 'qunit';
|
||
|
import { setupRenderingTest } from 'ember-qunit';
|
||
|
import { render } from '@ember/test-helpers';
|
||
|
import hbs from 'htmlbars-inline-precompile';
|
||
|
import { stubService } from '@datahub/utils/test-helpers/stub-service';
|
||
|
import { BaseEntity } from '@datahub/data-models/entity/base-entity';
|
||
|
import { IEntityRenderProps } from '@datahub/data-models/types/entity/rendering/entity-render-props';
|
||
|
import { TestContext } from 'ember-test-helpers';
|
||
|
import { MirageTestContext } from '@datahub/utils/types/vendor/ember-cli-mirage/mirage-tests';
|
||
|
import { getApiRoot, ApiVersion } from '@datahub/utils/api/shared';
|
||
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||
|
import { setupErrorHandler } from '@datahub/utils/test-helpers/setup-error';
|
||
|
import { setupHandlerRegistrations } from '@datahub/shared/test-helpers/setup-handler-registrations';
|
||
|
|
||
|
const setupTest = async function(
|
||
|
test: TestContext,
|
||
|
options: {
|
||
|
withBrowsePage: boolean;
|
||
|
}
|
||
|
): Promise<void> {
|
||
|
class MockEntity extends BaseEntity<{}> {
|
||
|
static get displayName(): string {
|
||
|
return 'mock';
|
||
|
}
|
||
|
static get renderProps(): IEntityRenderProps {
|
||
|
const renderProps: IEntityRenderProps = {
|
||
|
apiEntityName: '',
|
||
|
search: {
|
||
|
attributes: [],
|
||
|
autocompleteNameField: '',
|
||
|
placeholder: ''
|
||
|
}
|
||
|
};
|
||
|
if (options.withBrowsePage) {
|
||
|
renderProps.browse = {
|
||
|
showHierarchySearch: false
|
||
|
};
|
||
|
}
|
||
|
return renderProps;
|
||
|
}
|
||
|
get name(): string {
|
||
|
return 'entityName';
|
||
|
}
|
||
|
get displayName(): string {
|
||
|
return this.staticInstance.displayName;
|
||
|
}
|
||
|
}
|
||
|
stubService('configurator', {
|
||
|
getConfig(): boolean {
|
||
|
return true;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
stubService('data-models', {
|
||
|
createInstance(_entityDisplayName: string, urn: string): MockEntity {
|
||
|
return new MockEntity(urn);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
test.setProperties({
|
||
|
entityClass: MockEntity,
|
||
|
urn: 'some-urn',
|
||
|
tabSelected: 'overview'
|
||
|
});
|
||
|
await render(
|
||
|
hbs`<EntityPage::EntityPageMain @urn={{this.urn}} @entityClass={{this.entityClass}} @tabSelected={{this.tabSelected}} />`
|
||
|
);
|
||
|
};
|
||
|
|
||
|
module('Integration | Component | entity-page/entity-page-main', function(hooks): void {
|
||
|
setupRenderingTest(hooks);
|
||
|
setupMirage(hooks);
|
||
|
setupErrorHandler(hooks, { catchMsgs: ['Unexpected token E in JSON at position 0'] });
|
||
|
setupHandlerRegistrations(hooks);
|
||
|
|
||
|
test('it renders', async function(assert): Promise<void> {
|
||
|
await setupTest(this, { withBrowsePage: false });
|
||
|
assert.dom().hasText('MOCK entityName');
|
||
|
});
|
||
|
|
||
|
test('breadcrumb error', async function(this: MirageTestContext, assert): Promise<void> {
|
||
|
this.server.namespace = getApiRoot(ApiVersion.v2);
|
||
|
this.server.get('/browsePaths', () => 'Error', 500);
|
||
|
await setupTest(this, { withBrowsePage: true });
|
||
|
assert.dom().containsText('Error loading the path. Please refresh the page and try again');
|
||
|
});
|
||
|
});
|