Skip to content

Commit

Permalink
MajorKeys: Fix wikimedia_common keys (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvaclavik authored Feb 13, 2025
1 parent ea8a372 commit 8915309
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/components/FeaturePanel/Climbing/utils/__tests__/photo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { getNextWikimediaCommonsIndex } from '../photo';
import { FeatureTags } from '../../../../../services/types';

describe('getNextWikimediaCommonsIndex', () => {
it('should return 0 when there are no wikimedia_commons keys', () => {
const tags: FeatureTags = {};
expect(getNextWikimediaCommonsIndex(tags)).toBe(0);
});

it('should return 1 when there is one wikimedia_commons key', () => {
const tags: FeatureTags = { wikimedia_commons: 'File:example.jpg' };
expect(getNextWikimediaCommonsIndex(tags)).toBe(1);
});

it('should return the next index when there are multiple wikimedia_commons keys', () => {
const tags: FeatureTags = {
wikimedia_commons: 'File:example1.jpg',
'wikimedia_commons:2': 'File:example2.jpg',
};
expect(getNextWikimediaCommonsIndex(tags)).toBe(2);
});

it('should handle non-numeric wikimedia_commons keys correctly', () => {
const tags: FeatureTags = {
wikimedia_commons: 'File:example1.jpg',
'wikimedia_commons:path': 'some/path',
};
expect(getNextWikimediaCommonsIndex(tags)).toBe(1);
});

it('should handle gaps in the sequence of wikimedia_commons keys', () => {
const tags: FeatureTags = {
wikimedia_commons: 'File:example1.jpg',
'wikimedia_commons:3': 'File:example3.jpg',
};
expect(getNextWikimediaCommonsIndex(tags)).toBe(3);
});
});
4 changes: 3 additions & 1 deletion src/components/FeaturePanel/Climbing/utils/photo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export const getWikimediaCommonsPhotoPathKeys = (tags: FeatureTags) =>

export const getWikimediaCommonsTags = (tags: FeatureTags) => {
return naturalSort(
Object.entries(tags).filter(([key]) => isWikimediaCommons[key]),
Object.entries(tags).filter(([key]) => {
return isWikimediaCommons(key);
}),
(item) => item[0],
);
};
Expand Down

0 comments on commit 8915309

Please sign in to comment.