mirror of
https://github.com/mastodon/mastodon.git
synced 2026-09-27 15:28:21 -05:00
Refactor compose path detection into a reusable utility function and add related tests (#40663)
This commit is contained in:
@@ -10,6 +10,7 @@ import { tagHistory } from '@/mastodon/settings';
|
||||
import { emojiMartSearch } from '@/mastodon/features/emoji/picker';
|
||||
|
||||
import { showAlert, showAlertForError } from './alerts';
|
||||
import { isStandaloneComposePath } from './compose_path';
|
||||
import { emojiUse } from './emojis';
|
||||
import { importFetchedAccounts, importFetchedStatus } from './importer';
|
||||
import { openModal } from './modal';
|
||||
@@ -278,7 +279,7 @@ export function submitCompose(successCallback) {
|
||||
'Idempotency-Key': getState().getIn(['compose', 'idempotencyKey']),
|
||||
},
|
||||
}).then(function (response) {
|
||||
if ((browserHistory.location.pathname === '/publish' || browserHistory.location.pathname === '/statuses/new') && window.history.state) {
|
||||
if (isStandaloneComposePath(browserHistory.location.pathname) && window.history.state) {
|
||||
browserHistory.goBack();
|
||||
}
|
||||
|
||||
|
||||
35
app/javascript/mastodon/actions/compose_path.test.ts
Normal file
35
app/javascript/mastodon/actions/compose_path.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { isStandaloneComposePath } from './compose_path';
|
||||
|
||||
describe('isStandaloneComposePath', () => {
|
||||
test('returns true for /publish', () => {
|
||||
expect(isStandaloneComposePath('/publish')).toBe(true);
|
||||
});
|
||||
|
||||
test('returns true for /statuses/new', () => {
|
||||
expect(isStandaloneComposePath('/statuses/new')).toBe(true);
|
||||
});
|
||||
|
||||
test('returns true for /deck/publish', () => {
|
||||
expect(isStandaloneComposePath('/deck/publish')).toBe(true);
|
||||
});
|
||||
|
||||
test('returns true for /deck/statuses/new', () => {
|
||||
expect(isStandaloneComposePath('/deck/statuses/new')).toBe(true);
|
||||
});
|
||||
|
||||
test('returns false for /deck/home', () => {
|
||||
expect(isStandaloneComposePath('/deck/home')).toBe(false);
|
||||
});
|
||||
|
||||
test('returns false for /home', () => {
|
||||
expect(isStandaloneComposePath('/home')).toBe(false);
|
||||
});
|
||||
|
||||
test('returns false for /deck', () => {
|
||||
expect(isStandaloneComposePath('/deck')).toBe(false);
|
||||
});
|
||||
|
||||
test('returns false for /deck/publish/extra', () => {
|
||||
expect(isStandaloneComposePath('/deck/publish/extra')).toBe(false);
|
||||
});
|
||||
});
|
||||
7
app/javascript/mastodon/actions/compose_path.ts
Normal file
7
app/javascript/mastodon/actions/compose_path.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export function isStandaloneComposePath(pathname: string): boolean {
|
||||
const normalized = pathname.startsWith('/deck/')
|
||||
? pathname.slice('/deck'.length)
|
||||
: pathname;
|
||||
|
||||
return normalized === '/publish' || normalized === '/statuses/new';
|
||||
}
|
||||
Reference in New Issue
Block a user