@finos/legend-studio
Version:
109 lines • 11.2 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { EDITOR_LANGUAGE } from '@finos/legend-application';
import { clsx, CompareIcon, Dialog, PanelLoadingIndicator, RefreshIcon, WrenchIcon, } from '@finos/legend-art';
import { TestError } from '@finos/legend-graph';
import { prettyCONSTName, tryToFormatLosslessJSONString, } from '@finos/legend-shared';
import { observer } from 'mobx-react-lite';
import { AssertFailState, EqualToJsonAssertFailState, EqualToJsonAssertionState, TestAssertionStatusState, TEST_ASSERTION_TAB, } from '../../../../stores/editor-state/element-editor-state/testable/TestAssertionState.js';
import { externalFormatData_setData } from '../../../../stores/graphModifier/DSLData_GraphModifierHelper.js';
import { TESTABLE_RESULT } from '../../../../stores/sidebar-state/testable/GlobalTestRunnerState.js';
import { JsonDiffView } from '../../../shared/DiffView.js';
import { StudioTextInputEditor } from '../../../shared/StudioTextInputEditor.js';
import { UnsupportedEditorPanel } from '../UnsupportedElementEditor.js';
const EqualToJsonAsssertionEditor = observer((props) => {
const { equalToJsonAssertionState, testAssertionEditorState } = props;
const assertion = equalToJsonAssertionState.assertion;
const formatExpectedResultJSONString = () => {
externalFormatData_setData(assertion.expected, tryToFormatLosslessJSONString(assertion.expected.data));
};
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "panel__header", children: [_jsx("div", { className: "panel__header__title", children: _jsx("div", { className: "panel__header__title__label", children: "expected" }) }), _jsx("div", { className: "panel__header__actions", children: _jsx("button", { className: "panel__header__action", disabled: testAssertionEditorState.testState.isReadOnly, tabIndex: -1, onClick: formatExpectedResultJSONString, title: 'Format JSON (Alt + Shift + F)', children: _jsx(WrenchIcon, {}) }) })] }), _jsx("div", { className: "equal-to-json-editor__content panel__content", children: _jsx("div", { className: "equal-to-json-editor__content__data", children: _jsx(StudioTextInputEditor, { inputValue: assertion.expected.data, language: EDITOR_LANGUAGE.JSON, updateInput: (val) => {
equalToJsonAssertionState.setExpectedValue(val);
}, hideGutter: true }) }) })] }));
});
const EqualToJsonAssertFailViewer = observer((props) => {
const { equalToJsonAssertFailState } = props;
const open = () => equalToJsonAssertFailState.setDiffModal(true);
const close = () => equalToJsonAssertFailState.setDiffModal(false);
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "equal-to-json-editor__message", onClick: open, children: `<Click to see difference>` }), equalToJsonAssertFailState.diffModal && (_jsx(Dialog, { open: Boolean(equalToJsonAssertFailState.diffModal), onClose: close, classes: {
root: 'editor-modal__root-container',
container: 'editor-modal__container',
paper: 'editor-modal__content',
}, children: _jsxs("div", { className: "modal modal--dark editor-modal", children: [_jsx("div", { className: "modal__header", children: _jsxs("div", { className: "equal-to-json-result__diff__summary", children: [_jsx("div", { className: "equal-to-json-result__diff__header__label", children: "expected" }), _jsx("div", { className: "equal-to-json-result__diff__icon", children: _jsx(CompareIcon, {}) }), _jsx("div", { className: "equal-to-json-result__diff__header__label", children: "actual" })] }) }), _jsx("div", { className: "modal__body", children: _jsx(JsonDiffView, { from: equalToJsonAssertFailState.status.expected, to: equalToJsonAssertFailState.status.actual }) }), _jsx("div", { className: "modal__footer", children: _jsx("button", { className: "btn modal__footer__close-btn", onClick: close, children: "Close" }) })] }) }))] }));
});
const TestErrorViewer = observer((props) => {
const { testError } = props;
return (_jsx(_Fragment, { children: _jsx("div", { className: "testable-test-assertion-result__summary-info", children: testError.error }) }));
});
const AssertFailViewer = observer((props) => {
const { assertFailState } = props;
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "testable-test-assertion-result__summary-info", children: assertFailState.status.message }), assertFailState instanceof EqualToJsonAssertFailState && (_jsx(EqualToJsonAssertFailViewer, { equalToJsonAssertFailState: assertFailState }))] }));
});
const TestAssertionResultViewer = observer((props) => {
const { testAssertionEditorState } = props;
const parentAssertionResultState = testAssertionEditorState.assertionResultState;
const assertionResult = testAssertionEditorState.assertionResultState.result;
const renderAssertionResult = (assertionResultState) => {
const _statusState = assertionResultState.statusState;
if (assertionResultState.testResult instanceof TestError) {
return _jsx(TestErrorViewer, { testError: assertionResultState.testResult });
}
else if (_statusState instanceof TestAssertionStatusState) {
return _statusState instanceof AssertFailState ? (_jsx(AssertFailViewer, { assertFailState: _statusState })) : null;
}
return null;
};
const renderResultView = (assertionResultState) => {
const _statusState = assertionResultState.statusState;
if (_statusState === undefined ||
_statusState instanceof TestAssertionStatusState) {
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "testable-test-assertion-result__summary-info", children: ["Result: ", prettyCONSTName(assertionResult)] }), renderAssertionResult(assertionResultState)] }));
}
else {
return Array.from(_statusState.entries()).map((state) => {
const _key = state[0];
const resultState = state[1];
return (_jsxs("div", { className: "testable-test-assertion-result__summary-multi", children: [_jsx("div", { children: _key }), _jsxs("div", { className: "testable-test-assertion-result__summary-info", children: ["Result: ", prettyCONSTName(resultState.result)] }), renderAssertionResult(resultState)] }, _key));
});
}
};
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "panel__header", children: [_jsx("div", { className: "panel__header__title", children: _jsx("div", { className: "panel__header__title__label", children: "result" }) }), _jsx("div", { className: "panel__header__actions" })] }), _jsxs("div", { className: "testable-test-assertion-result__content panel__content", children: [_jsxs("div", { className: clsx('testable-test-assertion-result__summary', {
'testable-test-assertion-result__summary--fail': assertionResult === TESTABLE_RESULT.ERROR ||
assertionResult === TESTABLE_RESULT.FAILED,
'testable-test-assertion-result__summary--success': assertionResult === TESTABLE_RESULT.PASSED,
}), children: [_jsx("div", { className: "testable-test-assertion-result__summary-main", children: "Assertion Result Summary" }), assertionResult === TESTABLE_RESULT.IN_PROGRESS && (_jsx("div", { className: "testable-test-assertion-result__summary-info", children: "Running assertion..." })), !(assertionResult === TESTABLE_RESULT.IN_PROGRESS) && (_jsxs(_Fragment, { children: [_jsxs("div", { className: "testable-test-assertion-result__summary-info", children: ["Id: ", testAssertionEditorState.assertion.id] }), _jsxs("div", { className: "testable-test-assertion-result__summary-info", children: ["Type: ", testAssertionEditorState.assertionState.label()] }), renderResultView(parentAssertionResultState)] }))] }), _jsx("div", {})] })] }));
});
export const TestAssertionEditor = observer((props) => {
const { testAssertionState } = props;
const selectedTab = testAssertionState.selectedTab;
const isReadOnly = testAssertionState.testState.isReadOnly;
const changeTab = (val) => testAssertionState.setSelectedTab(val);
const renderContent = (state) => {
if (state instanceof EqualToJsonAssertionState) {
return (_jsx(EqualToJsonAsssertionEditor, { equalToJsonAssertionState: state, testAssertionEditorState: testAssertionState }));
}
return (_jsx(UnsupportedEditorPanel, { text: "Can't display this assertion in form-mode", isReadOnly: isReadOnly }));
};
const generate = () => {
testAssertionState.generateExpected();
};
const isRunning = testAssertionState.generatingExpectedAction.isInProgress;
return (_jsxs("div", { className: "testable-test-assertion-editor", children: [_jsx(PanelLoadingIndicator, { isLoading: isRunning }), _jsxs("div", { className: "testable-test-assertion-editor__header", children: [_jsx("div", { className: "testable-test-assertion-editor__header__tabs", children: Object.values(TEST_ASSERTION_TAB).map((tab) => (_jsx("div", { onClick: () => changeTab(tab), className: clsx('testable-test-assertion-editor__header__tab', {
'testable-test-assertion-editor__header__tab--active': tab === selectedTab,
}), children: prettyCONSTName(tab) }, tab))) }), _jsx("div", { className: "testable-test-assertion-editor__header__actions", children: _jsx("button", { className: "panel__header__action service-execution-editor__test-data__generate-btn", onClick: generate, title: "Generate expected result if possible", disabled: isReadOnly, tabIndex: -1, children: _jsxs("div", { className: "service-execution-editor__test-data__generate-btn__label", children: [_jsx(RefreshIcon, { className: "service-execution-editor__test-data__generate-btn__label__icon" }), _jsx("div", { className: "service-execution-editor__test-data__generate-btn__label__title", children: "Generate" })] }) }) })] }), _jsxs("div", { className: "testable-test-assertion-editor__content", children: [selectedTab === TEST_ASSERTION_TAB.ASSERTION_SETUP && (_jsx("div", { className: "testable-test-assertion-editor__setup", children: renderContent(testAssertionState.assertionState) })), selectedTab === TEST_ASSERTION_TAB.ASSERTION_RESULT && (_jsx(TestAssertionResultViewer, { testAssertionEditorState: testAssertionState }))] })] }));
});
//# sourceMappingURL=TestAssertionEditor.js.map