-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
feat: add slackv2 notification #29264
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b1c40b6
add slackv2 notification
eschutho 3cb71fa
fix rate limiting
eschutho ef4581a
increase limit
eschutho 22968c3
display private channels
eschutho 1b98531
add more tests
eschutho 2225a94
add test
eschutho f7e4a1e
translate strings and improve tests
eschutho 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 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
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
183 changes: 183 additions & 0 deletions
183
superset-frontend/src/features/alerts/components/NotificationMethod.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,183 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { fireEvent, render, screen } from 'spec/helpers/testing-library'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { NotificationMethod, mapSlackValues } from './NotificationMethod'; | ||
import { NotificationMethodOption, NotificationSetting } from '../types'; | ||
|
||
const mockOnUpdate = jest.fn(); | ||
const mockOnRemove = jest.fn(); | ||
const mockOnInputChange = jest.fn(); | ||
const mockSetErrorSubject = jest.fn(); | ||
|
||
const mockSetting: NotificationSetting = { | ||
method: NotificationMethodOption.Email, | ||
recipients: 'test@example.com', | ||
options: [ | ||
NotificationMethodOption.Email, | ||
NotificationMethodOption.Slack, | ||
NotificationMethodOption.SlackV2, | ||
], | ||
}; | ||
|
||
const mockEmailSubject = 'Test Subject'; | ||
const mockDefaultSubject = 'Default Subject'; | ||
|
||
describe('NotificationMethod', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render the component', () => { | ||
render( | ||
<NotificationMethod | ||
setting={mockSetting} | ||
index={0} | ||
onUpdate={mockOnUpdate} | ||
onRemove={mockOnRemove} | ||
onInputChange={mockOnInputChange} | ||
email_subject={mockEmailSubject} | ||
defaultSubject={mockDefaultSubject} | ||
setErrorSubject={mockSetErrorSubject} | ||
/>, | ||
); | ||
|
||
expect(screen.getByText('Notification Method')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText('Email subject name (optional)'), | ||
).toBeInTheDocument(); | ||
expect(screen.getByText('Email recipients')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call onRemove when the delete button is clicked', () => { | ||
render( | ||
<NotificationMethod | ||
setting={mockSetting} | ||
index={1} | ||
onUpdate={mockOnUpdate} | ||
onRemove={mockOnRemove} | ||
onInputChange={mockOnInputChange} | ||
email_subject={mockEmailSubject} | ||
defaultSubject={mockDefaultSubject} | ||
setErrorSubject={mockSetErrorSubject} | ||
/>, | ||
); | ||
|
||
const deleteButton = screen.getByRole('button'); | ||
userEvent.click(deleteButton); | ||
|
||
expect(mockOnRemove).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
it('should update recipient value when input changes', () => { | ||
render( | ||
<NotificationMethod | ||
setting={mockSetting} | ||
index={0} | ||
onUpdate={mockOnUpdate} | ||
onRemove={mockOnRemove} | ||
onInputChange={mockOnInputChange} | ||
email_subject={mockEmailSubject} | ||
defaultSubject={mockDefaultSubject} | ||
setErrorSubject={mockSetErrorSubject} | ||
/>, | ||
); | ||
|
||
const recipientsInput = screen.getByTestId('recipients'); | ||
fireEvent.change(recipientsInput, { | ||
target: { value: 'test1@example.com' }, | ||
}); | ||
|
||
expect(mockOnUpdate).toHaveBeenCalledWith(0, { | ||
...mockSetting, | ||
recipients: 'test1@example.com', | ||
}); | ||
}); | ||
|
||
it('should call onRecipientsChange when the recipients value is changed', () => { | ||
render( | ||
<NotificationMethod | ||
setting={mockSetting} | ||
index={0} | ||
onUpdate={mockOnUpdate} | ||
onRemove={mockOnRemove} | ||
onInputChange={mockOnInputChange} | ||
email_subject={mockEmailSubject} | ||
defaultSubject={mockDefaultSubject} | ||
setErrorSubject={mockSetErrorSubject} | ||
/>, | ||
); | ||
|
||
const recipientsInput = screen.getByTestId('recipients'); | ||
fireEvent.change(recipientsInput, { | ||
target: { value: 'test1@example.com' }, | ||
}); | ||
|
||
expect(mockOnUpdate).toHaveBeenCalledWith(0, { | ||
...mockSetting, | ||
recipients: 'test1@example.com', | ||
}); | ||
}); | ||
|
||
it('should correctly map recipients when method is SlackV2', () => { | ||
const method = 'SlackV2'; | ||
const recipientValue = 'user1,user2'; | ||
const slackOptions: { label: string; value: string }[] = [ | ||
{ label: 'User One', value: 'user1' }, | ||
{ label: 'User Two', value: 'user2' }, | ||
]; | ||
|
||
const result = mapSlackValues({ method, recipientValue, slackOptions }); | ||
|
||
expect(result).toEqual([ | ||
{ label: 'User One', value: 'user1' }, | ||
{ label: 'User Two', value: 'user2' }, | ||
]); | ||
}); | ||
|
||
it('should return an empty array when recipientValue is an empty string', () => { | ||
const method = 'SlackV2'; | ||
const recipientValue = ''; | ||
const slackOptions: { label: string; value: string }[] = [ | ||
{ label: 'User One', value: 'user1' }, | ||
{ label: 'User Two', value: 'user2' }, | ||
]; | ||
|
||
const result = mapSlackValues({ method, recipientValue, slackOptions }); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should correctly map recipients when method is Slack with updated recipient values', () => { | ||
const method = 'Slack'; | ||
const recipientValue = 'User One,User Two'; | ||
const slackOptions: { label: string; value: string }[] = [ | ||
{ label: 'User One', value: 'user1' }, | ||
{ label: 'User Two', value: 'user2' }, | ||
]; | ||
|
||
const result = mapSlackValues({ method, recipientValue, slackOptions }); | ||
|
||
expect(result).toEqual([ | ||
{ label: 'User One', value: 'user1' }, | ||
{ label: 'User Two', value: 'user2' }, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.
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.
Can we use userEvent here instead and everywhere else?
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 can in two places, but it doesn't work in the others.