Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {MonitorFixture} from 'sentry-fixture/monitor';
import {OrganizationFixture} from 'sentry-fixture/organization';

import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import MonitorHeaderActions from 'sentry/views/insights/crons/components/monitorHeaderActions';

describe('MonitorHeaderActions', () => {
const organization = OrganizationFixture();

it('disables mute button when monitor has no environments', async () => {
const monitor = MonitorFixture({
environments: [],
});

render(
<MonitorHeaderActions
monitor={monitor}
orgSlug={organization.slug}
onUpdate={jest.fn()}
/>,
{organization}
);

const muteButton = screen.getByRole('button', {name: 'Mute'});
expect(muteButton).toBeDisabled();

await userEvent.hover(muteButton);
expect(
await screen.findByText(
'Muting is only available when there are monitor environments'
)
).toBeInTheDocument();
});

it('enables mute button when monitor has environments', async () => {
const monitor = MonitorFixture();

const updateMock = MockApiClient.addMockResponse({
url: `/projects/${organization.slug}/${monitor.project.slug}/monitors/${monitor.slug}/`,
method: 'PUT',
body: {...monitor, isMuted: true},
});

render(
<MonitorHeaderActions
monitor={monitor}
orgSlug={organization.slug}
onUpdate={jest.fn()}
/>,
{organization}
);

const muteButton = screen.getByRole('button', {name: 'Mute'});
expect(muteButton).toBeEnabled();

await userEvent.click(muteButton);
expect(updateMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
data: {isMuted: true},
})
);
});

it('shows unmute button when monitor is muted', () => {
const monitor = MonitorFixture({
isMuted: true,
});

render(
<MonitorHeaderActions
monitor={monitor}
orgSlug={organization.slug}
onUpdate={jest.fn()}
/>,
{organization}
);

expect(screen.getByRole('button', {name: 'Unmute'})).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,24 @@ function MonitorHeaderActions({monitor, orgSlug, onUpdate}: Props) {
disableProps.title = permissionTooltipText;
}

const hasEnvironments = monitor.environments.length > 0;
const muteDisableProps = {...disableProps};

if (!hasEnvironments) {
muteDisableProps.disabled = true;
muteDisableProps.title = t(
'Muting is only available when there are monitor environments'
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: UI Masks True Reason for Disabled Button

When a monitor has no environments, the muteDisableProps.title is unconditionally overwritten, which loses the permission tooltip if the user lacks edit access. When both conditions are true (no permission and no environments), users see the environment message instead of the permission message, masking the actual reason the button is disabled.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's OK

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree - the user can fix the env, then the permissions error will show up. might be nice if you could see both, but doesn't seem vital.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it would be, the user creates an env, then they see they can't mute the monitor.

either way doesn't matter, this will go away in the future


return (
<ButtonBar>
<FeedbackWidgetButton />
<Button
size="sm"
icon={monitor.isMuted ? <IconSubscribed /> : <IconUnsubscribed />}
onClick={() => handleUpdate({isMuted: !monitor.isMuted})}
{...disableProps}
{...muteDisableProps}
>
{monitor.isMuted ? t('Unmute') : t('Mute')}
</Button>
Expand Down
Loading