From 1bd8d6dc349ad6695648f9d145145ce9b01df64f Mon Sep 17 00:00:00 2001 From: Tommaso Casaburi Date: Mon, 1 Jun 2026 10:57:13 +0700 Subject: [PATCH] fix(flags): hide geolocation-only selectors on /int/ and /sp/ Country-only boards auto-publish geographic location flags without showing a flag dropdown, matching existing /bant/ behavior. --- .../post-form/__tests__/post-form.test.tsx | 25 +++++++++++++++++++ .../__tests__/reply-modal.test.tsx | 20 +++++++++++++-- .../__tests__/comment-flag-selection.test.ts | 20 +++++++++------ src/lib/comment-flag-selection.ts | 2 +- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/components/post-form/__tests__/post-form.test.tsx b/src/components/post-form/__tests__/post-form.test.tsx index 884f26fe..54b48024 100644 --- a/src/components/post-form/__tests__/post-form.test.tsx +++ b/src/components/post-form/__tests__/post-form.test.tsx @@ -444,6 +444,7 @@ describe('PostForm', () => { testState.directories = [ { address: 'music-posting.eth', features: {}, title: '/mu/ - Music' }, { address: 'politically-incorrect.bso', directoryCode: 'pol', features: { hasFlags: true }, title: '/pol/ - Politically Incorrect' }, + { address: 'sports-posting.bso', directoryCode: 'sp', features: { hasFlags: true }, title: '/sp/ - Sports' }, { address: 'random-nsfw.bso', features: {}, title: '/b/ - Random' }, { address: 'flash-posting.bso', @@ -699,6 +700,30 @@ describe('PostForm', () => { }); }); + it('publishes geographic location on /sp/ without showing a flag field', async () => { + testState.resolvedCommunityAddress = 'sports-posting.bso'; + + await renderPostForm('/sp'); + await clickByText(container, 'start_new_thread'); + + const table = container.querySelector('table'); + const flagSelect = table?.querySelector('select[aria-label="flag"]'); + const textarea = table?.querySelector('textarea'); + + expect(flagSelect).toBeNull(); + + await dispatchInput(textarea as HTMLTextAreaElement, 'sports post'); + await clickByText(table as HTMLTableElement, 'post'); + + expect(testState.publishPostMock).toHaveBeenCalledWith({ + content: 'sports post', + challengeRequest: { + challengeAnswers: ['bitsocial-flags:5chan:flag:country:auto'], + }, + flairs: [{ type: 'country', code: 'auto', text: 'flag:country:auto' }], + }); + }); + it('publishes selected political flags from the post form', async () => { testState.resolvedCommunityAddress = 'politically-incorrect.bso'; diff --git a/src/components/reply-modal/__tests__/reply-modal.test.tsx b/src/components/reply-modal/__tests__/reply-modal.test.tsx index a31c310c..b510d2a2 100644 --- a/src/components/reply-modal/__tests__/reply-modal.test.tsx +++ b/src/components/reply-modal/__tests__/reply-modal.test.tsx @@ -340,6 +340,18 @@ describe('ReplyModal', () => { features: { hasFlags: true }, title: '/bant/ - International/Random', }, + 'international-sfw.bso': { + address: 'international-sfw.bso', + directoryCode: 'int', + features: { hasFlags: true }, + title: '/int/ - International', + }, + 'sports-posting.bso': { + address: 'sports-posting.bso', + directoryCode: 'sp', + features: { hasFlags: true }, + title: '/sp/ - Sports', + }, 'random-nsfw.bso': { address: 'random-nsfw.bso', features: {}, @@ -494,8 +506,12 @@ describe('ReplyModal', () => { }); }); - it('publishes geographic location on /bant/ without showing a flag selector', async () => { - await renderReplyModal('/bant/thread/post-1', 'international-nsfw.bso'); + it.each([ + { boardPath: '/bant/thread/post-1', communityAddress: 'international-nsfw.bso' }, + { boardPath: '/int/thread/post-1', communityAddress: 'international-sfw.bso' }, + { boardPath: '/sp/thread/post-1', communityAddress: 'sports-posting.bso' }, + ])('publishes geographic location on country-only boards without showing a flag selector', async ({ boardPath, communityAddress }) => { + await renderReplyModal(boardPath, communityAddress); expect(container.querySelector('select[aria-label="flag"]')).toBeNull(); diff --git a/src/lib/__tests__/comment-flag-selection.test.ts b/src/lib/__tests__/comment-flag-selection.test.ts index 098f0c62..3d49eb9b 100644 --- a/src/lib/__tests__/comment-flag-selection.test.ts +++ b/src/lib/__tests__/comment-flag-selection.test.ts @@ -17,30 +17,34 @@ describe('comment-flag-selection', () => { expect(hasCommentFlagsForDirectory({ features: { hasFlags: true }, title: '/pol/ - Politically Incorrect' })).toBe(true); }); - it('uses geographic location as the default for country flag boards', () => { + it('uses geographic location as the default for other flag boards', () => { expect( getCommentFlagOptionsForDirectory({ - directoryCode: 'int', + directoryCode: 'fit', features: { hasFlags: true }, - title: '/int/ - International', + title: '/fit/ - Fitness', }), ).toEqual([{ label: 'Geographic Location', value: 'country:auto' }]); }); - it('does not expose a flag selector on /bant/ but still publishes geographic location', () => { + it.each([ + { directoryCode: 'bant', title: '/bant/ - International/Random' }, + { directoryCode: 'int', title: '/int/ - International' }, + { directoryCode: 'sp', title: '/sp/ - Sports' }, + ])('does not expose a flag selector on /$directoryCode/ but still publishes geographic location', ({ directoryCode, title }) => { expect( getCommentFlagOptionsForDirectory({ - directoryCode: 'bant', + directoryCode, features: { hasFlags: true }, - title: '/bant/ - International/Random', + title, }), ).toEqual([]); expect( getCommentFlagPublishOptionsForDirectory({ - directoryCode: 'bant', + directoryCode, features: { hasFlags: true }, - title: '/bant/ - International/Random', + title, }), ).toEqual({ challengeRequest: { diff --git a/src/lib/comment-flag-selection.ts b/src/lib/comment-flag-selection.ts index 871f0de6..2ba3d15d 100644 --- a/src/lib/comment-flag-selection.ts +++ b/src/lib/comment-flag-selection.ts @@ -38,7 +38,7 @@ const NO_FLAG_OPTION: CommentFlagSelectOption = { }; /** Boards that always publish geographic location without showing a flag selector. */ -const AUTO_GEOGRAPHIC_FLAG_DIRECTORY_CODES = new Set(['bant']); +const AUTO_GEOGRAPHIC_FLAG_DIRECTORY_CODES = new Set(['bant', 'int', 'sp']); const getDirectoryCode = (directory: Pick | undefined): string | undefined => { const directoryCode = directory?.directoryCode?.trim().toLowerCase();