-
Notifications
You must be signed in to change notification settings - Fork 426
RI-7776 Fix cloud discovery search and notifications #5296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ArtemHoruzhenko
wants to merge
2
commits into
main
Choose a base branch
from
bugfix/RI-7776/fix-cloud-discovery-search-notifications
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+188
−34
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
200 changes: 173 additions & 27 deletions
200
...-cloud/redis-cloud-subscriptions/RedisCloudSubscriptions/RedisCloudSubscriptions.spec.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -1,46 +1,192 @@ | ||
| import React from 'react' | ||
| import { instance, mock } from 'ts-mockito' | ||
| import { faker } from '@faker-js/faker' | ||
| import { | ||
| RedisCloudSubscription, | ||
| RedisCloudSubscriptionStatus, | ||
| RedisCloudSubscriptionType, | ||
| } from 'uiSrc/slices/interfaces' | ||
| import { render } from 'uiSrc/utils/test-utils' | ||
| import { fireEvent, render, screen, waitFor } from 'uiSrc/utils/test-utils' | ||
| import RedisCloudSubscriptions, { Props } from './RedisCloudSubscriptions' | ||
|
|
||
| const mockedProps = mock<Props>() | ||
|
|
||
| const columnsMock = [ | ||
| { | ||
| id: 'name', | ||
| accessorKey: 'name', | ||
| header: 'Name', | ||
| enableSorting: true, | ||
| }, | ||
| { | ||
| id: 'id', | ||
| accessorKey: 'id', | ||
| header: 'Subscription ID', | ||
| enableSorting: true, | ||
| }, | ||
| ] | ||
|
|
||
| const createSubscription = ( | ||
| overrides?: Partial<RedisCloudSubscription>, | ||
| ): RedisCloudSubscription => ({ | ||
| id: faker.number.int(), | ||
| name: faker.company.name(), | ||
| numberOfDatabases: faker.number.int({ min: 1, max: 10 }), | ||
| provider: faker.helpers.arrayElement(['AWS', 'GCP', 'Azure']), | ||
| region: faker.helpers.arrayElement(['us-east-1', 'eu-west-1', 'ap-south-1']), | ||
| status: RedisCloudSubscriptionStatus.Active, | ||
| type: RedisCloudSubscriptionType.Fixed, | ||
| free: faker.datatype.boolean(), | ||
| ...overrides, | ||
| }) | ||
|
|
||
| describe('RedisCloudSubscriptions', () => { | ||
| const defaultProps: Partial<Props> = { | ||
| columns: columnsMock, | ||
| subscriptions: [], | ||
| selection: [], | ||
| loading: false, | ||
| account: null, | ||
| error: '', | ||
| onClose: jest.fn(), | ||
| onBack: jest.fn(), | ||
| onSubmit: jest.fn(), | ||
| onSelectionChange: jest.fn(), | ||
| } | ||
|
|
||
| const renderComponent = (propsOverride?: Partial<Props>) => { | ||
| const props = { ...defaultProps, ...propsOverride } as Props | ||
| return render( | ||
| <RedisCloudSubscriptions {...instance(mockedProps)} {...props} />, | ||
| ) | ||
| } | ||
|
|
||
| it('should render', () => { | ||
| const columnsMock = [ | ||
| { | ||
| id: 'subscriptionId', | ||
| accessorKey: 'subscriptionId', | ||
| header: 'Subscription ID', | ||
| enableSorting: true, | ||
| }, | ||
| ] | ||
| const subscriptionsMock: RedisCloudSubscription[] = [createSubscription()] | ||
| expect(renderComponent({ subscriptions: subscriptionsMock })).toBeTruthy() | ||
| }) | ||
|
|
||
| const subscriptionsMock: RedisCloudSubscription[] = [ | ||
| { | ||
| id: 123, | ||
| name: 'name', | ||
| numberOfDatabases: 123, | ||
| provider: 'provider', | ||
| region: 'region', | ||
| describe('search functionality', () => { | ||
| const subscriptions: RedisCloudSubscription[] = [ | ||
| createSubscription({ | ||
| id: 111, | ||
| name: 'Production Database', | ||
| provider: 'AWS', | ||
| region: 'us-east-1', | ||
| status: RedisCloudSubscriptionStatus.Active, | ||
| type: RedisCloudSubscriptionType.Flexible, | ||
| }), | ||
| createSubscription({ | ||
| id: 222, | ||
| name: 'Staging Environment', | ||
| provider: 'GCP', | ||
| region: 'eu-west-1', | ||
| status: RedisCloudSubscriptionStatus.Active, | ||
| type: RedisCloudSubscriptionType.Fixed, | ||
| free: false, | ||
| }, | ||
| }), | ||
| createSubscription({ | ||
| id: 333, | ||
| name: 'Development', | ||
| provider: 'Azure', | ||
| region: 'ap-south-1', | ||
| status: RedisCloudSubscriptionStatus.Error, | ||
| type: RedisCloudSubscriptionType.Fixed, | ||
| }), | ||
| ] | ||
| expect( | ||
| render( | ||
| <RedisCloudSubscriptions | ||
| {...instance(mockedProps)} | ||
| columns={columnsMock} | ||
| subscriptions={subscriptionsMock} | ||
| />, | ||
| ), | ||
| ).toBeTruthy() | ||
|
|
||
| it('should filter by name', async () => { | ||
| renderComponent({ subscriptions }) | ||
|
|
||
| const searchInput = screen.getByTestId('search') | ||
| fireEvent.change(searchInput, { target: { value: 'Production' } }) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Production Database')).toBeInTheDocument() | ||
| expect( | ||
| screen.queryByText('Staging Environment'), | ||
| ).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| it('should filter by id', async () => { | ||
| renderComponent({ subscriptions }) | ||
|
|
||
| const searchInput = screen.getByTestId('search') | ||
| fireEvent.change(searchInput, { target: { value: '222' } }) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Staging Environment')).toBeInTheDocument() | ||
| expect( | ||
| screen.queryByText('Production Database'), | ||
| ).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| it('should filter by provider', async () => { | ||
| renderComponent({ subscriptions }) | ||
|
|
||
| const searchInput = screen.getByTestId('search') | ||
| fireEvent.change(searchInput, { target: { value: 'AWS' } }) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Production Database')).toBeInTheDocument() | ||
| expect( | ||
| screen.queryByText('Staging Environment'), | ||
| ).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| it('should filter by region', async () => { | ||
| renderComponent({ subscriptions }) | ||
|
|
||
| const searchInput = screen.getByTestId('search') | ||
| fireEvent.change(searchInput, { target: { value: 'eu-west' } }) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Staging Environment')).toBeInTheDocument() | ||
| expect( | ||
| screen.queryByText('Production Database'), | ||
| ).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| it('should filter by status', async () => { | ||
| renderComponent({ subscriptions }) | ||
|
|
||
| const searchInput = screen.getByTestId('search') | ||
| fireEvent.change(searchInput, { target: { value: 'error' } }) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Development')).toBeInTheDocument() | ||
| expect( | ||
| screen.queryByText('Production Database'), | ||
| ).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| it('should filter by type', async () => { | ||
| renderComponent({ subscriptions }) | ||
|
|
||
| const searchInput = screen.getByTestId('search') | ||
| fireEvent.change(searchInput, { target: { value: 'flexible' } }) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Production Database')).toBeInTheDocument() | ||
| expect( | ||
| screen.queryByText('Staging Environment'), | ||
| ).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| it('should be case-insensitive', async () => { | ||
| renderComponent({ subscriptions }) | ||
|
|
||
| const searchInput = screen.getByTestId('search') | ||
| fireEvent.change(searchInput, { target: { value: 'PRODUCTION' } }) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Production Database')).toBeInTheDocument() | ||
| }) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering can't we add such util:
and then this syntax would be easier to be read and moreover we have it in the
RedisCloudDatabasesResult.tsxas well.Maybe not for this PR, but actually, why not 😸