Skip to content

Commit de4c631

Browse files
committed
#RI-4936 - fix tests
1 parent 767bd3a commit de4c631

File tree

3 files changed

+70
-15
lines changed

3 files changed

+70
-15
lines changed

redisinsight/ui/src/components/notifications/components/infinite-messages/InfiniteMessages.spec.tsx

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,70 @@ describe('INFINITE_MESSAGES', () => {
2424
})
2525
describe('PENDING_CREATE_DB', () => {
2626
it('should render message', () => {
27-
const { Inner } = INFINITE_MESSAGES.PENDING_CREATE_DB
27+
const { Inner } = INFINITE_MESSAGES.PENDING_CREATE_DB()
2828
expect(render(<>{Inner}</>)).toBeTruthy()
2929
})
3030
})
31+
describe('DATABASE_EXISTS', () => {
32+
it('should render message', () => {
33+
const { Inner } = INFINITE_MESSAGES.DATABASE_EXISTS(jest.fn())
34+
expect(render(<>{Inner}</>)).toBeTruthy()
35+
})
36+
37+
it('should call onSuccess', () => {
38+
const onSuccess = jest.fn()
39+
const { Inner } = INFINITE_MESSAGES.DATABASE_EXISTS(onSuccess)
40+
render(<>{Inner}</>)
41+
42+
fireEvent.click(screen.getByTestId('import-db-sso-btn'))
43+
fireEvent.mouseUp(screen.getByTestId('database-exists-notification'))
44+
fireEvent.mouseDown(screen.getByTestId('database-exists-notification'))
45+
46+
expect(onSuccess).toBeCalled()
47+
})
48+
49+
it('should call onCancel', () => {
50+
const onSuccess = jest.fn()
51+
const onCancel = jest.fn()
52+
const { Inner } = INFINITE_MESSAGES.DATABASE_EXISTS(onSuccess, onCancel)
53+
render(<>{Inner}</>)
54+
55+
fireEvent.click(screen.getByTestId('cancel-import-db-sso-btn'))
56+
fireEvent.mouseUp(screen.getByTestId('database-exists-notification'))
57+
fireEvent.mouseDown(screen.getByTestId('database-exists-notification'))
58+
59+
expect(onCancel).toBeCalled()
60+
})
61+
})
62+
describe('SUBSCRIPTION_EXISTS', () => {
63+
it('should render message', () => {
64+
const { Inner } = INFINITE_MESSAGES.SUBSCRIPTION_EXISTS(jest.fn())
65+
expect(render(<>{Inner}</>)).toBeTruthy()
66+
})
67+
68+
it('should call onSuccess', () => {
69+
const onSuccess = jest.fn()
70+
const { Inner } = INFINITE_MESSAGES.SUBSCRIPTION_EXISTS(onSuccess)
71+
render(<>{Inner}</>)
72+
73+
fireEvent.click(screen.getByTestId('create-subscription-sso-btn'))
74+
fireEvent.mouseUp(screen.getByTestId('subscription-exists-notification'))
75+
fireEvent.mouseDown(screen.getByTestId('subscription-exists-notification'))
76+
77+
expect(onSuccess).toBeCalled()
78+
})
79+
80+
it('should call onCancel', () => {
81+
const onSuccess = jest.fn()
82+
const onCancel = jest.fn()
83+
const { Inner } = INFINITE_MESSAGES.SUBSCRIPTION_EXISTS(onSuccess, onCancel)
84+
render(<>{Inner}</>)
85+
86+
fireEvent.click(screen.getByTestId('cancel-create-subscription-sso-btn'))
87+
fireEvent.mouseUp(screen.getByTestId('subscription-exists-notification'))
88+
fireEvent.mouseDown(screen.getByTestId('subscription-exists-notification'))
89+
90+
expect(onCancel).toBeCalled()
91+
})
92+
})
3193
})

redisinsight/ui/src/slices/oauth/cloud.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ export const initialState: StateAppOAuth = {
4343
name: CloudJobName.CreateFreeSubscriptionAndDatabase,
4444
status: '',
4545
},
46-
// job: {
47-
// id: localStorageService.get(BrowserStorageItem.OAuthJobId) ?? '',
48-
// name: CloudJobName.CreateFreeSubscriptionAndDatabase,
49-
// status: CloudJobStatus.Failed,
50-
// error: {
51-
// errorCode: CustomErrorCodes.CloudSubscriptionAlreadyExistsFree,
52-
// resource: {
53-
// subscriptionId: 123
54-
// }
55-
// }
56-
// },
5746
source: null,
5847
agreement: localStorageService.get(BrowserStorageItem.OAuthAgreement) ?? false,
5948
isOpenSocialDialog: false,

redisinsight/ui/src/slices/tests/oauth/cloud.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -886,14 +886,18 @@ describe('oauth cloud slice', () => {
886886
describe('createFreeDb', () => {
887887
it('call both addFreeDb and setJob when post is successed', async () => {
888888
// Arrange
889-
const data = { id: '123123', name: CloudJobName.CreateFreeDatabase, status: CloudJobStatus.Running }
889+
const data = {
890+
id: '123123',
891+
name: CloudJobName.CreateFreeSubscriptionAndDatabase,
892+
status: CloudJobStatus.Running,
893+
}
890894
const responsePayload = { data, status: 200 }
891895

892896
apiService.post = jest.fn().mockResolvedValue(responsePayload)
893897
apiService.get = jest.fn().mockResolvedValue(responsePayload)
894898

895899
// Act
896-
await store.dispatch<any>(createFreeDbJob())
900+
await store.dispatch<any>(createFreeDbJob({ name: CloudJobName.CreateFreeSubscriptionAndDatabase }))
897901

898902
// Assert
899903
const expectedActions = [
@@ -916,7 +920,7 @@ describe('oauth cloud slice', () => {
916920
apiService.post = jest.fn().mockRejectedValueOnce(responsePayload)
917921

918922
// Act
919-
await store.dispatch<any>(createFreeDbJob())
923+
await store.dispatch<any>(createFreeDbJob({ name: CloudJobName.CreateFreeSubscriptionAndDatabase }))
920924

921925
// Assert
922926
const expectedActions = [

0 commit comments

Comments
 (0)