widgetQueryFields.spec.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {
  4. mountWithTheme as reactMountWithTheme,
  5. screen,
  6. userEvent,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import WidgetQueryFields from 'sentry/components/dashboards/widgetQueryFields';
  9. import {QueryFieldValue} from 'sentry/utils/discover/fields';
  10. import {DisplayType, WidgetType} from 'sentry/views/dashboardsV2/types';
  11. import {FieldValueKind} from 'sentry/views/eventsV2/table/types';
  12. describe('WidgetQueryFields', function () {
  13. describe('Discover Fields', function () {
  14. const {routerContext} = initializeOrg();
  15. const organization = TestStubs.Organization();
  16. let wrapper;
  17. beforeEach(() => {
  18. // TODO change this to react testing library
  19. wrapper = mountWithTheme(
  20. <WidgetQueryFields
  21. widgetType={WidgetType.DISCOVER}
  22. displayType={DisplayType.TOP_N}
  23. fieldOptions={{
  24. 'function:count': {
  25. label: 'count()',
  26. value: {
  27. kind: FieldValueKind.FUNCTION,
  28. meta: {
  29. name: 'count',
  30. parameters: [],
  31. },
  32. },
  33. },
  34. 'field:title': {
  35. label: 'title',
  36. value: {
  37. kind: FieldValueKind.FIELD,
  38. meta: {
  39. name: 'title',
  40. dataType: 'string',
  41. },
  42. },
  43. },
  44. 'function:p95': {
  45. label: 'p95(…)',
  46. value: {
  47. kind: FieldValueKind.FUNCTION,
  48. meta: {
  49. name: 'p95',
  50. parameters: [],
  51. },
  52. },
  53. },
  54. }}
  55. fields={[
  56. {
  57. kind: 'field',
  58. field: 'title',
  59. },
  60. {
  61. kind: 'function',
  62. function: ['count', '', undefined, undefined],
  63. },
  64. {
  65. kind: 'function',
  66. function: ['p95', 'transaction.duration', undefined, undefined],
  67. },
  68. ]}
  69. organization={organization}
  70. onChange={() => undefined}
  71. />,
  72. routerContext
  73. );
  74. });
  75. it('renders with grey dotted previous period when using only a single series', function () {
  76. const columns = wrapper.find('StyledColumnEditCollection').find('QueryField');
  77. expect(columns.length).toEqual(2);
  78. expect(columns.at(0).props().fieldValue).toEqual({
  79. kind: 'field',
  80. field: 'title',
  81. });
  82. expect(columns.at(1).props().fieldValue).toEqual({
  83. kind: 'function',
  84. function: ['count', '', undefined, undefined],
  85. });
  86. expect(
  87. wrapper.find('QueryFieldWrapper').find('QueryField').props().fieldValue
  88. ).toEqual({
  89. function: ['p95', 'transaction.duration', undefined, undefined],
  90. kind: 'function',
  91. });
  92. });
  93. });
  94. describe('Issue Fields', function () {
  95. const organization = TestStubs.Organization();
  96. let fields: QueryFieldValue[];
  97. const mountComponent = () =>
  98. reactMountWithTheme(
  99. <WidgetQueryFields
  100. widgetType={WidgetType.ISSUE}
  101. displayType={DisplayType.TABLE}
  102. fieldOptions={{
  103. 'field:issue': {
  104. label: 'issue',
  105. value: {
  106. kind: FieldValueKind.FIELD,
  107. meta: {
  108. name: 'issue',
  109. dataType: 'string',
  110. },
  111. },
  112. },
  113. 'field:assignee': {
  114. label: 'assignee',
  115. value: {
  116. kind: FieldValueKind.FIELD,
  117. meta: {
  118. name: 'assignee',
  119. dataType: 'string',
  120. },
  121. },
  122. },
  123. }}
  124. fields={fields}
  125. organization={organization}
  126. onChange={newFields => {
  127. fields.splice(0, fields.length, ...newFields);
  128. }}
  129. />
  130. );
  131. beforeEach(() => {
  132. fields = [
  133. {
  134. kind: 'field',
  135. field: 'issue',
  136. },
  137. {
  138. kind: 'field',
  139. field: 'assignee',
  140. },
  141. ];
  142. mountComponent();
  143. });
  144. it('renders issue and assignee columns', function () {
  145. expect(screen.getByText('issue')).toBeInTheDocument();
  146. expect(screen.getByText('assignee')).toBeInTheDocument();
  147. });
  148. it('renders only issue column', function () {
  149. expect(screen.getByText('issue')).toBeInTheDocument();
  150. userEvent.click(screen.getByTestId('remove-column-1'));
  151. expect(screen.queryByText('assignee')).not.toBeInTheDocument();
  152. });
  153. it('renders issue column and then assignee column after adding', function () {
  154. userEvent.click(screen.getByTestId('remove-column-1'));
  155. expect(screen.queryByText('assignee')).not.toBeInTheDocument();
  156. expect(screen.getByText('Add a Column')).toBeInTheDocument();
  157. userEvent.click(screen.getByText('Add a Column'));
  158. mountComponent();
  159. expect(screen.getByText('(Required)')).toBeInTheDocument();
  160. userEvent.keyboard('a');
  161. userEvent.click(screen.getByText('assignee'));
  162. mountComponent();
  163. expect(screen.getByText('assignee')).toBeInTheDocument();
  164. });
  165. });
  166. });