mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
125 lines
5.1 KiB
TypeScript
125 lines
5.1 KiB
TypeScript
// FE-COMP-LIBPAIRS-001 to FE-COMP-LIBPAIRS-012
|
|
import type { PlacesLibraryDetailResponse } from '@trek/shared';
|
|
|
|
import {
|
|
bothOrigins,
|
|
libraryDetail,
|
|
libraryEntry,
|
|
libraryInfo,
|
|
listDetail,
|
|
listOrigin,
|
|
tripDetail,
|
|
tripOrigin,
|
|
} from '../../../tests/helpers/placesLibrary';
|
|
import { libraryCarryOptions, originPairs, saveDraftOf } from './libraryPairs';
|
|
|
|
describe('originPairs', () => {
|
|
it('FE-COMP-LIBPAIRS-001: nothing open gives nothing', () => {
|
|
expect(originPairs(null)).toEqual({ trips: [], lists: [], description: undefined });
|
|
});
|
|
|
|
it('FE-COMP-LIBPAIRS-002: a response with no entry gives nothing', () => {
|
|
const data = { entry: null, details: [] } as unknown as PlacesLibraryDetailResponse;
|
|
expect(originPairs(data)).toEqual({ trips: [], lists: [], description: undefined });
|
|
});
|
|
|
|
it('FE-COMP-LIBPAIRS-003: splits the origins into trips and lists, each beside its detail', () => {
|
|
const data = bothOrigins();
|
|
const { trips, lists } = originPairs(data);
|
|
expect(trips).toEqual([{ origin: data.entry?.origins[0], detail: data.details[0] }]);
|
|
expect(lists).toEqual([{ origin: data.entry?.origins[1], detail: data.details[1] }]);
|
|
});
|
|
|
|
it('FE-COMP-LIBPAIRS-004: keeps several of one kind in the order of the origins', () => {
|
|
const entry = libraryEntry({
|
|
origins: [tripOrigin({ place_id: 1 }), listOrigin({ collection_place_id: 20 }), tripOrigin({ place_id: 2 })],
|
|
});
|
|
const data = libraryDetail(entry, [
|
|
tripDetail({ place_id: 1 }),
|
|
listDetail({ collection_place_id: 20 }),
|
|
tripDetail({ place_id: 2 }),
|
|
]);
|
|
const { trips, lists } = originPairs(data);
|
|
expect(trips.map((p) => p.origin.place_id)).toEqual([1, 2]);
|
|
expect(lists.map((p) => p.origin.collection_place_id)).toEqual([20]);
|
|
});
|
|
|
|
it('FE-COMP-LIBPAIRS-005: an origin without a detail is left out', () => {
|
|
const entry = libraryEntry({ origins: [tripOrigin(), listOrigin()] });
|
|
const { trips, lists } = originPairs(libraryDetail(entry, [tripDetail()]));
|
|
expect(trips).toHaveLength(1);
|
|
expect(lists).toEqual([]);
|
|
});
|
|
|
|
it('FE-COMP-LIBPAIRS-006: an origin whose detail is of the other kind is left out', () => {
|
|
const entry = libraryEntry({ origins: [tripOrigin()] });
|
|
const { trips, lists } = originPairs(libraryDetail(entry, [listDetail()]));
|
|
expect(trips).toEqual([]);
|
|
expect(lists).toEqual([]);
|
|
});
|
|
|
|
it('FE-COMP-LIBPAIRS-007: the description is the first one that is not empty or blank', () => {
|
|
const entry = libraryEntry({ origins: [tripOrigin(), listOrigin(), listOrigin({ collection_place_id: 901 })] });
|
|
const data = libraryDetail(entry, [
|
|
tripDetail({ info: libraryInfo({ description: ' ' }) }),
|
|
listDetail({ info: libraryInfo({ description: 'Ancient arena' }) }),
|
|
listDetail({ collection_place_id: 901, info: libraryInfo({ description: 'Another text' }) }),
|
|
]);
|
|
expect(originPairs(data).description).toBe('Ancient arena');
|
|
});
|
|
|
|
it('FE-COMP-LIBPAIRS-008: no description anywhere leaves it undefined', () => {
|
|
expect(originPairs(bothOrigins()).description).toBeUndefined();
|
|
});
|
|
|
|
it('FE-COMP-LIBPAIRS-009: a trip place goes to the save dialog with what the trip keeps and the category', () => {
|
|
const origin = tripOrigin({ trip_id: 5, place_id: 8 });
|
|
const detail = tripDetail({ place_id: 8, info: libraryInfo({ name: 'Arena', website: 'https://arena.example' }) });
|
|
const draft = saveDraftOf(origin, detail, 3);
|
|
expect(draft).toMatchObject({
|
|
name: 'Arena',
|
|
source_trip_id: 5,
|
|
source_place_id: 8,
|
|
category_id: 3,
|
|
website: 'https://arena.example',
|
|
});
|
|
expect(saveDraftOf(origin, detail, undefined).category_id).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('libraryCarryOptions', () => {
|
|
it('FE-COMP-LIBPAIRS-010: nothing to carry without an open entry or a picked saved place', () => {
|
|
expect(libraryCarryOptions(null, 900)).toBeUndefined();
|
|
expect(libraryCarryOptions(bothOrigins(), null)).toBeUndefined();
|
|
});
|
|
|
|
it("FE-COMP-LIBPAIRS-011: offers the saved place's notes and labels and the reader's own tags", () => {
|
|
const entry = libraryEntry({
|
|
origins: [tripOrigin(), listOrigin()],
|
|
tags: [{ id: 3, name: 'Coffee', color: '#f97316' }],
|
|
});
|
|
const data = libraryDetail(entry, [
|
|
tripDetail(),
|
|
listDetail({ notes: ' Go early ', labels: [{ id: 7, name: 'Late', color: null }] }),
|
|
]);
|
|
expect(libraryCarryOptions(data, 900)).toEqual({
|
|
hasNotes: true,
|
|
tags: [{ id: 7, name: 'Late', color: null }],
|
|
personalTags: [{ id: 3, name: 'Coffee', color: '#f97316' }],
|
|
});
|
|
});
|
|
|
|
it('FE-COMP-LIBPAIRS-012: blank notes, an unknown saved place and an entry without tags offer nothing', () => {
|
|
const entry = libraryEntry({ origins: [listOrigin()] });
|
|
const data = libraryDetail(entry, [
|
|
listDetail({ notes: ' ', labels: [{ id: 7, name: 'Late', color: '#123456' }] }),
|
|
]);
|
|
expect(libraryCarryOptions(data, 900)).toEqual({
|
|
hasNotes: false,
|
|
tags: [{ id: 7, name: 'Late', color: '#123456' }],
|
|
personalTags: [],
|
|
});
|
|
expect(libraryCarryOptions(data, 12345)).toEqual({ hasNotes: false, tags: [], personalTags: [] });
|
|
});
|
|
});
|