diff --git a/superset-frontend/src/features/alerts/components/NotificationMethod.test.tsx b/superset-frontend/src/features/alerts/components/NotificationMethod.test.tsx index f0c22cfccb246..4b4e46c69e272 100644 --- a/superset-frontend/src/features/alerts/components/NotificationMethod.test.tsx +++ b/superset-frontend/src/features/alerts/components/NotificationMethod.test.tsx @@ -16,7 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -import { render, screen, fireEvent } from 'spec/helpers/testing-library'; +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'; @@ -79,11 +81,10 @@ describe('NotificationMethod', () => { ); const deleteButton = screen.getByRole('button'); - fireEvent.click(deleteButton); + userEvent.click(deleteButton); expect(mockOnRemove).toHaveBeenCalledWith(1); }); - // Should update recipient value when input changes. it('should update recipient value when input changes', () => { render( @@ -134,7 +135,7 @@ describe('NotificationMethod', () => { recipients: 'test1@example.com', }); }); - // correctly maps recipients when method is SlackV2 + it('should correctly map recipients when method is SlackV2', () => { const method = 'SlackV2'; const recipientValue = 'user1,user2'; @@ -150,7 +151,7 @@ describe('NotificationMethod', () => { { label: 'User Two', value: 'user2' }, ]); }); - // handles empty recipientValue string + it('should return an empty array when recipientValue is an empty string', () => { const method = 'SlackV2'; const recipientValue = ''; @@ -163,7 +164,7 @@ describe('NotificationMethod', () => { expect(result).toEqual([]); }); - // Ensure that the mapSlackValues function correctly maps recipients when the method is Slack with updated recipient values + it('should correctly map recipients when method is Slack with updated recipient values', () => { const method = 'Slack'; const recipientValue = 'User One,User Two'; diff --git a/superset-frontend/src/features/alerts/components/NotificationMethod.tsx b/superset-frontend/src/features/alerts/components/NotificationMethod.tsx index 92ef454d076e2..85e26f777ab2a 100644 --- a/superset-frontend/src/features/alerts/components/NotificationMethod.tsx +++ b/superset-frontend/src/features/alerts/components/NotificationMethod.tsx @@ -130,7 +130,7 @@ export const mapChannelsToOptions = (result: SlackChannel[]) => { label: 'Public Channels', options: publicChannels.map((channel: SlackChannel) => ({ label: `${channel.name} ${ - channel.is_member ? '' : '(Bot not in channel)' + channel.is_member ? '' : t('(Bot not in channel)') }`, value: channel.id, key: channel.id, @@ -138,7 +138,7 @@ export const mapChannelsToOptions = (result: SlackChannel[]) => { key: 'public', }, { - label: 'Private Channels (Bot in channel)', + label: t('Private Channels (Bot in channel)'), options: privateChannels.map((channel: SlackChannel) => ({ label: channel.name, value: channel.id, @@ -220,7 +220,7 @@ export const NotificationMethod: FunctionComponent = ({ NotificationMethodOption.Slack, NotificationMethodOption.SlackV2, ].includes(method) && - !slackOptions[0].options.length + !slackOptions[0]?.options.length ) { fetchSlackChannels({ types: ['public_channel', 'private_channel'] }) .then(({ json }) => { diff --git a/tests/unit_tests/utils/slack_test.py b/tests/unit_tests/utils/slack_test.py index ba6a729be1f49..42c3d3d4ce84e 100644 --- a/tests/unit_tests/utils/slack_test.py +++ b/tests/unit_tests/utils/slack_test.py @@ -138,7 +138,7 @@ def test_handle_slack_client_error_listing_channels(self, mocker): mock_client = mocker.Mock() mock_client.conversations_list.side_effect = SlackApiError( - "", "missing scope: channels:read" + "foo", "missing scope: channels:read" ) mocker.patch("superset.utils.slack.get_slack_client", return_value=mock_client) @@ -146,7 +146,7 @@ def test_handle_slack_client_error_listing_channels(self, mocker): get_channels_with_search() assert str(ex.value) == ( - """Failed to list channels: + """Failed to list channels: foo The server responded with: missing scope: channels:read""" )