Skip to content

Commit

Permalink
Use ellipsis when many versions returned for [ModrinthGameVersions] (b…
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB authored Jul 13, 2024
1 parent 1585d15 commit 67deddb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions services/modrinth/modrinth-game-versions.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export default class ModrinthGameVersions extends BaseModrinthService {
static defaultBadgeData = { label: 'game versions' }

static render({ versions }) {
if (versions.length > 5) {
return {
message: `${versions[0]} | ${versions[1]} | ... | ${versions[versions.length - 2]} | ${versions[versions.length - 1]}`,
color: 'blue',
}
}
return {
message: versions.join(' | '),
color: 'blue',
Expand Down
22 changes: 22 additions & 0 deletions services/modrinth/modrinth-game-versions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test, given } from 'sazerac'
import ModrinthGameVersions from './modrinth-game-versions.service.js'

describe('render function', function () {
it('displays up to five versions', async function () {
test(ModrinthGameVersions.render, () => {
given({ versions: ['1.1', '1.2', '1.3', '1.4', '1.5'] }).expect({
message: '1.1 | 1.2 | 1.3 | 1.4 | 1.5',
color: 'blue',
})
})
})

it('uses ellipsis for six versions or more', async function () {
test(ModrinthGameVersions.render, () => {
given({ versions: ['1.1', '1.2', '1.3', '1.4', '1.5', '1.6'] }).expect({
message: '1.1 | 1.2 | ... | 1.5 | 1.6',
color: 'blue',
})
})
})
})
8 changes: 7 additions & 1 deletion services/modrinth/modrinth-game-versions.tester.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Joi from 'joi'
import { createServiceTester } from '../tester.js'
import { withRegex } from '../test-validators.js'

Expand All @@ -7,7 +8,12 @@ t.create('Game Versions')
.get('/AANobbMI.json')
.expectBadge({
label: 'game versions',
message: withRegex(/\d+\.\d+(\.\d+)?( \| )?/),
message: Joi.alternatives().try(
withRegex(/^(\d+\.\d+(\.\d+)?( \| )?)+$/),
withRegex(
/^\d+\.\d+(\.\d+)? \| \d+\.\d+(\.\d+)? \| \.\.\. \| \d+\.\d+(\.\d+)? \| \d+\.\d+(\.\d+)?$/,
),
),
})

t.create('Game Versions (not found)')
Expand Down

0 comments on commit 67deddb

Please sign in to comment.