datajunction-ui 0.0.1-rc.17 → 0.0.1-rc.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +1 -1
- package/dj-logo.svg +10 -0
- package/package.json +28 -6
- package/src/app/__tests__/__snapshots__/index.test.tsx.snap +5 -84
- package/src/app/components/djgraph/DJNode.jsx +1 -1
- package/src/app/components/djgraph/LayoutFlow.jsx +1 -1
- package/src/app/constants.js +2 -0
- package/src/app/icons/AlertIcon.jsx +32 -0
- package/src/app/icons/DJLogo.jsx +36 -0
- package/src/app/icons/DeleteIcon.jsx +21 -0
- package/src/app/icons/EditIcon.jsx +18 -0
- package/src/app/index.tsx +70 -36
- package/src/app/pages/AddEditNodePage/FormikSelect.jsx +33 -0
- package/src/app/pages/AddEditNodePage/FullNameField.jsx +36 -0
- package/src/app/pages/AddEditNodePage/Loadable.jsx +16 -0
- package/src/app/pages/AddEditNodePage/NodeQueryField.jsx +89 -0
- package/src/app/pages/AddEditNodePage/__tests__/FormikSelect.test.jsx +44 -0
- package/src/app/pages/AddEditNodePage/__tests__/FullNameField.test.jsx +29 -0
- package/src/app/pages/AddEditNodePage/__tests__/NodeQueryField.test.jsx +30 -0
- package/src/app/pages/AddEditNodePage/__tests__/__snapshots__/index.test.jsx.snap +84 -0
- package/src/app/pages/AddEditNodePage/__tests__/index.test.jsx +353 -0
- package/src/app/pages/AddEditNodePage/index.jsx +349 -0
- package/src/app/pages/LoginPage/assets/sign-in-with-github.png +0 -0
- package/src/app/pages/LoginPage/assets/sign-in-with-google.png +0 -0
- package/src/app/pages/LoginPage/index.jsx +90 -0
- package/src/app/pages/NamespacePage/__tests__/__snapshots__/index.test.tsx.snap +50 -2
- package/src/app/pages/NamespacePage/index.jsx +38 -9
- package/src/app/pages/NodePage/NodeGraphTab.jsx +1 -2
- package/src/app/pages/NodePage/NodeHistory.jsx +0 -1
- package/src/app/pages/NodePage/index.jsx +43 -26
- package/src/app/pages/Root/index.tsx +20 -3
- package/src/app/pages/SQLBuilderPage/index.jsx +54 -8
- package/src/app/services/DJService.js +180 -32
- package/src/setupTests.ts +1 -1
- package/src/styles/index.css +82 -5
- package/src/styles/login.css +67 -0
- package/src/styles/node-creation.scss +190 -0
- package/src/styles/styles.scss +44 -0
- package/src/styles/styles.scss.d.ts +9 -0
- package/webpack.config.js +11 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL query input field, which consists of a CodeMirror SQL editor with autocompletion
|
|
3
|
+
* (for node names and columns) and syntax highlighting.
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { Field, useFormikContext } from 'formik';
|
|
7
|
+
import CodeMirror from '@uiw/react-codemirror';
|
|
8
|
+
import { langs } from '@uiw/codemirror-extensions-langs';
|
|
9
|
+
|
|
10
|
+
export const NodeQueryField = ({ djClient, value }) => {
|
|
11
|
+
const [schema, setSchema] = React.useState([]);
|
|
12
|
+
const formik = useFormikContext();
|
|
13
|
+
const sqlExt = langs.sql({ schema: schema });
|
|
14
|
+
|
|
15
|
+
const initialAutocomplete = async context => {
|
|
16
|
+
// Based on the parsed prefix, we load node names with that prefix
|
|
17
|
+
// into the autocomplete schema. At this stage we don't load the columns
|
|
18
|
+
// to save on unnecessary calls
|
|
19
|
+
const word = context.matchBefore(/[\.\w]*/);
|
|
20
|
+
const matches = await djClient.nodes(word.text);
|
|
21
|
+
matches.forEach(nodeName => {
|
|
22
|
+
if (schema[nodeName] === undefined) {
|
|
23
|
+
schema[nodeName] = [];
|
|
24
|
+
setSchema(schema);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const updateFormik = val => {
|
|
30
|
+
formik.setFieldValue('query', val);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const updateAutocomplete = async (value, _) => {
|
|
34
|
+
// If a particular node has been chosen, load the columns of that node into
|
|
35
|
+
// the autocomplete schema for column-level autocompletion
|
|
36
|
+
for (var nodeName in schema) {
|
|
37
|
+
if (
|
|
38
|
+
value.includes(nodeName) &&
|
|
39
|
+
(!schema.hasOwnProperty(nodeName) ||
|
|
40
|
+
(schema.hasOwnProperty(nodeName) && schema[nodeName].length === 0))
|
|
41
|
+
) {
|
|
42
|
+
const nodeDetails = await djClient.node(nodeName);
|
|
43
|
+
schema[nodeName] = nodeDetails.columns.map(col => col.name);
|
|
44
|
+
setSchema(schema);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<Field
|
|
52
|
+
type="textarea"
|
|
53
|
+
style={{ display: 'none' }}
|
|
54
|
+
as="textarea"
|
|
55
|
+
name="query"
|
|
56
|
+
id="Query"
|
|
57
|
+
/>
|
|
58
|
+
<div role="button" tabIndex={0} className="relative flex bg-[#282a36]">
|
|
59
|
+
<CodeMirror
|
|
60
|
+
id={'query'}
|
|
61
|
+
name={'query'}
|
|
62
|
+
extensions={[
|
|
63
|
+
sqlExt,
|
|
64
|
+
sqlExt.language.data.of({
|
|
65
|
+
autocomplete: initialAutocomplete,
|
|
66
|
+
}),
|
|
67
|
+
]}
|
|
68
|
+
value={value}
|
|
69
|
+
options={{
|
|
70
|
+
theme: 'default',
|
|
71
|
+
lineNumbers: true,
|
|
72
|
+
}}
|
|
73
|
+
width="100%"
|
|
74
|
+
height="400px"
|
|
75
|
+
style={{
|
|
76
|
+
margin: '0 0 23px 0',
|
|
77
|
+
flex: 1,
|
|
78
|
+
fontSize: '150%',
|
|
79
|
+
textAlign: 'left',
|
|
80
|
+
}}
|
|
81
|
+
onChange={(value, viewUpdate) => {
|
|
82
|
+
updateFormik(value);
|
|
83
|
+
updateAutocomplete(value, viewUpdate);
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
</div>
|
|
87
|
+
</>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { Formik, Form } from 'formik';
|
|
5
|
+
import { FormikSelect } from '../FormikSelect';
|
|
6
|
+
|
|
7
|
+
describe('FormikSelect', () => {
|
|
8
|
+
const namespaces = [
|
|
9
|
+
{ value: 'default', label: 'default' },
|
|
10
|
+
{ value: 'basic', label: 'basic' },
|
|
11
|
+
{ value: 'basic.one', label: 'basic.one' },
|
|
12
|
+
{ value: 'basic.two', label: 'basic.two' },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const setup = () => {
|
|
16
|
+
const utils = render(
|
|
17
|
+
<Formik initialValues={{ selectedOption: '' }} onSubmit={jest.fn()}>
|
|
18
|
+
<Form>
|
|
19
|
+
<FormikSelect
|
|
20
|
+
selectOptions={namespaces}
|
|
21
|
+
formikFieldName="namespace"
|
|
22
|
+
placeholder="Choose Namespace"
|
|
23
|
+
defaultValue={{
|
|
24
|
+
value: 'basic.one',
|
|
25
|
+
label: 'basic.one',
|
|
26
|
+
}}
|
|
27
|
+
/>
|
|
28
|
+
</Form>
|
|
29
|
+
</Formik>,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const selectInput = screen.getByRole('combobox');
|
|
33
|
+
return {
|
|
34
|
+
...utils,
|
|
35
|
+
selectInput,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
it('renders the select component with provided options', () => {
|
|
40
|
+
setup();
|
|
41
|
+
userEvent.click(screen.getByRole('combobox')); // to open the dropdown
|
|
42
|
+
expect(screen.getByText('basic.one')).toBeInTheDocument();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { Formik, Form } from 'formik';
|
|
4
|
+
import { FullNameField } from '../FullNameField';
|
|
5
|
+
|
|
6
|
+
describe('FullNameField', () => {
|
|
7
|
+
const setup = initialValues => {
|
|
8
|
+
return render(
|
|
9
|
+
<Formik initialValues={initialValues} onSubmit={jest.fn()}>
|
|
10
|
+
<Form>
|
|
11
|
+
<FullNameField name="full_name" />
|
|
12
|
+
</Form>
|
|
13
|
+
</Formik>,
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
it('generates the full name based on namespace and display name', () => {
|
|
18
|
+
setup({ namespace: 'cats', display_name: 'Jasper the Cat' });
|
|
19
|
+
const fullNameInput = screen.getByRole('textbox');
|
|
20
|
+
expect(fullNameInput.value).toBe('cats.jasper_the_cat');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('does not set the full name if namespace or display name is missing', () => {
|
|
24
|
+
setup({ namespace: '', display_name: '' });
|
|
25
|
+
|
|
26
|
+
const fullNameInput = screen.getByRole('textbox');
|
|
27
|
+
expect(fullNameInput.value).toBe('');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { Formik, Form } from 'formik';
|
|
4
|
+
import { NodeQueryField } from '../NodeQueryField';
|
|
5
|
+
|
|
6
|
+
describe('NodeQueryField', () => {
|
|
7
|
+
const mockDjClient = {
|
|
8
|
+
nodes: jest.fn(),
|
|
9
|
+
node: jest.fn(),
|
|
10
|
+
};
|
|
11
|
+
const renderWithFormik = (djClient = mockDjClient) => {
|
|
12
|
+
return render(
|
|
13
|
+
<Formik initialValues={{ query: '' }} onSubmit={jest.fn()}>
|
|
14
|
+
<Form>
|
|
15
|
+
<NodeQueryField djClient={djClient} />
|
|
16
|
+
</Form>
|
|
17
|
+
</Formik>,
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
jest.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('renders without crashing', () => {
|
|
26
|
+
renderWithFormik();
|
|
27
|
+
expect(screen.getByRole('textbox')).toBeInTheDocument();
|
|
28
|
+
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`AddEditNodePage Create node page renders with the selected nodeType and namespace 1`] = `HTMLCollection []`;
|
|
4
|
+
|
|
5
|
+
exports[`AddEditNodePage Verify create node page form failed submission 1`] = `
|
|
6
|
+
HTMLCollection [
|
|
7
|
+
<div
|
|
8
|
+
class="message alert"
|
|
9
|
+
>
|
|
10
|
+
<svg
|
|
11
|
+
height="2em"
|
|
12
|
+
version="1.1"
|
|
13
|
+
viewBox="0 0 24 24"
|
|
14
|
+
width="2em"
|
|
15
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
16
|
+
>
|
|
17
|
+
<title>
|
|
18
|
+
alert_fill
|
|
19
|
+
</title>
|
|
20
|
+
<g
|
|
21
|
+
fill="none"
|
|
22
|
+
fill-rule="evenodd"
|
|
23
|
+
id="page-1"
|
|
24
|
+
stroke="none"
|
|
25
|
+
stroke-width="1"
|
|
26
|
+
>
|
|
27
|
+
<g
|
|
28
|
+
fill-rule="nonzero"
|
|
29
|
+
id="System"
|
|
30
|
+
transform="translate(-48.000000, -48.000000)"
|
|
31
|
+
>
|
|
32
|
+
<g
|
|
33
|
+
id="alert_fill"
|
|
34
|
+
transform="translate(48.000000, 48.000000)"
|
|
35
|
+
>
|
|
36
|
+
<path
|
|
37
|
+
d="M24,0 L24,24 L0,24 L0,0 L24,0 Z M12.5934901,23.257841 L12.5819402,23.2595131 L12.5108777,23.2950439 L12.4918791,23.2987469 L12.4918791,23.2987469 L12.4767152,23.2950439 L12.4056548,23.2595131 C12.3958229,23.2563662 12.3870493,23.2590235 12.3821421,23.2649074 L12.3780323,23.275831 L12.360941,23.7031097 L12.3658947,23.7234994 L12.3769048,23.7357139 L12.4804777,23.8096931 L12.4953491,23.8136134 L12.4953491,23.8136134 L12.5071152,23.8096931 L12.6106902,23.7357139 L12.6232938,23.7196733 L12.6232938,23.7196733 L12.6266527,23.7031097 L12.609561,23.275831 C12.6075724,23.2657013 12.6010112,23.2592993 12.5934901,23.257841 L12.5934901,23.257841 Z M12.8583906,23.1452862 L12.8445485,23.1473072 L12.6598443,23.2396597 L12.6498822,23.2499052 L12.6498822,23.2499052 L12.6471943,23.2611114 L12.6650943,23.6906389 L12.6699349,23.7034178 L12.6699349,23.7034178 L12.678386,23.7104931 L12.8793402,23.8032389 C12.8914285,23.8068999 12.9022333,23.8029875 12.9078286,23.7952264 L12.9118235,23.7811639 L12.8776777,23.1665331 C12.8752882,23.1545897 12.8674102,23.1470016 12.8583906,23.1452862 L12.8583906,23.1452862 Z M12.1430473,23.1473072 C12.1332178,23.1423925 12.1221763,23.1452606 12.1156365,23.1525954 L12.1099173,23.1665331 L12.0757714,23.7811639 C12.0751323,23.7926639 12.0828099,23.8018602 12.0926481,23.8045676 L12.108256,23.8032389 L12.3092106,23.7104931 L12.3186497,23.7024347 L12.3186497,23.7024347 L12.3225043,23.6906389 L12.340401,23.2611114 L12.337245,23.2485176 L12.337245,23.2485176 L12.3277531,23.2396597 L12.1430473,23.1473072 Z"
|
|
38
|
+
fill-rule="nonzero"
|
|
39
|
+
id="MingCute"
|
|
40
|
+
/>
|
|
41
|
+
<path
|
|
42
|
+
d="M13.299,3.1477 L21.933,18.1022 C22.5103,19.1022 21.7887,20.3522 20.634,20.3522 L3.36601,20.3522 C2.21131,20.3522 1.48962,19.1022 2.06697,18.1022 L10.7009,3.14771 C11.2783,2.14771 12.7217,2.1477 13.299,3.1477 Z M12,15 C11.4477,15 11,15.4477 11,16 C11,16.5523 11.4477,17 12,17 C12.5523,17 13,16.5523 13,16 C13,15.4477 12.5523,15 12,15 Z M12,8 C11.48715,8 11.0644908,8.38604429 11.0067275,8.88337975 L11,9 L11,13 C11,13.5523 11.4477,14 12,14 C12.51285,14 12.9355092,13.613973 12.9932725,13.1166239 L13,13 L13,9 C13,8.44772 12.5523,8 12,8 Z"
|
|
43
|
+
fill="#09244B"
|
|
44
|
+
id="shape"
|
|
45
|
+
/>
|
|
46
|
+
</g>
|
|
47
|
+
</g>
|
|
48
|
+
</g>
|
|
49
|
+
</svg>
|
|
50
|
+
Some columns in the primary key [] were not found
|
|
51
|
+
</div>,
|
|
52
|
+
]
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
exports[`AddEditNodePage Verify create node page user interaction and successful form submission 1`] = `
|
|
56
|
+
HTMLCollection [
|
|
57
|
+
<div
|
|
58
|
+
class="message success"
|
|
59
|
+
>
|
|
60
|
+
<svg
|
|
61
|
+
class="bi bi-check-circle-fill"
|
|
62
|
+
fill="currentColor"
|
|
63
|
+
height="25"
|
|
64
|
+
viewBox="0 0 16 16"
|
|
65
|
+
width="25"
|
|
66
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
67
|
+
>
|
|
68
|
+
<path
|
|
69
|
+
d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"
|
|
70
|
+
/>
|
|
71
|
+
</svg>
|
|
72
|
+
Successfully created
|
|
73
|
+
dimension
|
|
74
|
+
node
|
|
75
|
+
|
|
76
|
+
<a
|
|
77
|
+
href="/nodes/default.special_forces_contractors"
|
|
78
|
+
>
|
|
79
|
+
default.special_forces_contractors
|
|
80
|
+
</a>
|
|
81
|
+
!
|
|
82
|
+
</div>,
|
|
83
|
+
]
|
|
84
|
+
`;
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MemoryRouter, Route, Routes } from 'react-router-dom';
|
|
3
|
+
import { act, render, screen, waitFor } from '@testing-library/react';
|
|
4
|
+
import fetchMock from 'jest-fetch-mock';
|
|
5
|
+
import { AddEditNodePage } from '../index.jsx';
|
|
6
|
+
import DJClientContext from '../../../providers/djclient';
|
|
7
|
+
import userEvent from '@testing-library/user-event';
|
|
8
|
+
|
|
9
|
+
fetchMock.enableMocks();
|
|
10
|
+
|
|
11
|
+
describe('AddEditNodePage', () => {
|
|
12
|
+
const initializeMockDJClient = () => {
|
|
13
|
+
return {
|
|
14
|
+
DataJunctionAPI: {
|
|
15
|
+
namespace: _ => {
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
name: 'default.contractors',
|
|
19
|
+
display_name: 'Default: Contractors',
|
|
20
|
+
version: 'v1.0',
|
|
21
|
+
type: 'source',
|
|
22
|
+
status: 'valid',
|
|
23
|
+
mode: 'published',
|
|
24
|
+
updated_at: '2023-08-21T16:48:53.246914+00:00',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'default.num_repair_orders',
|
|
28
|
+
display_name: 'Default: Num Repair Orders',
|
|
29
|
+
version: 'v1.0',
|
|
30
|
+
type: 'metric',
|
|
31
|
+
status: 'valid',
|
|
32
|
+
mode: 'published',
|
|
33
|
+
updated_at: '2023-08-21T16:48:56.841704+00:00',
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
},
|
|
37
|
+
metrics: {},
|
|
38
|
+
namespaces: () => {
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
namespace: 'default',
|
|
42
|
+
num_nodes: 33,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
},
|
|
46
|
+
createNode: jest.fn(),
|
|
47
|
+
patchNode: jest.fn(),
|
|
48
|
+
node: jest.fn(),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const testElement = djClient => {
|
|
54
|
+
return (
|
|
55
|
+
<DJClientContext.Provider value={djClient}>
|
|
56
|
+
<AddEditNodePage />
|
|
57
|
+
</DJClientContext.Provider>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const mockMetricNode = {
|
|
62
|
+
namespace: 'default',
|
|
63
|
+
node_revision_id: 23,
|
|
64
|
+
node_id: 23,
|
|
65
|
+
type: 'metric',
|
|
66
|
+
name: 'default.num_repair_orders',
|
|
67
|
+
display_name: 'Default: Num Repair Orders',
|
|
68
|
+
version: 'v1.0',
|
|
69
|
+
status: 'valid',
|
|
70
|
+
mode: 'published',
|
|
71
|
+
catalog: {
|
|
72
|
+
id: 1,
|
|
73
|
+
uuid: '0fc18295-e1a2-4c3c-b72a-894725c12488',
|
|
74
|
+
created_at: '2023-08-21T16:48:51.146121+00:00',
|
|
75
|
+
updated_at: '2023-08-21T16:48:51.146122+00:00',
|
|
76
|
+
extra_params: {},
|
|
77
|
+
name: 'warehouse',
|
|
78
|
+
},
|
|
79
|
+
schema_: null,
|
|
80
|
+
table: null,
|
|
81
|
+
description: 'Number of repair orders',
|
|
82
|
+
query:
|
|
83
|
+
'SELECT count(repair_order_id) default_DOT_num_repair_orders FROM default.repair_orders',
|
|
84
|
+
availability: null,
|
|
85
|
+
columns: [
|
|
86
|
+
{
|
|
87
|
+
name: 'default_DOT_num_repair_orders',
|
|
88
|
+
type: 'bigint',
|
|
89
|
+
attributes: [],
|
|
90
|
+
dimension: null,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
updated_at: '2023-08-21T16:48:56.841704+00:00',
|
|
94
|
+
materializations: [],
|
|
95
|
+
parents: [
|
|
96
|
+
{
|
|
97
|
+
name: 'default.repair_orders',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
created_at: '2023-08-21T16:48:56.841631+00:00',
|
|
101
|
+
tags: [],
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
beforeEach(() => {
|
|
105
|
+
fetchMock.resetMocks();
|
|
106
|
+
jest.clearAllMocks();
|
|
107
|
+
window.scrollTo = jest.fn();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const renderCreateNode = element => {
|
|
111
|
+
return render(
|
|
112
|
+
<MemoryRouter initialEntries={['/create/dimension/default']}>
|
|
113
|
+
<Routes>
|
|
114
|
+
<Route path="create/:nodeType/:initialNamespace" element={element} />
|
|
115
|
+
</Routes>
|
|
116
|
+
</MemoryRouter>,
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const renderEditNode = element => {
|
|
121
|
+
return render(
|
|
122
|
+
<MemoryRouter initialEntries={['/nodes/default.num_repair_orders/edit']}>
|
|
123
|
+
<Routes>
|
|
124
|
+
<Route path="nodes/:name/edit" element={element} />
|
|
125
|
+
</Routes>
|
|
126
|
+
</MemoryRouter>,
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
it('Create node page renders with the selected nodeType and namespace', () => {
|
|
131
|
+
const mockDjClient = initializeMockDJClient();
|
|
132
|
+
const element = testElement(mockDjClient);
|
|
133
|
+
const { container } = renderCreateNode(element);
|
|
134
|
+
|
|
135
|
+
// The node type should be included in the page title
|
|
136
|
+
expect(
|
|
137
|
+
container.getElementsByClassName('node_type__metric'),
|
|
138
|
+
).toMatchSnapshot();
|
|
139
|
+
|
|
140
|
+
// The namespace should be set to the one provided in params
|
|
141
|
+
expect(screen.getByText('default')).toBeInTheDocument();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('Edit node page renders with the selected node', async () => {
|
|
145
|
+
const mockDjClient = initializeMockDJClient();
|
|
146
|
+
mockDjClient.DataJunctionAPI.node.mockReturnValue(mockMetricNode);
|
|
147
|
+
|
|
148
|
+
const element = testElement(mockDjClient);
|
|
149
|
+
renderEditNode(element);
|
|
150
|
+
|
|
151
|
+
await waitFor(() => {
|
|
152
|
+
// Should be an edit node page
|
|
153
|
+
expect(screen.getByText('Edit')).toBeInTheDocument();
|
|
154
|
+
|
|
155
|
+
// The node name should be loaded onto the page
|
|
156
|
+
expect(screen.getByText('default.num_repair_orders')).toBeInTheDocument();
|
|
157
|
+
|
|
158
|
+
// The node type should be loaded onto the page
|
|
159
|
+
expect(screen.getByText('metric')).toBeInTheDocument();
|
|
160
|
+
|
|
161
|
+
// The description should be populated
|
|
162
|
+
expect(screen.getByText('Number of repair orders')).toBeInTheDocument();
|
|
163
|
+
|
|
164
|
+
// The query should be populated
|
|
165
|
+
expect(
|
|
166
|
+
screen.getByText(
|
|
167
|
+
'SELECT count(repair_order_id) default_DOT_num_repair_orders FROM default.repair_orders',
|
|
168
|
+
),
|
|
169
|
+
).toBeInTheDocument();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('Verify create node page user interaction and successful form submission', async () => {
|
|
174
|
+
const mockDjClient = initializeMockDJClient();
|
|
175
|
+
mockDjClient.DataJunctionAPI.createNode.mockReturnValue({
|
|
176
|
+
status: 200,
|
|
177
|
+
json: { name: 'default.special_forces_contractors', type: 'dimension' },
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const element = testElement(mockDjClient);
|
|
181
|
+
const { container } = renderCreateNode(element);
|
|
182
|
+
|
|
183
|
+
const query =
|
|
184
|
+
'select \n' +
|
|
185
|
+
' C.contractor_id,\n' +
|
|
186
|
+
' C.address, C.contact_title, C.contact_name, C.city from default.contractors C \n' +
|
|
187
|
+
"where C.contact_title = 'special forces agent'";
|
|
188
|
+
|
|
189
|
+
// Fill in display name
|
|
190
|
+
await userEvent.type(
|
|
191
|
+
screen.getByLabelText('Display Name'),
|
|
192
|
+
'Special Forces Contractors',
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// After typing in a display name, the full name should be updated based on the display name
|
|
196
|
+
expect(
|
|
197
|
+
screen.getByDisplayValue('default.special_forces_contractors'),
|
|
198
|
+
).toBeInTheDocument();
|
|
199
|
+
|
|
200
|
+
// Fill in the rest of the fields and submit
|
|
201
|
+
await userEvent.type(screen.getByLabelText('Query'), query);
|
|
202
|
+
await userEvent.type(
|
|
203
|
+
screen.getByLabelText('Description'),
|
|
204
|
+
'A curated list of special forces contractors',
|
|
205
|
+
);
|
|
206
|
+
await userEvent.type(screen.getByLabelText('Primary Key'), 'contractor_id');
|
|
207
|
+
await userEvent.click(screen.getByText('Create dimension'));
|
|
208
|
+
|
|
209
|
+
await waitFor(() => {
|
|
210
|
+
expect(mockDjClient.DataJunctionAPI.createNode).toBeCalledTimes(1);
|
|
211
|
+
expect(mockDjClient.DataJunctionAPI.createNode).toBeCalledWith(
|
|
212
|
+
'dimension',
|
|
213
|
+
'default.special_forces_contractors',
|
|
214
|
+
'Special Forces Contractors',
|
|
215
|
+
'A curated list of special forces contractors',
|
|
216
|
+
query,
|
|
217
|
+
'draft',
|
|
218
|
+
'default',
|
|
219
|
+
['contractor_id'],
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// After successful creation, it should return a success message
|
|
224
|
+
expect(container.getElementsByClassName('success')).toMatchSnapshot();
|
|
225
|
+
}, 60000);
|
|
226
|
+
|
|
227
|
+
it('Verify create node page form failed submission', async () => {
|
|
228
|
+
const mockDjClient = initializeMockDJClient();
|
|
229
|
+
mockDjClient.DataJunctionAPI.createNode.mockReturnValue({
|
|
230
|
+
status: 500,
|
|
231
|
+
json: { message: 'Some columns in the primary key [] were not found' },
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const element = testElement(mockDjClient);
|
|
235
|
+
const { container } = renderCreateNode(element);
|
|
236
|
+
|
|
237
|
+
await userEvent.type(
|
|
238
|
+
screen.getByLabelText('Display Name'),
|
|
239
|
+
'Some Test Metric',
|
|
240
|
+
);
|
|
241
|
+
await userEvent.type(screen.getByLabelText('Query'), 'SELECT * FROM test');
|
|
242
|
+
await userEvent.click(screen.getByText('Create dimension'));
|
|
243
|
+
|
|
244
|
+
await waitFor(() => {
|
|
245
|
+
expect(mockDjClient.DataJunctionAPI.createNode).toBeCalledTimes(1);
|
|
246
|
+
expect(mockDjClient.DataJunctionAPI.createNode).toBeCalledWith(
|
|
247
|
+
'dimension',
|
|
248
|
+
'default.some_test_metric',
|
|
249
|
+
'Some Test Metric',
|
|
250
|
+
'',
|
|
251
|
+
'SELECT * FROM test',
|
|
252
|
+
'draft',
|
|
253
|
+
'default',
|
|
254
|
+
null,
|
|
255
|
+
);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// After failed creation, it should return a failure message
|
|
259
|
+
expect(container.getElementsByClassName('alert')).toMatchSnapshot();
|
|
260
|
+
}, 60000);
|
|
261
|
+
|
|
262
|
+
it('Verify edit node page form submission success', async () => {
|
|
263
|
+
const mockDjClient = initializeMockDJClient();
|
|
264
|
+
|
|
265
|
+
mockDjClient.DataJunctionAPI.node.mockReturnValue(mockMetricNode);
|
|
266
|
+
mockDjClient.DataJunctionAPI.patchNode = jest.fn();
|
|
267
|
+
mockDjClient.DataJunctionAPI.patchNode.mockReturnValue({
|
|
268
|
+
status: 201,
|
|
269
|
+
json: { name: 'default.num_repair_orders', type: 'metric' },
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
const element = testElement(mockDjClient);
|
|
273
|
+
renderEditNode(element);
|
|
274
|
+
|
|
275
|
+
await userEvent.type(await screen.getByLabelText('Display Name'), '!!!');
|
|
276
|
+
await userEvent.type(await screen.getByLabelText('Description'), '!!!');
|
|
277
|
+
await userEvent.click(await screen.getByText('Save'));
|
|
278
|
+
|
|
279
|
+
await waitFor(async () => {
|
|
280
|
+
expect(mockDjClient.DataJunctionAPI.patchNode).toBeCalledTimes(1);
|
|
281
|
+
expect(mockDjClient.DataJunctionAPI.patchNode).toBeCalledWith(
|
|
282
|
+
'default.num_repair_orders',
|
|
283
|
+
'Default: Num Repair Orders!!!',
|
|
284
|
+
'Number of repair orders!!!',
|
|
285
|
+
'SELECT count(repair_order_id) default_DOT_num_repair_orders FROM default.repair_orders',
|
|
286
|
+
'published',
|
|
287
|
+
null,
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
}, 60000);
|
|
291
|
+
|
|
292
|
+
it('Verify edit node page form submission failure displays alert', async () => {
|
|
293
|
+
const mockDjClient = initializeMockDJClient();
|
|
294
|
+
mockDjClient.DataJunctionAPI.node.mockReturnValue(mockMetricNode);
|
|
295
|
+
mockDjClient.DataJunctionAPI.patchNode.mockReturnValue({
|
|
296
|
+
status: 500,
|
|
297
|
+
json: { message: 'Update failed' },
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const element = testElement(mockDjClient);
|
|
301
|
+
renderEditNode(element);
|
|
302
|
+
|
|
303
|
+
await userEvent.type(await screen.getByLabelText('Display Name'), '!!!');
|
|
304
|
+
await userEvent.type(await screen.getByLabelText('Description'), '!!!');
|
|
305
|
+
await userEvent.click(await screen.getByText('Save'));
|
|
306
|
+
|
|
307
|
+
await waitFor(async () => {
|
|
308
|
+
expect(mockDjClient.DataJunctionAPI.patchNode).toBeCalledTimes(1);
|
|
309
|
+
expect(await screen.getByText('Update failed')).toBeInTheDocument();
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('Verify edit page node not found', async () => {
|
|
314
|
+
const mockDjClient = initializeMockDJClient();
|
|
315
|
+
mockDjClient.DataJunctionAPI.node = jest.fn();
|
|
316
|
+
mockDjClient.DataJunctionAPI.node.mockReturnValue({
|
|
317
|
+
message: 'A node with name `default.num_repair_orders` does not exist.',
|
|
318
|
+
errors: [],
|
|
319
|
+
warnings: [],
|
|
320
|
+
});
|
|
321
|
+
const element = testElement(mockDjClient);
|
|
322
|
+
renderEditNode(element);
|
|
323
|
+
|
|
324
|
+
await waitFor(() => {
|
|
325
|
+
expect(mockDjClient.DataJunctionAPI.node).toBeCalledTimes(1);
|
|
326
|
+
expect(
|
|
327
|
+
screen.getByText('Node default.num_repair_orders does not exist!'),
|
|
328
|
+
).toBeInTheDocument();
|
|
329
|
+
});
|
|
330
|
+
}, 60000);
|
|
331
|
+
|
|
332
|
+
it('Verify only transforms, metrics, and dimensions can be edited', async () => {
|
|
333
|
+
const mockDjClient = initializeMockDJClient();
|
|
334
|
+
mockDjClient.DataJunctionAPI.node = jest.fn();
|
|
335
|
+
mockDjClient.DataJunctionAPI.node.mockReturnValue({
|
|
336
|
+
namespace: 'default',
|
|
337
|
+
type: 'source',
|
|
338
|
+
name: 'default.repair_orders',
|
|
339
|
+
display_name: 'Default: Repair Orders',
|
|
340
|
+
});
|
|
341
|
+
const element = testElement(mockDjClient);
|
|
342
|
+
renderEditNode(element);
|
|
343
|
+
|
|
344
|
+
await waitFor(() => {
|
|
345
|
+
expect(mockDjClient.DataJunctionAPI.node).toBeCalledTimes(1);
|
|
346
|
+
expect(
|
|
347
|
+
screen.getByText(
|
|
348
|
+
'Node default.num_repair_orders is of type source and cannot be edited',
|
|
349
|
+
),
|
|
350
|
+
).toBeInTheDocument();
|
|
351
|
+
});
|
|
352
|
+
}, 60000);
|
|
353
|
+
});
|