@testing-library/react#getByTitle TypeScript Examples
The following examples show how to use
@testing-library/react#getByTitle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EditPanel.test.tsx From legend-studio with Apache License 2.0 | 5 votes |
test(integrationTest('Test navigation between element states'), async () => {
// Test opening multiple elements
await TEST__openElementFromExplorerTree('ui::test1::Animal', renderResult);
const packageExplorer = renderResult.getByTestId(
LEGEND_STUDIO_TEST_ID.EXPLORER_TREES,
);
fireEvent.click(getByText(packageExplorer, 'TestClass'));
fireEvent.click(getByText(packageExplorer, 'TestEnumeration'));
fireEvent.click(getByText(packageExplorer, 'Anyone'));
fireEvent.click(getByText(packageExplorer, 'Dog'));
fireEvent.click(getByText(packageExplorer, 'Something'));
fireEvent.click(getByText(packageExplorer, 'ProfileTest'));
const editPanelHeader = renderResult.getByTestId(
LEGEND_STUDIO_TEST_ID.EDIT_PANEL__HEADER_TABS,
);
await waitFor(() => getByText(editPanelHeader, 'ProfileTest'));
const openElements = [
'TestEnumeration',
'TestClass',
'Anyone',
'Dog',
'Something',
'ProfileTest',
];
openElements.forEach((openEl) => getByText(editPanelHeader, openEl));
// navigate through visit buttons
fireEvent.click(getByText(editPanelHeader, 'TestClass'));
await waitFor(() => renderResult.getByText('founder'));
const navigateToClass = async (className: string): Promise<void> => {
const classForm = renderResult.getByTestId(
LEGEND_STUDIO_TEST_ID.CLASS_FORM_EDITOR,
);
const property = await waitFor(() => getByText(classForm, className));
const propertyBasicEditor = property.parentElement as HTMLElement;
const navigateButton = getByTestId(
propertyBasicEditor,
LEGEND_STUDIO_TEST_ID.TYPE_VISIT,
);
fireEvent.click(navigateButton);
await waitFor(() => getByText(editPanelHeader, className));
};
await navigateToClass('Person');
await navigateToClass('Firm');
await navigateToClass('Person');
await navigateToClass('Degree');
const newOpened = ['Firm', 'Degree', 'Person'];
openElements
.concat(newOpened)
.forEach((openElement) => getByText(editPanelHeader, openElement));
// test closing of tabs
const closeTabs = ['Firm', 'Degree', 'TestEnumeration'];
closeTabs.forEach((tab) => {
const text = getByText(editPanelHeader, tab);
const parent = text.parentElement as HTMLElement;
const deleteButton = getByTitle(parent, 'Close');
fireEvent.click(deleteButton);
});
closeTabs.forEach((tab) =>
expect(queryByText(editPanelHeader, tab)).toBeNull(),
);
// TODO Add Diff Element States
});
Example #2
Source File: QueryBuilder_FetchStructure.test.tsx From legend-studio with Apache License 2.0 | 4 votes |
test(
integrationTest(
'Query builder state is properly set after processing a projection lambda',
),
async () => {
const pluginManager = LegendQueryPluginManager.create();
pluginManager.usePresets([new Query_GraphPreset()]).install();
const mockedQueryStore = TEST__provideMockedLegendQueryStore({
pluginManager,
});
const renderResult = await TEST__setUpQueryEditor(
mockedQueryStore,
TEST_DATA__ComplexRelationalModel,
stub_RawLambda(),
'model::relational::tests::simpleRelationalMapping',
'model::MyRuntime',
);
const queryBuilderState = mockedQueryStore.queryBuilderState;
const _personClass = mockedQueryStore.graphManagerState.graph.getClass(
'model::pure::tests::model::simple::Person',
);
const _firmClass = mockedQueryStore.graphManagerState.graph.getClass(
'model::pure::tests::model::simple::Firm',
);
const mapping = mockedQueryStore.graphManagerState.graph.getMapping(
'model::relational::tests::simpleRelationalMapping',
);
act(() => {
queryBuilderState.changeClass(_personClass);
});
const queryBuilderSetup = await waitFor(() =>
renderResult.getByTestId(QUERY_BUILDER_TEST_ID.QUERY_BUILDER_SETUP),
);
await waitFor(() => getByText(queryBuilderSetup, 'Person'));
await waitFor(() =>
getByText(queryBuilderSetup, 'simpleRelationalMapping'),
);
await waitFor(() => getByText(queryBuilderSetup, 'MyRuntime'));
const treeData = guaranteeNonNullable(
queryBuilderState.explorerState.treeData,
);
const rootNode = guaranteeType(
treeData.nodes.get(treeData.rootIds[0] as string),
QueryBuilderExplorerTreeRootNodeData,
);
expect(getRootSetImplementation(mapping, _personClass)).toBe(
rootNode.mappingData.targetSetImpl,
);
expect(rootNode.mappingData.mapped).toBe(true);
// simpleProjection
act(() => {
queryBuilderState.initialize(
create_RawLambda(
TEST_DATA__simpleProjection.parameters,
TEST_DATA__simpleProjection.body,
),
);
});
let projectionCols = await waitFor(() =>
renderResult.getByTestId(QUERY_BUILDER_TEST_ID.QUERY_BUILDER_PROJECTION),
);
const FIRST_NAME_ALIAS = 'Edited First Name';
const LAST_NAME_ALIAS = 'Last Name';
expect(
await waitFor(() =>
projectionCols.querySelector(`input[value="${FIRST_NAME_ALIAS}"]`),
),
).not.toBeNull();
expect(
await waitFor(() =>
projectionCols.querySelector(`input[value="${LAST_NAME_ALIAS}"]`),
),
).not.toBeNull();
expect(
queryBuilderState.fetchStructureState.projectionState.columns.length,
).toBe(2);
let fistNameCol = guaranteeNonNullable(
queryBuilderState.fetchStructureState.projectionState.columns.find(
(e) => e.columnName === FIRST_NAME_ALIAS,
),
);
const firstNameProperty = guaranteeType(
fistNameCol,
QueryBuilderSimpleProjectionColumnState,
).propertyExpressionState.propertyExpression.func;
expect(firstNameProperty).toBe(getClassProperty(_personClass, 'firstName'));
const lastNameCol = guaranteeNonNullable(
queryBuilderState.fetchStructureState.projectionState.columns.find(
(e) => e.columnName === LAST_NAME_ALIAS,
),
);
const lastNameProperty = guaranteeType(
lastNameCol,
QueryBuilderSimpleProjectionColumnState,
).propertyExpressionState.propertyExpression.func;
expect(lastNameProperty).toBe(getClassProperty(_personClass, 'lastName'));
expect(queryBuilderState.resultSetModifierState.limit).toBeUndefined();
// chainedProperty
const CHAINED_PROPERTY_ALIAS = 'Firm/Legal Name';
act(() => {
queryBuilderState.initialize(
create_RawLambda(
TEST_DATA__projectionWithChainedProperty.parameters,
TEST_DATA__projectionWithChainedProperty.body,
),
);
});
const projectionWithChainedPropertyCols = await waitFor(() =>
renderResult.getByTestId(QUERY_BUILDER_TEST_ID.QUERY_BUILDER_PROJECTION),
);
expect(
await waitFor(() =>
projectionWithChainedPropertyCols.querySelector(
`input[value="${CHAINED_PROPERTY_ALIAS}"]`,
),
),
).not.toBeNull();
expect(
queryBuilderState.fetchStructureState.projectionState.columns.length,
).toBe(1);
let legalNameCol = guaranteeNonNullable(
queryBuilderState.fetchStructureState.projectionState.columns.find(
(e) => e.columnName === CHAINED_PROPERTY_ALIAS,
),
);
const legalNameColProperty = guaranteeType(
legalNameCol,
QueryBuilderSimpleProjectionColumnState,
).propertyExpressionState.propertyExpression.func;
expect(legalNameColProperty).toBe(
getClassProperty(_firmClass, 'legalName'),
);
const _firmPropertyExpression = guaranteeType(
guaranteeType(legalNameCol, QueryBuilderSimpleProjectionColumnState)
.propertyExpressionState.propertyExpression.parametersValues[0],
AbstractPropertyExpression,
);
expect(_firmPropertyExpression.func).toBe(
getClassProperty(_personClass, 'firm'),
);
expect(queryBuilderState.resultSetModifierState.limit).toBeUndefined();
// result set modifiers
const RESULT_LIMIT = 500;
act(() => {
queryBuilderState.initialize(
create_RawLambda(
TEST_DATA__projectionWithResultSetModifiers.parameters,
TEST_DATA__projectionWithResultSetModifiers.body,
),
);
});
projectionCols = await waitFor(() =>
renderResult.getByTestId(QUERY_BUILDER_TEST_ID.QUERY_BUILDER_PROJECTION),
);
expect(
await waitFor(() =>
projectionCols.querySelector(`input[value="${FIRST_NAME_ALIAS}"]`),
),
).not.toBeNull();
expect(
await waitFor(() =>
projectionCols.querySelector(`input[value="${LAST_NAME_ALIAS}"]`),
),
).not.toBeNull();
expect(
await waitFor(() =>
projectionCols.querySelector(
`input[value="${CHAINED_PROPERTY_ALIAS}"]`,
),
),
).not.toBeNull();
expect(
queryBuilderState.fetchStructureState.projectionState.columns.length,
).toBe(3);
const resultSetModifierState = queryBuilderState.resultSetModifierState;
expect(resultSetModifierState.limit).toBe(RESULT_LIMIT);
expect(resultSetModifierState.distinct).toBe(true);
expect(resultSetModifierState.sortColumns).toHaveLength(2);
fistNameCol = guaranteeNonNullable(
queryBuilderState.fetchStructureState.projectionState.columns.find(
(e) => e.columnName === FIRST_NAME_ALIAS,
),
);
legalNameCol = guaranteeNonNullable(
queryBuilderState.fetchStructureState.projectionState.columns.find(
(e) => e.columnName === CHAINED_PROPERTY_ALIAS,
),
);
const firstnameSortState = guaranteeNonNullable(
resultSetModifierState.sortColumns.find(
(e) => e.columnState === fistNameCol,
),
);
expect(firstnameSortState.sortType).toBe(COLUMN_SORT_TYPE.ASC);
const legalNameColSortState = guaranteeNonNullable(
resultSetModifierState.sortColumns.find(
(e) => e.columnState === legalNameCol,
),
);
expect(legalNameColSortState.sortType).toBe(COLUMN_SORT_TYPE.DESC);
const queryBuilder = await waitFor(() =>
renderResult.getByTestId(QUERY_BUILDER_TEST_ID.QUERY_BUILDER),
);
fireEvent.click(
getByTitle(queryBuilder, 'Configure result set modifiers...'),
);
const modal = await waitFor(() => renderResult.getByRole('dialog'));
await waitFor(() => getByText(modal, 'Sort and Order'));
await waitFor(() => getByText(modal, 'Eliminate Duplicate Rows'));
await waitFor(() => getByText(modal, 'Limit Results'));
await waitFor(() => getByText(modal, FIRST_NAME_ALIAS));
await waitFor(() => getByText(modal, CHAINED_PROPERTY_ALIAS));
expect(
await waitFor(() =>
modal.querySelector(`input[value="${RESULT_LIMIT}"]`),
),
).not.toBeNull();
fireEvent.click(getByText(modal, 'Close'));
// filter with simple condition
await waitFor(() => renderResult.getByText('Add a filter condition'));
act(() => {
queryBuilderState.initialize(
create_RawLambda(
TEST_DATA__getAllWithOneConditionFilter.parameters,
TEST_DATA__getAllWithOneConditionFilter.body,
),
);
});
let filterValue = 'testFirstName';
let filterPanel = await waitFor(() =>
renderResult.getByTestId(QUERY_BUILDER_TEST_ID.QUERY_BUILDER_FILTER),
);
expect(
await waitFor(() =>
filterPanel.querySelector(`input[value="${filterValue}"]`),
),
).not.toBeNull();
await waitFor(() => getByText(filterPanel, 'First Name'));
await waitFor(() => getByText(filterPanel, 'is'));
const filterState = queryBuilderState.filterState;
expect(filterState.nodes.size).toBe(1);
expect(
queryBuilderState.fetchStructureState.projectionState.columns.length,
).toBe(0);
// filter with group condition
act(() => {
queryBuilderState.resetQueryBuilder();
queryBuilderState.resetQuerySetup();
});
await waitFor(() => renderResult.getByText('Add a filter condition'));
act(() => {
queryBuilderState.initialize(
create_RawLambda(
TEST_DATA__getAllWithGroupedFilter.parameters,
TEST_DATA__getAllWithGroupedFilter.body,
),
);
});
filterPanel = await waitFor(() =>
renderResult.getByTestId(QUERY_BUILDER_TEST_ID.QUERY_BUILDER_FILTER),
);
await waitFor(() =>
expect(getAllByText(filterPanel, 'is')).toHaveLength(2),
);
await waitFor(() => getByText(filterPanel, 'or'));
filterValue = 'lastNameTest';
expect(
await waitFor(() =>
filterPanel.querySelector(`input[value="${filterValue}"]`),
),
).not.toBeNull();
await waitFor(() => getByText(filterPanel, 'First Name'));
const lastNameFilterValue = 'lastNameTest';
expect(
await waitFor(() =>
filterPanel.querySelector(`input[value="${lastNameFilterValue}"]`),
),
).not.toBeNull();
await waitFor(() => getByText(filterPanel, 'Last Name'));
expect(queryBuilderState.filterState.nodes.size).toBe(3);
expect(
queryBuilderState.fetchStructureState.projectionState.columns.length,
).toBe(0);
// projection column with derived property
act(() => {
queryBuilderState.resetQueryBuilder();
queryBuilderState.resetQuerySetup();
});
await waitFor(() => renderResult.getByText('Add a filter condition'));
act(() => {
queryBuilderState.initialize(
create_RawLambda(
TEST_DATA__projectWithDerivedProperty.parameters,
TEST_DATA__projectWithDerivedProperty.body,
),
);
});
projectionCols = await waitFor(() =>
renderResult.getByTestId(QUERY_BUILDER_TEST_ID.QUERY_BUILDER_PROJECTION),
);
expect(
await waitFor(() =>
projectionCols.querySelector(`input[value="Full Name With Title"]`),
),
).not.toBeNull();
await waitFor(() => getByText(projectionCols, 'Name With Title'));
expect(
queryBuilderState.fetchStructureState.projectionState.columns.length,
).toBe(1);
fireEvent.click(
getByTitle(projectionCols, 'Set Derived Property Argument(s)...'),
);
const dpModal = await waitFor(() => renderResult.getByRole('dialog'));
await waitFor(() => getByText(dpModal, 'Derived Property'));
await waitFor(() => getByText(dpModal, 'Name With Title'));
await waitFor(() => getByText(dpModal, 'title'));
expect(
await waitFor(() => dpModal.querySelector(`input[value="Mr."]`)),
).not.toBeNull();
},
);
Example #3
Source File: ServiceRegistrationTest.test.tsx From legend-studio with Apache License 2.0 | 4 votes |
test(
integrationTest(
'Service Editor basic general and registration functionality for projects without versions',
),
async () => {
const mockedEditorStore = await setup(
TEST_DATA__DefaultSDLCInfo.project,
TEST_DATA__DefaultSDLCInfo.workspace,
);
const result = new ServiceRegistrationResult(
'https://legend.org/exec',
'/myservice',
'id1',
);
MOBX__enableSpyOrMock();
jest
.spyOn(
mockedEditorStore.graphManagerState.graphManager,
'registerService',
)
.mockResolvedValue(result);
jest
.spyOn(
mockedEditorStore.graphManagerState.graphManager,
'activateService',
)
.mockResolvedValue();
MOBX__disableSpyOrMock();
await TEST__openElementFromExplorerTree('test::myService', renderResult);
const editPanelHeader = await waitFor(() =>
renderResult.getByTestId(LEGEND_STUDIO_TEST_ID.EDIT_PANEL__HEADER_TABS),
);
await waitFor(() => getByText(editPanelHeader, 'myService'));
const editPanel = await waitFor(() =>
renderResult.getByTestId(LEGEND_STUDIO_TEST_ID.EDIT_PANEL),
);
// labels + values
await waitFor(() => getByText(editPanel, 'URL Pattern'));
expect(
await waitFor(() =>
editPanel.querySelector(`input[value="/example/myTestUrl/{myParam}"]`),
),
).toBeTruthy();
await waitFor(() => getByText(editPanel, 'URL Pattern'));
await waitFor(() => getByText(editPanel, 'myParam'));
await waitFor(() => getByText(editPanel, 'Documentation'));
await waitFor(() => getByText(editPanel, 'Auto Activate Updates'));
await waitFor(() => getByText(editPanel, 'Owners'));
await waitFor(() => getByText(editPanel, 'owner1'));
await waitFor(() => getByText(editPanel, 'owner2'));
// add owner
const serviceEditorState =
mockedEditorStore.getCurrentEditorState(ServiceEditorState);
const service = serviceEditorState.service;
expect(service.owners).toHaveLength(2);
fireEvent.click(getByTitle(editPanel, 'Add owner'));
const ownerInput = await waitFor(() =>
getByPlaceholderText(editPanel, 'Enter an owner...'),
);
fireEvent.change(ownerInput, { target: { value: 'owner3' } });
fireEvent.click(getByText(editPanel, 'Save'));
await waitFor(() => getByText(editPanel, 'owner3'));
expect(service.owners).toHaveLength(3);
// registration
fireEvent.click(getByText(editPanel, 'Registration'));
const registrationEditor = await waitFor(() =>
renderResult.getByTestId(
LEGEND_STUDIO_TEST_ID.SERVICE_REGISTRATION_EDITOR,
),
);
await waitFor(() =>
getByText(
registrationEditor,
'Only valid for Semi Interactive and Prod service types',
),
);
await waitFor(() => getByText(registrationEditor, 'Execution Server'));
await waitFor(() => getByText(registrationEditor, 'Service Type'));
await waitFor(() => getByText(registrationEditor, 'Project Version'));
// register
fireEvent.click(getByTitle(registrationEditor, 'Register Service'));
const actionAlertDialog = await waitFor(() =>
renderResult.getByRole('dialog'),
);
await waitFor(() => getByText(actionAlertDialog, 'Launch Service'));
getByText(
actionAlertDialog,
'Service with patten /myservice registered and activated',
);
fireEvent.click(renderResult.getByText('Close'));
// check no owners check
service_deleteOwner(serviceEditorState.service, 0);
service_deleteOwner(serviceEditorState.service, 0);
service_deleteOwner(serviceEditorState.service, 0);
fireEvent.click(getByTitle(registrationEditor, 'Register Service'));
await waitFor(() =>
renderResult.getByText(
'Service needs to have at least 2 owners in order to be registered',
),
);
},
);