123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import {mountWithTheme} from 'sentry-test/enzyme';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import IssueAlertOptions from 'sentry/views/projectInstall/issueAlertOptions';
- describe('IssueAlertOptions', function () {
- const {organization, routerContext} = initializeOrg();
- const URL = `/projects/${organization.slug}/rule-conditions/`;
- let props;
- const baseProps = {
- onChange: _ => {},
- };
- beforeEach(() => {
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/rule-conditions/`,
- body: TestStubs.MOCK_RESP_VERBOSE,
- });
- props = {...baseProps};
- });
- const selectControlVerifier = async (wrapper, dataTestId, optionsText) => {
- wrapper
- .find(`[data-test-id="${dataTestId}"] input[id*="react-select"]`)
- .last()
- .simulate('focus');
- await tick();
- wrapper.update();
- expect(
- wrapper.find(`InlineSelectControl[data-test-id="${dataTestId}"] Option`)
- ).toHaveLength(optionsText.length);
- optionsText.forEach((metricText, idx) =>
- expect(
- wrapper
- .find(`InlineSelectControl[data-test-id="${dataTestId}"] Option`)
- .at(idx)
- .text()
- ).toBe(metricText)
- );
- };
- it('should render only the `Default Rule` and `Create Later` option on empty response:[]', () => {
- MockApiClient.addMockResponse({
- url: URL,
- body: [],
- });
- const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
- expect(wrapper.find('RadioLineItem')).toHaveLength(2);
- });
- it('should render only the `Default Rule` and `Create Later` option on empty response:{}', () => {
- MockApiClient.addMockResponse({
- url: URL,
- body: {},
- });
- const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
- expect(wrapper.find('RadioLineItem')).toHaveLength(2);
- });
- it('should render only the `Default Rule` and `Create Later` option on responses with different allowable intervals', () => {
- MockApiClient.addMockResponse({
- url: URL,
- body: TestStubs.MOCK_RESP_INCONSISTENT_INTERVALS,
- });
- const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
- expect(wrapper.find('RadioLineItem')).toHaveLength(2);
- });
- it('should render all(three) options on responses with different placeholder values', () => {
- MockApiClient.addMockResponse({
- url: URL,
- body: TestStubs.MOCK_RESP_INCONSISTENT_PLACEHOLDERS,
- });
- const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
- expect(wrapper.find('RadioLineItem')).toHaveLength(3);
- });
- it('should ignore conditions that are not `sentry.rules.conditions.event_frequency.EventFrequencyCondition` and `sentry.rules.conditions.event_frequency.EventUniqueUserFrequencyCondition`', () => {
- MockApiClient.addMockResponse({
- url: URL,
- body: TestStubs.MOCK_RESP_ONLY_IGNORED_CONDITIONS_INVALID,
- });
- const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
- expect(wrapper.find('RadioLineItem')).toHaveLength(3);
- selectControlVerifier(wrapper, 'metric-select-control', ['users affected by']);
- });
- it('should render all(three) options on a valid response', () => {
- MockApiClient.addMockResponse({
- url: URL,
- body: TestStubs.MOCK_RESP_VERBOSE,
- });
- const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
- expect(wrapper.find('RadioLineItem')).toHaveLength(3);
- });
- it('should pre-populate fields from server response', () => {
- MockApiClient.addMockResponse({
- url: URL,
- body: TestStubs.MOCK_RESP_VERBOSE,
- });
- const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
- [
- ['metric-select-control', ['occurrences of', 'users affected by']],
- [
- 'interval-select-control',
- ['one minute', 'one hour', 'one day', 'one week', '30 days'],
- ],
- ].forEach(([dataTestId, options]) =>
- selectControlVerifier(wrapper, dataTestId, options)
- );
- });
- it('should not pre-fill threshold value after a valid server response', () => {
- MockApiClient.addMockResponse({
- url: URL,
- body: TestStubs.MOCK_RESP_VERBOSE,
- });
- const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
- expect(wrapper.find('input[data-test-id="range-input"]').props().value).toBe('');
- });
- });
|