-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle negative credit in UI (#10814)
* Handle create connection feature * Handle sync feature * Add create and sync connection features to service * Add unit tests * Add allowSync property to deps Co-authored-by: Artem Astapenko <[email protected]>
- Loading branch information
1 parent
39107bf
commit df6c8c7
Showing
13 changed files
with
212 additions
and
24 deletions.
There are no files selected for viewing
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
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
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
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
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
93 changes: 93 additions & 0 deletions
93
airbyte-webapp/src/hooks/services/Feature/FeatureService.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,93 @@ | ||
import React from "react"; | ||
import { act, renderHook } from "@testing-library/react-hooks"; | ||
import { | ||
FeatureService, | ||
useFeatureRegisterValues, | ||
useFeatureService, | ||
} from "./FeatureService"; | ||
import { FeatureItem } from "./types"; | ||
import { TestWrapper } from "utils/testutils"; | ||
import { ConfigContext, configContext } from "config"; | ||
|
||
const predefinedFeatures = [ | ||
{ | ||
id: FeatureItem.AllowCustomDBT, | ||
}, | ||
]; | ||
|
||
const wrapper: React.FC = ({ children }) => ( | ||
<TestWrapper> | ||
<configContext.Provider | ||
value={ | ||
({ | ||
config: { features: predefinedFeatures }, | ||
} as unknown) as ConfigContext | ||
} | ||
> | ||
<FeatureService>{children}</FeatureService> | ||
</configContext.Provider> | ||
</TestWrapper> | ||
); | ||
|
||
describe("FeatureService", () => { | ||
test("should register and unregister features", async () => { | ||
const { result } = renderHook(() => useFeatureService(), { | ||
wrapper, | ||
}); | ||
|
||
expect(result.current.features).toEqual(predefinedFeatures); | ||
|
||
act(() => { | ||
result.current.registerFeature([ | ||
{ | ||
id: FeatureItem.AllowCreateConnection, | ||
}, | ||
]); | ||
}); | ||
|
||
expect(result.current.features).toEqual([ | ||
...predefinedFeatures, | ||
{ | ||
id: FeatureItem.AllowCreateConnection, | ||
}, | ||
]); | ||
|
||
act(() => { | ||
result.current.unregisterFeature([FeatureItem.AllowCreateConnection]); | ||
}); | ||
|
||
expect(result.current.features).toEqual(predefinedFeatures); | ||
}); | ||
}); | ||
|
||
describe("useFeatureRegisterValues", () => { | ||
test("should register more than 1 feature", async () => { | ||
const { result } = renderHook( | ||
() => { | ||
useFeatureRegisterValues([{ id: FeatureItem.AllowCreateConnection }]); | ||
useFeatureRegisterValues([{ id: FeatureItem.AllowSync }]); | ||
|
||
return useFeatureService(); | ||
}, | ||
{ | ||
initialProps: { initialValue: 0 }, | ||
wrapper, | ||
} | ||
); | ||
|
||
expect(result.current.features).toEqual([ | ||
...predefinedFeatures, | ||
{ id: FeatureItem.AllowCreateConnection }, | ||
{ id: FeatureItem.AllowSync }, | ||
]); | ||
|
||
act(() => { | ||
result.current.unregisterFeature([FeatureItem.AllowCreateConnection]); | ||
}); | ||
|
||
expect(result.current.features).toEqual([ | ||
...predefinedFeatures, | ||
{ id: FeatureItem.AllowSync }, | ||
]); | ||
}); | ||
}); |
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
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
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
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
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
Oops, something went wrong.