Skip to content

Commit

Permalink
translate strings and improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Jul 17, 2024
1 parent 2225a94 commit f7e4a1e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -134,7 +135,7 @@ describe('NotificationMethod', () => {
recipients: '[email protected]',
});
});
// correctly maps recipients when method is SlackV2

it('should correctly map recipients when method is SlackV2', () => {
const method = 'SlackV2';
const recipientValue = 'user1,user2';
Expand All @@ -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 = '';
Expand All @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ 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,
})),
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,
Expand Down Expand Up @@ -220,7 +220,7 @@ export const NotificationMethod: FunctionComponent<NotificationMethodProps> = ({
NotificationMethodOption.Slack,
NotificationMethodOption.SlackV2,
].includes(method) &&
!slackOptions[0].options.length
!slackOptions[0]?.options.length
) {
fetchSlackChannels({ types: ['public_channel', 'private_channel'] })
.then(({ json }) => {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/utils/slack_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ 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)

with pytest.raises(SupersetException) as ex:
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"""
)

Expand Down

0 comments on commit f7e4a1e

Please sign in to comment.