dyaskur /
google-chat-shuffler
| 1 | import { |
||
| 2 | buildInputForm, |
||
| 3 | buildMessageBody, |
||
| 4 | buildNameListSection, |
||
| 5 | buildNameListWinnerSection, |
||
| 6 | } from '../helpers/components.js'; |
||
| 7 | |||
| 8 | test('build name list card', () => { |
||
| 9 | const names = [ |
||
| 10 | 'Yaskur', |
||
| 11 | 'Nganu', |
||
| 12 | 'Dyas', |
||
| 13 | 'Muhammad', |
||
| 14 | ]; |
||
| 15 | const section = buildNameListSection(names); |
||
| 16 | const expected = { |
||
| 17 | 'sections': [ |
||
| 18 | { |
||
| 19 | 'widgets': [ |
||
| 20 | { |
||
| 21 | 'decoratedText': { |
||
| 22 | 'text': 'Yaskur', |
||
| 23 | 'startIcon': { |
||
| 24 | 'iconUrl': expect.any(String), |
||
|
0 ignored issues
–
show
|
|||
| 25 | }, |
||
| 26 | }, |
||
| 27 | }, |
||
| 28 | { |
||
| 29 | 'decoratedText': { |
||
| 30 | 'text': 'Nganu', |
||
| 31 | 'startIcon': { |
||
| 32 | 'iconUrl': expect.any(String), |
||
| 33 | }, |
||
| 34 | }, |
||
| 35 | }, |
||
| 36 | { |
||
| 37 | 'decoratedText': { |
||
| 38 | 'text': 'Dyas', |
||
| 39 | 'startIcon': { |
||
| 40 | 'iconUrl': expect.any(String), |
||
| 41 | }, |
||
| 42 | }, |
||
| 43 | }, |
||
| 44 | { |
||
| 45 | 'decoratedText': { |
||
| 46 | 'text': 'Muhammad', |
||
| 47 | 'startIcon': { |
||
| 48 | 'iconUrl': expect.any(String), |
||
| 49 | }, |
||
| 50 | }, |
||
| 51 | }, |
||
| 52 | ], |
||
| 53 | }, |
||
| 54 | ], |
||
| 55 | }; |
||
| 56 | expect(section).toStrictEqual(expected); |
||
| 57 | const messageBody = buildMessageBody(section); |
||
| 58 | const expectedMessage = { |
||
| 59 | 'text': '', |
||
| 60 | 'cardsV2': [ |
||
| 61 | { |
||
| 62 | 'cardId': 'card-id', |
||
| 63 | 'card': section, |
||
| 64 | }, |
||
| 65 | ], |
||
| 66 | }; |
||
| 67 | expect(messageBody).toStrictEqual(expectedMessage); |
||
| 68 | }); |
||
| 69 | |||
| 70 | test('build name list card with a winner', () => { |
||
| 71 | const names = [ |
||
| 72 | 'Moses', |
||
| 73 | 'Ibrahim', |
||
| 74 | 'Ismail', |
||
| 75 | 'Zulkarnain', |
||
| 76 | 'Sulaiman', |
||
| 77 | ]; |
||
| 78 | const winnerSection = buildNameListWinnerSection(names, ['Moses']); |
||
| 79 | const expected = { |
||
| 80 | 'sections': [ |
||
| 81 | { |
||
| 82 | 'widgets': [ |
||
| 83 | { |
||
| 84 | 'decoratedText': { |
||
| 85 | 'text': '<b>Moses</b>', |
||
| 86 | 'startIcon': { |
||
| 87 | 'iconUrl': 'https://raw.githubusercontent.com/dyaskur/google-chat-shuffler/master/assets/1/1.gif', |
||
| 88 | }, |
||
| 89 | }, |
||
| 90 | }, |
||
| 91 | { |
||
| 92 | 'decoratedText': { |
||
| 93 | 'text': 'Ibrahim', |
||
| 94 | 'startIcon': { |
||
| 95 | 'iconUrl': 'https://upload.wikimedia.org/wikipedia/commons/3/38/Solid_white_bordered.png', |
||
| 96 | }, |
||
| 97 | }, |
||
| 98 | }, |
||
| 99 | { |
||
| 100 | 'decoratedText': { |
||
| 101 | 'text': 'Ismail', |
||
| 102 | 'startIcon': { |
||
| 103 | 'iconUrl': 'https://upload.wikimedia.org/wikipedia/commons/3/38/Solid_white_bordered.png', |
||
| 104 | }, |
||
| 105 | }, |
||
| 106 | }, |
||
| 107 | { |
||
| 108 | 'decoratedText': { |
||
| 109 | 'text': 'Zulkarnain', |
||
| 110 | 'startIcon': { |
||
| 111 | 'iconUrl': 'https://upload.wikimedia.org/wikipedia/commons/3/38/Solid_white_bordered.png', |
||
| 112 | }, |
||
| 113 | }, |
||
| 114 | }, |
||
| 115 | { |
||
| 116 | 'decoratedText': { |
||
| 117 | 'text': 'Sulaiman', |
||
| 118 | 'startIcon': { |
||
| 119 | 'iconUrl': 'https://upload.wikimedia.org/wikipedia/commons/3/38/Solid_white_bordered.png', |
||
| 120 | }, |
||
| 121 | }, |
||
| 122 | }, |
||
| 123 | ], |
||
| 124 | }, |
||
| 125 | ], |
||
| 126 | }; |
||
| 127 | expect(winnerSection).toStrictEqual(expected); |
||
| 128 | }); |
||
| 129 | |||
| 130 | test('buildInputForm test', () => { |
||
| 131 | const defaultValues = ['Ismail bin Ibrahim', 'Ishaq bin Ibrahim', 'Isa bin Mariyam']; |
||
| 132 | const form = buildInputForm(defaultValues); |
||
| 133 | expect(form).toEqual({ |
||
| 134 | 'fixedFooter': { |
||
| 135 | 'primaryButton': { |
||
| 136 | 'onClick': { |
||
| 137 | 'action': { |
||
| 138 | 'function': 'create_shuffle', |
||
| 139 | 'parameters': [], |
||
| 140 | }, |
||
| 141 | }, |
||
| 142 | 'text': 'Submit', |
||
| 143 | }, |
||
| 144 | }, |
||
| 145 | 'header': { |
||
| 146 | 'imageType': 'CIRCLE', |
||
| 147 | 'imageUrl': '', |
||
| 148 | 'subtitle': 'If the items are more than 32, the items will be randomly cut to 32', |
||
| 149 | 'title': 'Maximum item is 32.', |
||
| 150 | }, |
||
| 151 | 'sections': [ |
||
| 152 | { |
||
| 153 | 'header': 'Names', |
||
| 154 | 'widgets': [ |
||
| 155 | { |
||
| 156 | 'textInput': { |
||
| 157 | 'label': 'Please input the items', |
||
| 158 | 'name': 'items', |
||
| 159 | 'type': 'MULTIPLE_LINE', |
||
| 160 | 'value': 'Ismail bin Ibrahim\nIshaq bin Ibrahim\nIsa bin Mariyam', |
||
| 161 | }, |
||
| 162 | }, |
||
| 163 | ], |
||
| 164 | }, |
||
| 165 | ], |
||
| 166 | }); |
||
| 167 | }); |
||
| 168 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.