datajunction-ui 0.0.1-a44.dev5 → 0.0.1-a45.dev14

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.
@@ -1,55 +0,0 @@
1
- import DJClientContext from '../providers/djclient';
2
- import * as React from 'react';
3
- import DeleteIcon from '../icons/DeleteIcon';
4
- import { Form, Formik } from 'formik';
5
- import { useContext } from 'react';
6
- import { displayMessageAfterSubmit } from '../../utils/form';
7
-
8
- export default function DeleteNode({ nodeName }) {
9
- const djClient = useContext(DJClientContext).DataJunctionAPI;
10
- const deleteNode = async (values, { setSubmitting, setStatus }) => {
11
- const { status, json } = await djClient.deactivate(values.nodeName);
12
- if (status === 200 || status === 201 || status === 204) {
13
- setStatus({
14
- success: <>Successfully deleted node {values.nodeName}</>,
15
- });
16
- } else {
17
- setStatus({
18
- failure: `${json.message}`,
19
- });
20
- }
21
- setSubmitting(false);
22
- };
23
-
24
- const initialValues = {
25
- nodeName: nodeName,
26
- };
27
-
28
- return (
29
- <Formik initialValues={initialValues} onSubmit={deleteNode}>
30
- {function Render({ isSubmitting, status, setFieldValue }) {
31
- return (
32
- <Form className="deleteNode">
33
- {displayMessageAfterSubmit(status)}
34
- {
35
- <>
36
- <button
37
- type="submit"
38
- disabled={isSubmitting}
39
- style={{
40
- marginLeft: 0,
41
- all: 'unset',
42
- color: '#005c72',
43
- cursor: 'pointer',
44
- }}
45
- >
46
- <DeleteIcon />
47
- </button>
48
- </>
49
- }
50
- </Form>
51
- );
52
- }}
53
- </Formik>
54
- );
55
- }
@@ -1,53 +0,0 @@
1
- import React from 'react';
2
- import { screen, waitFor } from '@testing-library/react';
3
- import fetchMock from 'jest-fetch-mock';
4
- import userEvent from '@testing-library/user-event';
5
- import { render } from '../../../setupTests';
6
- import DJClientContext from '../../providers/djclient';
7
- import DeleteNode from '../DeleteNode';
8
-
9
- describe('<DeleteNode />', () => {
10
- beforeEach(() => {
11
- fetchMock.resetMocks();
12
- jest.clearAllMocks();
13
- window.scrollTo = jest.fn();
14
- });
15
-
16
- const renderElement = djClient => {
17
- return render(
18
- <DJClientContext.Provider value={djClient}>
19
- <DeleteNode nodeName="default.hard_hat" />
20
- </DJClientContext.Provider>,
21
- );
22
- };
23
-
24
- const initializeMockDJClient = () => {
25
- return {
26
- DataJunctionAPI: {
27
- deactivate: jest.fn(),
28
- },
29
- };
30
- };
31
-
32
- it('deletes a node when clicked', async () => {
33
- const mockDjClient = initializeMockDJClient();
34
- mockDjClient.DataJunctionAPI.deactivate.mockReturnValue({
35
- status: 204,
36
- json: { name: 'source.warehouse.schema.some_table' },
37
- });
38
-
39
- renderElement(mockDjClient);
40
-
41
- await userEvent.click(screen.getByRole('button'));
42
-
43
- await waitFor(() => {
44
- expect(mockDjClient.DataJunctionAPI.deactivate).toBeCalled();
45
- expect(mockDjClient.DataJunctionAPI.deactivate).toBeCalledWith(
46
- 'default.hard_hat',
47
- );
48
- });
49
- expect(
50
- screen.getByText('Successfully deleted node default.hard_hat'),
51
- ).toBeInTheDocument();
52
- }, 60000);
53
- });