-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Krishna (kc) Glick <krishnaglick@users.noreply.github.com>
- Loading branch information
1 parent
7696f85
commit 724c8c8
Showing
4 changed files
with
265 additions
and
33 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
airbyte-webapp/src/components/connection/CatalogTree/next/CatalogTreeTableRow.test.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
242 changes: 242 additions & 0 deletions
242
airbyte-webapp/src/components/connection/CatalogTree/next/useCatalogTreeRowProps.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
import classNames from "classnames"; | ||
import * as formik from "formik"; | ||
|
||
import { AirbyteStreamAndConfiguration } from "core/request/AirbyteClient"; | ||
import * as bulkEditService from "hooks/services/BulkEdit/BulkEditService"; | ||
import * as connectionFormService from "hooks/services/ConnectionForm/ConnectionFormService"; | ||
import { FormikConnectionFormValues } from "views/Connection/ConnectionForm/formConfig"; | ||
|
||
// eslint-disable-next-line css-modules/no-unused-class | ||
import styles from "./CatalogTreeTableRow.module.scss"; | ||
import { useCatalogTreeRowProps } from "./useCatalogTreeRowProps"; | ||
|
||
const mockStream: Partial<AirbyteStreamAndConfiguration> = { | ||
stream: { | ||
name: "stream_name", | ||
namespace: "stream_namespace", | ||
}, | ||
config: { selected: true, syncMode: "full_refresh", destinationSyncMode: "overwrite" }, | ||
}; | ||
|
||
const mockInitialValues: Partial<FormikConnectionFormValues> = { | ||
syncCatalog: { | ||
streams: [ | ||
{ | ||
stream: { | ||
name: "stream_name", | ||
namespace: "stream_namespace", | ||
}, | ||
config: { selected: true, syncMode: "full_refresh", destinationSyncMode: "overwrite" }, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
describe("<CatalogTreeTableRow />", () => { | ||
it("should return default styles for a row that starts enabled", () => { | ||
// eslint-disable-next-line | ||
jest.spyOn(bulkEditService, "useBulkEditSelect").mockImplementation(() => [false, () => null] as any); // not selected for bulk edit | ||
jest.spyOn(connectionFormService, "useConnectionFormService").mockImplementation(() => { | ||
// eslint-disable-next-line | ||
return { initialValues: mockInitialValues } as any; | ||
}); | ||
jest.spyOn(formik, "useField").mockImplementationOnce(() => { | ||
// eslint-disable-next-line | ||
return [{}, { error: undefined }] as any; // no error | ||
}); | ||
|
||
const { result } = renderHook(() => useCatalogTreeRowProps(mockStream)); | ||
|
||
expect(result.current.streamHeaderContentStyle).toEqual(classNames(styles.streamHeaderContent)); | ||
expect(result.current.statusIcon).toEqual(null); | ||
expect(result.current.pillButtonVariant).toEqual("grey"); | ||
}); | ||
it("should return disabled styles for a row that starts disabled", () => { | ||
// eslint-disable-next-line | ||
jest.spyOn(bulkEditService, "useBulkEditSelect").mockImplementation(() => [false, () => null] as any); // not selected for bulk edit | ||
jest.spyOn(connectionFormService, "useConnectionFormService").mockImplementation(() => { | ||
return { | ||
initialValues: { | ||
syncCatalog: { | ||
streams: [ | ||
{ | ||
...mockInitialValues.syncCatalog?.streams[0], | ||
config: { ...mockInitialValues.syncCatalog?.streams[0].config, selected: false }, | ||
}, | ||
], | ||
}, | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any; | ||
}); | ||
jest.spyOn(formik, "useField").mockImplementationOnce(() => { | ||
// eslint-disable-next-line | ||
return [{}, { error: undefined }] as any; // no error | ||
}); | ||
const { result } = renderHook(() => | ||
useCatalogTreeRowProps({ | ||
...mockStream, | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
config: { ...mockStream.config!, selected: false }, | ||
}) | ||
); | ||
|
||
expect(result.current.streamHeaderContentStyle).toEqual(classNames(styles.streamHeaderContent, styles.disabled)); | ||
expect(result.current.statusIcon).toEqual(null); | ||
expect(result.current.pillButtonVariant).toEqual("grey"); | ||
}); | ||
it("should return added styles for a row that is added", () => { | ||
// eslint-disable-next-line | ||
jest.spyOn(bulkEditService, "useBulkEditSelect").mockImplementation(() => [false, () => null] as any); // not selected for bulk edit | ||
jest.spyOn(connectionFormService, "useConnectionFormService").mockImplementation(() => { | ||
return { | ||
initialValues: { | ||
syncCatalog: { | ||
streams: [ | ||
{ | ||
...mockInitialValues.syncCatalog?.streams[0], | ||
config: { ...mockInitialValues.syncCatalog?.streams[0].config, selected: false }, | ||
}, | ||
], | ||
}, | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any; | ||
}); | ||
jest.spyOn(formik, "useField").mockImplementationOnce(() => { | ||
// eslint-disable-next-line | ||
return [{}, { error: undefined }] as any; // no error | ||
}); | ||
const { result } = renderHook(() => | ||
useCatalogTreeRowProps({ | ||
...mockStream, | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
config: { ...mockStream.config!, selected: true }, // selected true | ||
}) | ||
); | ||
|
||
expect(result.current.streamHeaderContentStyle).toEqual(classNames(styles.streamHeaderContent, styles.added)); | ||
// expect(result.current.statusIcon).(); TODO: jest is weird at comparing react nodes | ||
expect(result.current.pillButtonVariant).toEqual("green"); | ||
}); | ||
it("should return removed styles for a row that is removed", () => { | ||
// eslint-disable-next-line | ||
jest.spyOn(bulkEditService, "useBulkEditSelect").mockImplementation(() => [false, () => null] as any); // not selected for bulk edit | ||
jest.spyOn(connectionFormService, "useConnectionFormService").mockImplementation(() => { | ||
return { | ||
initialValues: { ...mockInitialValues }, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any; | ||
}); | ||
jest.spyOn(formik, "useField").mockImplementationOnce(() => { | ||
// eslint-disable-next-line | ||
return [{}, { error: undefined }] as any; // no error | ||
}); | ||
const { result } = renderHook(() => | ||
useCatalogTreeRowProps({ | ||
...mockStream, | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
config: { ...mockStream.config!, selected: false }, // selected false | ||
}) | ||
); | ||
|
||
expect(result.current.streamHeaderContentStyle).toEqual(classNames(styles.streamHeaderContent, styles.removed)); | ||
// expect(result.current.statusIcon).(); TODO: jest is weird at comparing react nodes | ||
expect(result.current.pillButtonVariant).toEqual("red"); | ||
}); | ||
it("should return updated styles for a row that is updated", () => { | ||
// eslint-disable-next-line | ||
jest.spyOn(bulkEditService, "useBulkEditSelect").mockImplementation(() => [false, () => null] as any); // not selected for bulk edit | ||
// todo: i'm only changing config.selected... this can be cleaned up with a spread operator and the mockInitialValues | ||
jest.spyOn(connectionFormService, "useConnectionFormService").mockImplementation(() => { | ||
return { | ||
initialValues: { ...mockInitialValues }, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any; | ||
}); | ||
jest.spyOn(formik, "useField").mockImplementationOnce(() => { | ||
// eslint-disable-next-line | ||
return [{}, { error: undefined }] as any; // no error | ||
}); | ||
const { result } = renderHook(() => | ||
useCatalogTreeRowProps({ | ||
...mockStream, | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
config: { ...mockStream.config!, syncMode: "incremental", destinationSyncMode: "append_dedup" }, // new sync mode and destination sync mode | ||
}) | ||
); | ||
|
||
expect(result.current.streamHeaderContentStyle).toEqual(classNames(styles.streamHeaderContent, styles.changed)); | ||
// expect(result.current.statusIcon).(); TODO: jest is weird at comparing react nodes | ||
expect(result.current.pillButtonVariant).toEqual("blue"); | ||
}); | ||
it("should return added styles for a row that is both added and updated", () => { | ||
// eslint-disable-next-line | ||
jest.spyOn(bulkEditService, "useBulkEditSelect").mockImplementation(() => [false, () => null] as any); // not selected for bulk edit | ||
// todo: i'm only changing config.selected... this can be cleaned up with a spread operator and the mockInitialValues | ||
jest.spyOn(connectionFormService, "useConnectionFormService").mockImplementation(() => { | ||
return { | ||
initialValues: { | ||
syncCatalog: { | ||
streams: [ | ||
{ | ||
...mockInitialValues.syncCatalog?.streams[0], | ||
config: { ...mockInitialValues.syncCatalog?.streams[0].config, selected: false }, | ||
}, | ||
], | ||
}, | ||
}, // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any; | ||
}); | ||
jest.spyOn(formik, "useField").mockImplementationOnce(() => { | ||
// eslint-disable-next-line | ||
return [{}, { error: undefined }] as any; // no error | ||
}); | ||
const { result } = renderHook(() => | ||
useCatalogTreeRowProps({ | ||
...mockStream, | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
config: { selected: true, syncMode: "incremental", destinationSyncMode: "append_dedup" }, // selected true, new sync, mode and destination sync mode | ||
}) | ||
); | ||
|
||
expect(result.current.streamHeaderContentStyle).toEqual(classNames(styles.streamHeaderContent, styles.added)); | ||
// expect(result.current.statusIcon).(); TODO: jest is weird at comparing react nodes | ||
expect(result.current.pillButtonVariant).toEqual("green"); | ||
}); | ||
it("should return change background color with relevant icon if selected for bulk edit", () => { | ||
// eslint-disable-next-line | ||
jest.spyOn(bulkEditService, "useBulkEditSelect").mockImplementation(() => [true, () => null] as any); // not selected for bulk edit | ||
jest.spyOn(connectionFormService, "useConnectionFormService").mockImplementation(() => { | ||
// eslint-disable-next-line | ||
return { initialValues: mockInitialValues } as any; | ||
}); | ||
jest.spyOn(formik, "useField").mockImplementationOnce(() => { | ||
// eslint-disable-next-line | ||
return [{}, { error: undefined }] as any; // no error | ||
}); | ||
|
||
const { result } = renderHook(() => useCatalogTreeRowProps(mockStream)); | ||
|
||
expect(result.current.streamHeaderContentStyle).toEqual(classNames(styles.streamHeaderContent, styles.changed)); | ||
// expect(result.current.statusIcon).(); TODO: jest is weird at comparing react nodes | ||
expect(result.current.pillButtonVariant).toEqual("blue"); | ||
}); | ||
it("should return error styles for a row that has an error", () => { | ||
// eslint-disable-next-line | ||
jest.spyOn(bulkEditService, "useBulkEditSelect").mockImplementation(() => [false, () => null] as any); // not selected for bulk edit | ||
jest.spyOn(connectionFormService, "useConnectionFormService").mockImplementation(() => { | ||
// eslint-disable-next-line | ||
return { initialValues: mockInitialValues } as any; | ||
}); | ||
jest.spyOn(formik, "useField").mockImplementationOnce(() => { | ||
// eslint-disable-next-line | ||
return [{}, { error: true }] as any; // no error | ||
}); | ||
|
||
const { result } = renderHook(() => useCatalogTreeRowProps(mockStream)); | ||
|
||
expect(result.current.streamHeaderContentStyle).toEqual(classNames(styles.streamHeaderContent, styles.error)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters