|
| 1 | +import { Labels } from '../labels'; |
| 2 | + |
| 3 | +function createLabels(overrides: Partial<Record<keyof Labels, string>> = {}): Labels { |
| 4 | + const base = { |
| 5 | + branchManagementLauncherLabel: 'launch', |
| 6 | + bug: 'bug', |
| 7 | + bugfix: 'bugfix', |
| 8 | + hotfix: 'hotfix', |
| 9 | + enhancement: 'enhancement', |
| 10 | + feature: 'feature', |
| 11 | + release: 'release', |
| 12 | + question: 'question', |
| 13 | + help: 'help', |
| 14 | + deploy: 'deploy', |
| 15 | + deployed: 'deployed', |
| 16 | + docs: 'docs', |
| 17 | + documentation: 'documentation', |
| 18 | + chore: 'chore', |
| 19 | + maintenance: 'maintenance', |
| 20 | + sizeXxl: 'size/xxl', |
| 21 | + sizeXl: 'size/xl', |
| 22 | + sizeL: 'size/l', |
| 23 | + sizeM: 'size/m', |
| 24 | + sizeS: 'size/s', |
| 25 | + sizeXs: 'size/xs', |
| 26 | + priorityHigh: 'priority/high', |
| 27 | + priorityMedium: 'priority/medium', |
| 28 | + priorityLow: 'priority/low', |
| 29 | + priorityNone: 'priority/none', |
| 30 | + }; |
| 31 | + const l = new Labels( |
| 32 | + base.branchManagementLauncherLabel, |
| 33 | + base.bug, |
| 34 | + base.bugfix, |
| 35 | + base.hotfix, |
| 36 | + base.enhancement, |
| 37 | + base.feature, |
| 38 | + base.release, |
| 39 | + base.question, |
| 40 | + base.help, |
| 41 | + base.deploy, |
| 42 | + base.deployed, |
| 43 | + base.docs, |
| 44 | + base.documentation, |
| 45 | + base.chore, |
| 46 | + base.maintenance, |
| 47 | + base.priorityHigh, |
| 48 | + base.priorityMedium, |
| 49 | + base.priorityLow, |
| 50 | + base.priorityNone, |
| 51 | + base.sizeXxl, |
| 52 | + base.sizeXl, |
| 53 | + base.sizeL, |
| 54 | + base.sizeM, |
| 55 | + base.sizeS, |
| 56 | + base.sizeXs |
| 57 | + ); |
| 58 | + Object.assign(l, overrides); |
| 59 | + return l; |
| 60 | +} |
| 61 | + |
| 62 | +describe('Labels', () => { |
| 63 | + it('isMandatoryBranchedLabel is true when isHotfix or isRelease', () => { |
| 64 | + const l = createLabels(); |
| 65 | + l.currentIssueLabels = []; |
| 66 | + expect(l.isMandatoryBranchedLabel).toBe(false); |
| 67 | + l.currentIssueLabels = [l.hotfix]; |
| 68 | + expect(l.isMandatoryBranchedLabel).toBe(true); |
| 69 | + l.currentIssueLabels = [l.release]; |
| 70 | + expect(l.isMandatoryBranchedLabel).toBe(true); |
| 71 | + }); |
| 72 | + |
| 73 | + it('containsBranchedLabel reflects branchManagementLauncherLabel in currentIssueLabels', () => { |
| 74 | + const l = createLabels(); |
| 75 | + l.currentIssueLabels = []; |
| 76 | + expect(l.containsBranchedLabel).toBe(false); |
| 77 | + l.currentIssueLabels = [l.branchManagementLauncherLabel]; |
| 78 | + expect(l.containsBranchedLabel).toBe(true); |
| 79 | + }); |
| 80 | + |
| 81 | + it('isDeploy and isDeployed from currentIssueLabels', () => { |
| 82 | + const l = createLabels(); |
| 83 | + l.currentIssueLabels = [l.deploy]; |
| 84 | + expect(l.isDeploy).toBe(true); |
| 85 | + expect(l.isDeployed).toBe(false); |
| 86 | + l.currentIssueLabels = [l.deployed]; |
| 87 | + expect(l.isDeploy).toBe(false); |
| 88 | + expect(l.isDeployed).toBe(true); |
| 89 | + }); |
| 90 | + |
| 91 | + it('isHelp and isQuestion from currentIssueLabels', () => { |
| 92 | + const l = createLabels(); |
| 93 | + l.currentIssueLabels = [l.help]; |
| 94 | + expect(l.isHelp).toBe(true); |
| 95 | + expect(l.isQuestion).toBe(false); |
| 96 | + l.currentIssueLabels = [l.question]; |
| 97 | + expect(l.isQuestion).toBe(true); |
| 98 | + }); |
| 99 | + |
| 100 | + it('isFeature, isEnhancement, isBugfix, isBug, isHotfix, isRelease', () => { |
| 101 | + const l = createLabels(); |
| 102 | + l.currentIssueLabels = [l.feature]; |
| 103 | + expect(l.isFeature).toBe(true); |
| 104 | + l.currentIssueLabels = [l.enhancement]; |
| 105 | + expect(l.isEnhancement).toBe(true); |
| 106 | + l.currentIssueLabels = [l.bugfix]; |
| 107 | + expect(l.isBugfix).toBe(true); |
| 108 | + l.currentIssueLabels = [l.bug]; |
| 109 | + expect(l.isBug).toBe(true); |
| 110 | + l.currentIssueLabels = [l.hotfix]; |
| 111 | + expect(l.isHotfix).toBe(true); |
| 112 | + l.currentIssueLabels = [l.release]; |
| 113 | + expect(l.isRelease).toBe(true); |
| 114 | + }); |
| 115 | + |
| 116 | + it('isDocs, isDocumentation, isChore, isMaintenance', () => { |
| 117 | + const l = createLabels(); |
| 118 | + l.currentIssueLabels = [l.docs]; |
| 119 | + expect(l.isDocs).toBe(true); |
| 120 | + l.currentIssueLabels = [l.documentation]; |
| 121 | + expect(l.isDocumentation).toBe(true); |
| 122 | + l.currentIssueLabels = [l.chore]; |
| 123 | + expect(l.isChore).toBe(true); |
| 124 | + l.currentIssueLabels = [l.maintenance]; |
| 125 | + expect(l.isMaintenance).toBe(true); |
| 126 | + }); |
| 127 | + |
| 128 | + it('sizedLabelOnIssue returns first matching size label', () => { |
| 129 | + const l = createLabels(); |
| 130 | + l.currentIssueLabels = [l.sizeM]; |
| 131 | + expect(l.sizedLabelOnIssue).toBe(l.sizeM); |
| 132 | + l.currentIssueLabels = [l.sizeXxl, l.sizeM]; |
| 133 | + expect(l.sizedLabelOnIssue).toBe(l.sizeXxl); |
| 134 | + l.currentIssueLabels = []; |
| 135 | + expect(l.sizedLabelOnIssue).toBeUndefined(); |
| 136 | + }); |
| 137 | + |
| 138 | + it('sizedLabelOnPullRequest returns first matching size label', () => { |
| 139 | + const l = createLabels(); |
| 140 | + l.currentPullRequestLabels = [l.sizeS]; |
| 141 | + expect(l.sizedLabelOnPullRequest).toBe(l.sizeS); |
| 142 | + l.currentPullRequestLabels = []; |
| 143 | + expect(l.sizedLabelOnPullRequest).toBeUndefined(); |
| 144 | + }); |
| 145 | + |
| 146 | + it('isIssueSized and isPullRequestSized', () => { |
| 147 | + const l = createLabels(); |
| 148 | + l.currentIssueLabels = []; |
| 149 | + l.currentPullRequestLabels = []; |
| 150 | + expect(l.isIssueSized).toBe(false); |
| 151 | + expect(l.isPullRequestSized).toBe(false); |
| 152 | + l.currentIssueLabels = [l.sizeM]; |
| 153 | + expect(l.isIssueSized).toBe(true); |
| 154 | + l.currentPullRequestLabels = [l.sizeL]; |
| 155 | + expect(l.isPullRequestSized).toBe(true); |
| 156 | + }); |
| 157 | + |
| 158 | + it('sizeLabels and priorityLabels return arrays', () => { |
| 159 | + const l = createLabels(); |
| 160 | + expect(l.sizeLabels).toEqual([l.sizeXxl, l.sizeXl, l.sizeL, l.sizeM, l.sizeS, l.sizeXs]); |
| 161 | + expect(l.priorityLabels).toEqual([l.priorityHigh, l.priorityMedium, l.priorityLow, l.priorityNone]); |
| 162 | + }); |
| 163 | + |
| 164 | + it('priorityLabelOnIssue and priorityLabelOnPullRequest', () => { |
| 165 | + const l = createLabels(); |
| 166 | + l.currentIssueLabels = [l.priorityHigh]; |
| 167 | + l.currentPullRequestLabels = [l.priorityLow]; |
| 168 | + expect(l.priorityLabelOnIssue).toBe(l.priorityHigh); |
| 169 | + expect(l.priorityLabelOnPullRequest).toBe(l.priorityLow); |
| 170 | + l.currentIssueLabels = []; |
| 171 | + expect(l.priorityLabelOnIssue).toBeUndefined(); |
| 172 | + }); |
| 173 | + |
| 174 | + it('priorityLabelOnIssueProcessable and priorityLabelOnPullRequestProcessable', () => { |
| 175 | + const l = createLabels(); |
| 176 | + l.currentIssueLabels = [l.priorityNone]; |
| 177 | + expect(l.priorityLabelOnIssueProcessable).toBe(false); |
| 178 | + l.currentIssueLabels = [l.priorityHigh]; |
| 179 | + expect(l.priorityLabelOnIssueProcessable).toBe(true); |
| 180 | + l.currentPullRequestLabels = [l.priorityMedium]; |
| 181 | + expect(l.priorityLabelOnPullRequestProcessable).toBe(true); |
| 182 | + }); |
| 183 | + |
| 184 | + it('isIssuePrioritized and isPullRequestPrioritized', () => { |
| 185 | + const l = createLabels(); |
| 186 | + l.currentIssueLabels = [l.priorityHigh]; |
| 187 | + expect(l.isIssuePrioritized).toBe(true); |
| 188 | + l.currentIssueLabels = [l.priorityNone]; |
| 189 | + expect(l.isIssuePrioritized).toBe(false); |
| 190 | + l.currentPullRequestLabels = [l.priorityLow]; |
| 191 | + expect(l.isPullRequestPrioritized).toBe(true); |
| 192 | + }); |
| 193 | +}); |
0 commit comments