slackblock 0.4.0 → 1.0.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/CHANGELOG.md +33 -26
  2. package/LICENSE +21 -21
  3. package/README.md +95 -85
  4. package/dist/block.cjs +341 -0
  5. package/dist/block.cjs.map +1 -0
  6. package/dist/block.d.mts +412 -0
  7. package/dist/block.d.ts +412 -0
  8. package/dist/block.mjs +268 -0
  9. package/dist/block.mjs.map +1 -0
  10. package/dist/index.cjs +1202 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.mts +6 -0
  13. package/dist/index.d.ts +6 -0
  14. package/dist/index.mjs +1170 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/types.d-DgQXbJte.d.mts +296 -0
  17. package/dist/types.d-DgQXbJte.d.ts +296 -0
  18. package/package.json +85 -135
  19. package/blocks.js +0 -12
  20. package/index.js +0 -7
  21. package/lib/components/block/button.js +0 -27
  22. package/lib/components/block/confirmation.js +0 -27
  23. package/lib/components/block/image.js +0 -27
  24. package/lib/components/block/text.js +0 -27
  25. package/lib/components/index.js +0 -42
  26. package/lib/components/input/date-picker.js +0 -27
  27. package/lib/components/input/option-group.js +0 -27
  28. package/lib/components/input/option.js +0 -27
  29. package/lib/components/input/overflow.js +0 -27
  30. package/lib/components/input/radio-group.js +0 -27
  31. package/lib/components/input/select.js +0 -34
  32. package/lib/components/input/text.js +0 -27
  33. package/lib/components/layout/actions.js +0 -27
  34. package/lib/components/layout/container.js +0 -27
  35. package/lib/components/layout/context.js +0 -27
  36. package/lib/components/layout/divider.js +0 -27
  37. package/lib/components/layout/file.js +0 -27
  38. package/lib/components/layout/image.js +0 -27
  39. package/lib/components/layout/input.js +0 -27
  40. package/lib/components/layout/section.js +0 -27
  41. package/lib/components/message.js +0 -27
  42. package/lib/index.js +0 -7
  43. package/lib/parser/index.js +0 -32
  44. package/lib/renderer/index.js +0 -71
  45. package/lib/transformers/block/button.js +0 -29
  46. package/lib/transformers/block/confirmation.js +0 -18
  47. package/lib/transformers/block/image.js +0 -10
  48. package/lib/transformers/block/text.js +0 -16
  49. package/lib/transformers/index.js +0 -54
  50. package/lib/transformers/input/date-picker.js +0 -30
  51. package/lib/transformers/input/option-group.js +0 -19
  52. package/lib/transformers/input/option.js +0 -19
  53. package/lib/transformers/input/overflow.js +0 -19
  54. package/lib/transformers/input/radio-group.js +0 -22
  55. package/lib/transformers/input/select.js +0 -84
  56. package/lib/transformers/input/text.js +0 -31
  57. package/lib/transformers/layout/actions.js +0 -18
  58. package/lib/transformers/layout/container.js +0 -11
  59. package/lib/transformers/layout/context.js +0 -18
  60. package/lib/transformers/layout/divider.js +0 -10
  61. package/lib/transformers/layout/file.js +0 -14
  62. package/lib/transformers/layout/image.js +0 -23
  63. package/lib/transformers/layout/input.js +0 -26
  64. package/lib/transformers/layout/section.js +0 -31
  65. package/lib/utils/get-type.js +0 -16
  66. package/lib/utils/type-helpers.js +0 -2
  67. package/src/components/block/button.tsx +0 -20
  68. package/src/components/block/confirmation.tsx +0 -19
  69. package/src/components/block/image.tsx +0 -8
  70. package/src/components/block/text.tsx +0 -10
  71. package/src/components/index.ts +0 -23
  72. package/src/components/input/date-picker.tsx +0 -11
  73. package/src/components/input/option-group.tsx +0 -9
  74. package/src/components/input/option.tsx +0 -9
  75. package/src/components/input/overflow.tsx +0 -12
  76. package/src/components/input/radio-group.tsx +0 -13
  77. package/src/components/input/select.tsx +0 -36
  78. package/src/components/input/text.tsx +0 -12
  79. package/src/components/layout/actions.tsx +0 -9
  80. package/src/components/layout/container.tsx +0 -9
  81. package/src/components/layout/context.tsx +0 -12
  82. package/src/components/layout/divider.tsx +0 -7
  83. package/src/components/layout/file.tsx +0 -8
  84. package/src/components/layout/image.tsx +0 -10
  85. package/src/components/layout/input.tsx +0 -12
  86. package/src/components/layout/section.tsx +0 -15
  87. package/src/components/message.tsx +0 -20
  88. package/src/constants/types.d.ts +0 -93
  89. package/src/index.ts +0 -3
  90. package/src/parser/index.ts +0 -32
  91. package/src/renderer/index.ts +0 -75
  92. package/src/transformers/block/button.tsx +0 -47
  93. package/src/transformers/block/confirmation.tsx +0 -26
  94. package/src/transformers/block/image.ts +0 -18
  95. package/src/transformers/block/text.ts +0 -34
  96. package/src/transformers/index.ts +0 -65
  97. package/src/transformers/input/date-picker.tsx +0 -43
  98. package/src/transformers/input/option-group.tsx +0 -26
  99. package/src/transformers/input/option.tsx +0 -27
  100. package/src/transformers/input/overflow.ts +0 -33
  101. package/src/transformers/input/radio-group.ts +0 -38
  102. package/src/transformers/input/select.tsx +0 -136
  103. package/src/transformers/input/text.tsx +0 -47
  104. package/src/transformers/layout/actions.ts +0 -29
  105. package/src/transformers/layout/container.ts +0 -16
  106. package/src/transformers/layout/context.ts +0 -35
  107. package/src/transformers/layout/divider.ts +0 -20
  108. package/src/transformers/layout/file.ts +0 -24
  109. package/src/transformers/layout/image.tsx +0 -34
  110. package/src/transformers/layout/input.tsx +0 -39
  111. package/src/transformers/layout/section.ts +0 -53
  112. package/src/tsconfig.json +0 -11
  113. package/src/utils/get-type.ts +0 -20
  114. package/src/utils/type-helpers.ts +0 -1
  115. package/test/index.test.tsx +0 -11
  116. package/test/parser/parser.test.tsx +0 -67
  117. package/test/renderer/renderer.test.tsx +0 -138
  118. package/test/transformers/block/button.test.tsx +0 -63
  119. package/test/transformers/block/confirmation.test.tsx +0 -37
  120. package/test/transformers/block/image.test.tsx +0 -20
  121. package/test/transformers/block/text.test.tsx +0 -32
  122. package/test/transformers/input/date-picker.test.tsx +0 -66
  123. package/test/transformers/input/option-group.test.tsx +0 -26
  124. package/test/transformers/input/option.test.tsx +0 -36
  125. package/test/transformers/input/overflow.test.tsx +0 -57
  126. package/test/transformers/input/radio-group.test.tsx +0 -81
  127. package/test/transformers/input/select.test.tsx +0 -249
  128. package/test/transformers/input/text.test.tsx +0 -42
  129. package/test/transformers/layout/actions.test.tsx +0 -33
  130. package/test/transformers/layout/container.test.tsx +0 -34
  131. package/test/transformers/layout/context.test.tsx +0 -43
  132. package/test/transformers/layout/divider.test.tsx +0 -20
  133. package/test/transformers/layout/file.test.tsx +0 -26
  134. package/test/transformers/layout/image.test.tsx +0 -43
  135. package/test/transformers/layout/input.test.tsx +0 -59
  136. package/test/transformers/layout/section.test.tsx +0 -89
  137. package/test/tsconfig.json +0 -9
  138. package/test/utils/get-type.test.tsx +0 -21
  139. package/tsconfig.json +0 -14
@@ -1,33 +0,0 @@
1
- import {Element} from '../../constants/types';
2
- import {Props as OverflowProps} from '../../components/input/overflow';
3
- import {ConfirmationType} from '../block/confirmation';
4
- import {OptionType} from './option';
5
- import {transform} from '..';
6
-
7
- export type OverflowType = {
8
- type: 'overflow';
9
- action_id: string;
10
- options: OptionType[];
11
- confirm?: ConfirmationType;
12
- };
13
-
14
- export default (child: Element): OverflowType => {
15
- const {actionId, children, confirm}: OverflowProps = child.props;
16
-
17
- let elements = children;
18
- if (!Array.isArray(elements)) {
19
- elements = [elements];
20
- }
21
-
22
- const res: OverflowType = {
23
- type: 'overflow',
24
- action_id: actionId,
25
- options: elements.map(element => transform(element as Element)) as OptionType[]
26
- };
27
-
28
- if (confirm) {
29
- res.confirm = transform(confirm as Element) as ConfirmationType;
30
- }
31
-
32
- return res;
33
- };
@@ -1,38 +0,0 @@
1
- import {Element} from '../../constants/types';
2
- import {Props as RadioGroupProps} from '../../components/input/radio-group';
3
- import {ConfirmationType} from '../block/confirmation';
4
- import {OptionType} from './option';
5
- import {transform} from '..';
6
-
7
- export type RadioGroupType = {
8
- type: 'radio_buttons';
9
- action_id: string;
10
- options: OptionType[];
11
- initial_option?: OptionType;
12
- confirm?: ConfirmationType;
13
- };
14
-
15
- export default (child: Element): RadioGroupType => {
16
- const {actionId, children, initialOption, confirm}: RadioGroupProps = child.props;
17
-
18
- let elements = children;
19
- if (!Array.isArray(elements)) {
20
- elements = [elements];
21
- }
22
-
23
- const res: RadioGroupType = {
24
- type: 'radio_buttons',
25
- action_id: actionId,
26
- options: elements.map(element => transform(element as Element)) as OptionType[]
27
- };
28
-
29
- if (initialOption) {
30
- res.initial_option = transform(initialOption as Element) as OptionType;
31
- }
32
-
33
- if (confirm) {
34
- res.confirm = transform(confirm as Element) as ConfirmationType;
35
- }
36
-
37
- return res;
38
- };
@@ -1,136 +0,0 @@
1
- import React from 'react';
2
- import {Element} from '../../constants/types';
3
- import {TextType} from '../block/text';
4
- import {OptionType} from './option';
5
- import {OptionGroupType} from './option-group';
6
- import {ConfirmationType} from '../block/confirmation';
7
- import {Props as SelectProps, selectTypes} from '../../components/input/select';
8
- import Option from '../../components/input/option';
9
- import Text from '../../components/block/text';
10
- import {transform} from '..';
11
- import getType from '../../utils/get-type';
12
- import OptionGroup from '../../components/input/option-group';
13
-
14
- type ValidSelectType =
15
- 'static_select' |
16
- 'multi_static_select' |
17
- 'external_select' |
18
- 'multi_external_select' |
19
- 'users_select' |
20
- 'multi_users_select' |
21
- 'conversations_select' |
22
- 'multi_conversations_select' |
23
- 'channels_select' |
24
- 'multi_channels_select';
25
-
26
- export type SelectType = {
27
- type: ValidSelectType;
28
- placeholder: TextType;
29
- action_id: string;
30
- options?: OptionType[];
31
- option_groups?: OptionGroupType[];
32
- initial_options?: OptionType[];
33
- confirm?: ConfirmationType;
34
- max_selected_items?: number;
35
- initial_users?: string[];
36
- initial_conversations?: string[];
37
- initial_channels?: string[];
38
- };
39
-
40
- const OPTION = 'Option';
41
- const OPTION_GROUP = 'OptionGroup';
42
-
43
- const types = {
44
- [selectTypes.STATIC]: 'static_select',
45
- [selectTypes.EXTERNAL]: 'external_select',
46
- [selectTypes.USER]: 'users_select',
47
- [selectTypes.CONVERSATION]: 'conversations_select',
48
- [selectTypes.CHANNEL]: 'channels_select'
49
- };
50
- const MULTI_PREFIX = 'multi_';
51
-
52
- export default (child: Element): SelectType => {
53
- const {
54
- placeholder,
55
- actionId,
56
- multi,
57
- children,
58
- initialOptions,
59
- confirm,
60
- maxSelectedItems,
61
- type: typeProp,
62
- initialUsers,
63
- initialConversations,
64
- initialChannels
65
- }: SelectProps = child.props;
66
-
67
- const type = typeProp || selectTypes.STATIC;
68
- const typeString = `${multi ? MULTI_PREFIX : ''}${types[type]}` as ValidSelectType;
69
-
70
- const res: SelectType = {
71
- type: typeString,
72
- placeholder: transform(<Text plainText>{placeholder}</Text>) as TextType,
73
- action_id: actionId
74
- };
75
-
76
- let elements = children;
77
- if (!Array.isArray(elements)) {
78
- elements = [elements] as React.ReactElement[];
79
- }
80
-
81
- if (type === selectTypes.STATIC) {
82
- const type = getType(elements[0] as Element);
83
- if (elements.some((element: React.ReactElement) => getType(element as Element) !== type)) {
84
- if (type === OPTION && elements.some((element: React.ReactElement) => getType(element as Element) !== OPTION_GROUP)) {
85
- throw new TypeError('You cannot mix OptionGroup types with Option types in a Select block.');
86
- } else if (type === OPTION_GROUP && elements.some((element: React.ReactElement) => getType(element as Element) !== OPTION)) {
87
- throw new TypeError('You cannot mix OptionGroup types with Option types in a Select block.');
88
- }
89
- throw new TypeError('Only allowed types are Option OR OptionGroup');
90
- }
91
-
92
- if (type === OPTION) {
93
- elements = elements as React.ReactElement<Option>[];
94
-
95
- res.options = elements.map(element => transform(element as Element)) as OptionType[];
96
- } else if (type === OPTION_GROUP) {
97
- elements = elements as React.ReactElement<OptionGroup>[];
98
-
99
- res.option_groups = elements.map(element => transform(element as Element)) as OptionGroupType[];
100
- }
101
- }
102
-
103
- if (confirm) {
104
- res.confirm = transform(confirm as Element) as ConfirmationType;
105
- }
106
-
107
- if (type !== selectTypes.USER && initialOptions) {
108
- }
109
-
110
- switch (type) {
111
- case selectTypes.USER:
112
- if (initialUsers) {
113
- res.initial_users = initialUsers;
114
- }
115
- break;
116
- case selectTypes.CONVERSATION:
117
- if (initialConversations) {
118
- res.initial_conversations = initialConversations;
119
- }
120
- break;
121
- case selectTypes.CHANNEL:
122
- if (initialChannels) {
123
- res.initial_channels = initialChannels;
124
- }
125
- default:
126
- if (initialOptions) {
127
- res.initial_options = initialOptions.map(element => transform(element as Element)) as OptionType[];
128
- }
129
- }
130
-
131
- if (maxSelectedItems) {
132
- res.max_selected_items = maxSelectedItems;
133
- }
134
-
135
- return res;
136
- };
@@ -1,47 +0,0 @@
1
- import React from 'react';
2
- import Text from '../../components/block/text';
3
- import {Props as TextInputProps} from '../../components/input/text';
4
- import {TextType as TextProps} from '../block/text';
5
- import {Element} from '../../constants/types';
6
- import { transform } from '..';
7
-
8
- export type TextType = {
9
- type: 'plain_text_input';
10
- action_id: string;
11
- placeholder?: TextProps;
12
- initial_value?: string;
13
- multiline?: boolean;
14
- min_length?: number;
15
- max_length?: number;
16
- };
17
-
18
- export default (child: Element): TextType => {
19
- const {actionId, placeholder, initial, multiline, minLength, maxLength}: TextInputProps = child.props;
20
-
21
- const res: TextType = {
22
- type: 'plain_text_input',
23
- action_id: actionId
24
- };
25
-
26
- if (placeholder) {
27
- res.placeholder = transform(<Text plainText>{placeholder}</Text>) as TextProps;
28
- }
29
-
30
- if (initial) {
31
- res.initial_value = initial;
32
- }
33
-
34
- if (multiline) {
35
- res.multiline = true;
36
- }
37
-
38
- if (minLength) {
39
- res.min_length = minLength;
40
- }
41
-
42
- if (maxLength) {
43
- res.max_length = maxLength;
44
- }
45
-
46
- return res;
47
- };
@@ -1,29 +0,0 @@
1
- import {Element, SerializedInteractiveBlockElement, InteractiveBlockElement} from '../../constants/types';
2
- import {Props as ActionProps} from '../../components/layout/actions';
3
- import {transform} from '..';
4
-
5
- type ActionType = {
6
- type: 'actions';
7
- elements: SerializedInteractiveBlockElement[];
8
- block_id?: string;
9
- };
10
-
11
- export default (child: Element): ActionType => {
12
- const {children, blockId}: ActionProps = child.props;
13
-
14
- let elements = children;
15
- if (!Array.isArray(elements)) {
16
- elements = [elements] as InteractiveBlockElement[];
17
- }
18
-
19
- const res: ActionType = {
20
- type: 'actions',
21
- elements: elements.map(element => transform(element as Element) as SerializedInteractiveBlockElement)
22
- };
23
-
24
- if (blockId) {
25
- res.block_id = blockId;
26
- }
27
-
28
- return res;
29
- };
@@ -1,16 +0,0 @@
1
- import {Props as ContainerProps} from '../../components/layout/container';
2
- import {Element, Child} from '../../constants/types';
3
- import {transform} from '..';
4
-
5
- type ContainerType = Child[];
6
-
7
- export default (child: Element): ContainerType => {
8
- const {children}: ContainerProps = child.props;
9
-
10
- let elements = children;
11
- if (!Array.isArray(elements)) {
12
- elements = [elements] as Child[];
13
- }
14
-
15
- return (elements as Element[]).map(element => transform(element)) as Child[];
16
- };
@@ -1,35 +0,0 @@
1
- import {Element} from '../../constants/types';
2
-
3
- import {Props as ContextProps, ImageOrText as ImageOrTextElem} from '../../components/layout/context';
4
- import {TextType} from '../block/text';
5
- import {ImageType} from '../block/image';
6
- import {transform} from '..';
7
-
8
- type ImageOrText = ImageType | TextType;
9
- type ImageOrTextElemSet = ImageOrTextElem | ImageOrTextElem[];
10
-
11
- type ContextType = {
12
- type: 'context';
13
- elements: ImageOrText | ImageOrText[];
14
- block_id?: string;
15
- };
16
-
17
- export default (child: Element): ContextType => {
18
- const {children, blockId}: ContextProps = child.props;
19
-
20
- let elements = children as ImageOrTextElemSet;
21
- if (!Array.isArray(elements)) {
22
- elements = [elements] as ImageOrTextElem[];
23
- }
24
-
25
- const res: ContextType = {
26
- type: 'context',
27
- elements: elements.map(element => transform(element as Element) as ImageOrText)
28
- };
29
-
30
- if (blockId) {
31
- res.block_id = blockId;
32
- }
33
-
34
- return res;
35
- };
@@ -1,20 +0,0 @@
1
- import {Element} from '../../constants/types';
2
-
3
- import {Props as DividerProps} from '../../components/layout/divider';
4
-
5
- type DividerType = {
6
- type: 'divider';
7
- block_id?: string;
8
- };
9
-
10
- export default (child: Element): DividerType => {
11
- const {blockId}: DividerProps = child.props;
12
-
13
- const res: DividerType = {type: 'divider'};
14
-
15
- if (blockId) {
16
- res.block_id = blockId;
17
- }
18
-
19
- return res;
20
- };
@@ -1,24 +0,0 @@
1
- import {Element} from '../../constants/types';
2
- import {Props as FileProps} from '../../components/layout/file';
3
-
4
- type FileType = {
5
- type: 'file';
6
- source: 'remote';
7
- external_id: string;
8
- block_id?: string;
9
- };
10
-
11
- export default (child: Element): FileType => {
12
- const {externalId, blockId}: FileProps = child.props;
13
- const res: FileType = {
14
- type: 'file',
15
- source: 'remote',
16
- external_id: externalId
17
- };
18
-
19
- if (blockId) {
20
- res.block_id = blockId;
21
- }
22
-
23
- return res;
24
- };
@@ -1,34 +0,0 @@
1
- import React from 'react';
2
- import {Element} from '../../constants/types';
3
- import {TextType} from '../block/text';
4
- import {Props as ImageProps} from '../../components/layout/image';
5
- import { transform } from '..';
6
- import Text from '../../components/block/text';
7
-
8
- type ImageType = {
9
- type: 'image';
10
- image_url: string;
11
- alt_text: string;
12
- title?: TextType;
13
- block_id?: string;
14
- };
15
-
16
- export default (child: Element): ImageType => {
17
- const {url, alt, title, blockId}: ImageProps = child.props;
18
-
19
- const res: ImageType = {
20
- type: 'image',
21
- image_url: url,
22
- alt_text: alt
23
- };
24
-
25
- if (title) {
26
- res.title = transform(<Text plainText>{title}</Text>) as TextType;
27
- }
28
-
29
- if (blockId) {
30
- res.block_id = blockId;
31
- }
32
-
33
- return res;
34
- };
@@ -1,39 +0,0 @@
1
- import React from 'react';
2
- import {Element, SerializedInputBlockElement} from '../../constants/types';
3
- import {TextType} from '../block/text';
4
- import {Props as InputProps} from '../../components/layout/input';
5
- import {transform} from '..';
6
- import Text from '../../components/block/text';
7
-
8
- type InputType = {
9
- type: 'input';
10
- label: TextType;
11
- element: SerializedInputBlockElement;
12
- hint?: TextType;
13
- optional?: boolean;
14
- block_id?: string;
15
- }
16
-
17
- export default (child: Element): InputType => {
18
- const {label, element, hint, optional, blockId}: InputProps = child.props;
19
-
20
- const res: InputType = {
21
- type: 'input',
22
- label: transform(<Text plainText>{label}</Text>) as TextType,
23
- element: transform(element as Element) as SerializedInputBlockElement
24
- };
25
-
26
- if (hint) {
27
- res.hint = transform(<Text plainText>{hint}</Text>) as TextType;
28
- }
29
-
30
- if (optional) {
31
- res.optional = true;
32
- }
33
-
34
- if (blockId) {
35
- res.block_id = blockId;
36
- }
37
-
38
- return res;
39
- };
@@ -1,53 +0,0 @@
1
- import {Element, SerializedBlockElement} from '../../constants/types';
2
- import {TextType as Text} from '../block/text';
3
- import TextComponent from '../../components/block/text';
4
- import {transform} from '..';
5
-
6
- type SectionType = {
7
- type: 'section';
8
- text: Text;
9
- block_id?: string;
10
- fields?: Text[];
11
- accessory?: SerializedBlockElement;
12
- };
13
-
14
- export default (elem: Element): SectionType => {
15
- const {
16
- props: {
17
- text,
18
- blockId,
19
- children,
20
- accessory
21
- }
22
- } = elem;
23
-
24
- const res: SectionType = {
25
- type: 'section',
26
- text: transform(text as Element) as Text
27
- };
28
-
29
- if (blockId) {
30
- res.block_id = blockId;
31
- }
32
-
33
- if (accessory) {
34
- res.accessory = transform(accessory) as SerializedBlockElement;
35
- }
36
-
37
- if (children) {
38
- res.fields = [];
39
- let fields = children;
40
- if (!Array.isArray(fields)) {
41
- fields = [fields];
42
- }
43
-
44
- for (const field of fields) {
45
- if (field) {
46
- const t = transform(field as TextComponent);
47
- res.fields.push(t as Text);
48
- }
49
- }
50
- }
51
-
52
- return res;
53
- };
package/src/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "noImplicitAny": true,
4
- "removeComments": true,
5
- "outDir": "../lib" ,
6
- "rootDir": ".",
7
- "target": "es5",
8
- "esModuleInterop": true,
9
- "jsx": "react"
10
- }
11
- }
@@ -1,20 +0,0 @@
1
- import {Child} from '../constants/types';
2
-
3
- export default (element: Child): string => {
4
- if (typeof element === 'string') {
5
- return 'string';
6
- }
7
-
8
- if (element === null) {
9
- return 'null';
10
- }
11
-
12
- if (Array.isArray(element)) {
13
- throw new TypeError('Cannot type arrays');
14
- }
15
-
16
- const {type} = element;
17
- const fn = type as () => void;
18
-
19
- return fn.name || type as string;
20
- };
@@ -1 +0,0 @@
1
- export type SingleOrArray<T> = T | T[];
@@ -1,11 +0,0 @@
1
- import test from 'ava';
2
- import React from 'react';
3
-
4
- import render from '../src';
5
- import Message from '../src/components/message';
6
-
7
- test('can accept React component without erroring', t => {
8
- const fn = () => render(<Message>child</Message>);
9
-
10
- t.notThrows(fn);
11
- });
@@ -1,67 +0,0 @@
1
- import React from 'react';
2
- import test from 'ava';
3
- import {stub} from 'sinon';
4
- import proxyquire from 'proxyquire';
5
-
6
- const fooTransformer = stub();
7
- const divTransformer = stub().callsFake(elem => {
8
- return {
9
- type: 'div',
10
- text: elem.props.children
11
- }
12
- });
13
-
14
- const parser = proxyquire('../../src/parser', {
15
- '../transformers': {
16
- default: {
17
- Foo: fooTransformer,
18
- div: divTransformer
19
- }
20
- }
21
- }).default;
22
-
23
- test('it returns a basic message if the child is just a string', t => {
24
- const text = 'Hello, world!';
25
- const result = parser(text);
26
- const expected = {text};
27
-
28
- t.deepEqual(result, expected);
29
- });
30
-
31
- const Foo = () => <p>Test</p>;
32
- test('it passes the item to the right transformer', t => {
33
- const elem = (
34
- <div>
35
- <p>Hi</p>
36
- </div>
37
- );
38
-
39
- const elem2 = <Foo/>;
40
-
41
- parser([elem, elem2]);
42
-
43
- t.true(divTransformer.calledWith(elem));
44
- t.true(fooTransformer.calledWith(elem2));
45
- });
46
-
47
- test('it returns the result of the transformers', t => {
48
- const res = parser(<div>Foo</div>);
49
-
50
- t.deepEqual(res, {
51
- blocks: [
52
- {type: 'div', text: 'Foo'}
53
- ]
54
- });
55
- });
56
-
57
- test('it does not transform unkown types', t => {
58
- const res = parser(<p>Hi</p>);
59
-
60
- t.deepEqual(res, {});
61
- });
62
-
63
- test('it does not explode on null', t => {
64
- const fn = () => parser(null);
65
-
66
- t.notThrows(fn);
67
- });