1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00

Use ellipsis when many versions returned for [ModrinthGameVersions] (#10350)

This commit is contained in:
Pierre-Yves Bigourdan 2024-07-13 20:58:11 +02:00 committed by GitHub
parent 1585d157c1
commit 67deddb8a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 1 deletions

View File

@ -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',

View File

@ -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',
})
})
})
})

View File

@ -1,3 +1,4 @@
import Joi from 'joi'
import { createServiceTester } from '../tester.js'
import { withRegex } from '../test-validators.js'
@ -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)')