mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 02:56:10 +00:00
test: keep the bringer and panel width changes within the lint and RTL ratchets
The bringer tests read their items through a small type instead of any, the panel hook names its two ceilings after the panels rather than the sides, and the stored-width test runs on a window wide enough for the map's share.
This commit is contained in:
@@ -82,15 +82,15 @@ export function useResizablePanels() {
|
||||
const shownRight = clampWidth(rightWidth, resizeMaxRight)
|
||||
const resizeMaxLeft = Math.max(MIN_SIDEBAR, room - (rightHidden ? 0 : shownRight))
|
||||
// The drag listeners are bound once, so they read the live ceilings from here.
|
||||
const maxRef = useRef({ left: resizeMaxLeft, right: resizeMaxRight })
|
||||
useEffect(() => { maxRef.current = { left: resizeMaxLeft, right: resizeMaxRight } }, [resizeMaxLeft, resizeMaxRight])
|
||||
const maxRef = useRef({ dayPlan: resizeMaxLeft, places: resizeMaxRight })
|
||||
useEffect(() => { maxRef.current = { dayPlan: resizeMaxLeft, places: resizeMaxRight } }, [resizeMaxLeft, resizeMaxRight])
|
||||
|
||||
// A mouse drags through mousemove; a finger on a tablet sends touch events and
|
||||
// never a mousemove, which is why the handles used to be dead on an iPad (#1012).
|
||||
useEffect(() => {
|
||||
const moveTo = (clientX: number) => {
|
||||
if (isResizingLeft.current) setLeftWidth(remember('sidebarLeftWidth', clampWidth(clientX - 10, maxRef.current.left)))
|
||||
if (isResizingRight.current) setRightWidth(remember('sidebarRightWidth', clampWidth(window.innerWidth - clientX - 10, maxRef.current.right)))
|
||||
if (isResizingLeft.current) setLeftWidth(remember('sidebarLeftWidth', clampWidth(clientX - 10, maxRef.current.dayPlan)))
|
||||
if (isResizingRight.current) setRightWidth(remember('sidebarRightWidth', clampWidth(window.innerWidth - clientX - 10, maxRef.current.places)))
|
||||
}
|
||||
const onMove = (e: MouseEvent) => moveTo(e.clientX)
|
||||
const onTouchMove = (e: TouchEvent) => {
|
||||
|
||||
@@ -50,6 +50,8 @@ describe('useResizablePanels', () => {
|
||||
});
|
||||
|
||||
it('FE-HOOK-PANELS-004: rightWidth loaded from localStorage when set', () => {
|
||||
// Wide enough that the map's share leaves the stored width alone.
|
||||
setViewport(1440, false);
|
||||
localStorage.setItem('sidebarRightWidth', '350');
|
||||
const { result } = renderHook(() => useResizablePanels());
|
||||
expect(result.current.rightWidth).toBe(350);
|
||||
|
||||
@@ -266,7 +266,7 @@ describe('Three-tier packing sharing (#858)', () => {
|
||||
.set('Cookie', authCookie(owner.id))
|
||||
.send({ user_id: helper.id });
|
||||
expect(assigned.status).toBe(201);
|
||||
expect(assigned.body.item.contributors.map((c: any) => c.user_id)).toEqual([helper.id]);
|
||||
expect(assigned.body.item.contributors.map((c: { user_id: number }) => c.user_id)).toEqual([helper.id]);
|
||||
|
||||
const outsider = await request(app)
|
||||
.post(`/api/trips/${trip.id}/packing/${id}/contributors`)
|
||||
@@ -285,7 +285,7 @@ describe('Three-tier packing sharing (#858)', () => {
|
||||
.set('Cookie', authCookie(helper.id));
|
||||
expect(ownerOff.status).toBe(200);
|
||||
expect(ownerOff.body.item.owner_id).toBeNull();
|
||||
expect(ownerOff.body.item.contributors.map((c: any) => c.user_id)).toEqual([helper.id]);
|
||||
expect(ownerOff.body.item.contributors.map((c: { user_id: number }) => c.user_id)).toEqual([helper.id]);
|
||||
});
|
||||
|
||||
it('PACK-3T-005 — sharing can only be changed by the owner', async () => {
|
||||
|
||||
@@ -78,6 +78,15 @@ async function tripItems(tripId: number) {
|
||||
}
|
||||
|
||||
/** The stored item; fails the case when it is gone. */
|
||||
/** What the bringer tests read off an item the service hands back (#3098). */
|
||||
type BroughtItem = {
|
||||
id: number;
|
||||
is_private: number;
|
||||
owner_id: number | null;
|
||||
owner_username: string | null;
|
||||
contributors: { user_id: number }[];
|
||||
};
|
||||
|
||||
async function itemRow(id: number) {
|
||||
const row = await findRow(await orm(), PackingItems, { id });
|
||||
if (!row) throw new Error(`no packing item ${id}`);
|
||||
@@ -734,10 +743,14 @@ describe('three-tier packing sharing (#858)', () => {
|
||||
const { user: stranger } = createUser(testDb);
|
||||
const trip = createTrip(testDb, owner.id);
|
||||
addTripMember(testDb, trip.id, friend.id);
|
||||
const common = (await svc.createItem(trip.id, { name: 'Tent', visibility: 'common' }, owner.id)) as any;
|
||||
const common = (await svc.createItem(
|
||||
trip.id,
|
||||
{ name: 'Tent', visibility: 'common' },
|
||||
owner.id,
|
||||
)) as unknown as BroughtItem;
|
||||
|
||||
const assigned = (await svc.addContributor(trip.id, common.id, friend.id, owner.id)) as any;
|
||||
expect(assigned.contributors.map((c: any) => c.user_id)).toEqual([friend.id]);
|
||||
const assigned = (await svc.addContributor(trip.id, common.id, friend.id, owner.id)) as unknown as BroughtItem;
|
||||
expect(assigned.contributors.map((c: { user_id: number }) => c.user_id)).toEqual([friend.id]);
|
||||
expect(await svc.addContributor(trip.id, common.id, stranger.id, owner.id)).toBeNull();
|
||||
});
|
||||
|
||||
@@ -747,15 +760,19 @@ describe('three-tier packing sharing (#858)', () => {
|
||||
const trip = createTrip(testDb, owner.id);
|
||||
addTripMember(testDb, trip.id, friend.id);
|
||||
// Personal first, then back to the shared list: the owner stays on as its bringer.
|
||||
const item = (await svc.createItem(trip.id, { name: 'Stove', visibility: 'personal' }, owner.id)) as any;
|
||||
const item = (await svc.createItem(
|
||||
trip.id,
|
||||
{ name: 'Stove', visibility: 'personal' },
|
||||
owner.id,
|
||||
)) as unknown as BroughtItem;
|
||||
await svc.setItemSharing(trip.id, item.id, owner.id, 'common', []);
|
||||
await svc.addContributor(trip.id, item.id, friend.id, friend.id);
|
||||
expect((await itemRow(item.id)).owner_id).toBe(owner.id);
|
||||
|
||||
const after = (await svc.removeContributor(trip.id, item.id, owner.id, friend.id)) as any;
|
||||
const after = (await svc.removeContributor(trip.id, item.id, owner.id, friend.id)) as unknown as BroughtItem;
|
||||
expect(after.owner_id).toBeNull();
|
||||
expect(after.owner_username).toBeNull();
|
||||
expect(after.contributors.map((c: any) => c.user_id)).toEqual([friend.id]);
|
||||
expect(after.contributors.map((c: { user_id: number }) => c.user_id)).toEqual([friend.id]);
|
||||
expect(after.is_private).toBe(0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user