Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { tabsSlice } from './tabs';
const path = require('path');
const { tabsSlice } = require('./tabs');

const { migrateCollectionTabsToYml } = tabsSlice.actions;
const { migrateCollectionTabsToYml, restoreTabs } = tabsSlice.actions;
const reducer = tabsSlice.reducer;

const p = (...parts) => path.join(...parts);

const makeState = () => ({
tabs: [
{ uid: 'r1', collectionUid: 'col1', type: 'http-request', pathname: '/c/ping.bru' },
{ uid: 'r2', collectionUid: 'col1', type: 'http-request', pathname: '/c/api/users.bru' },
{ uid: 'fs1', collectionUid: 'col1', type: 'folder-settings', pathname: '/c/api' },
{ uid: 'r1', collectionUid: 'col1', type: 'http-request', pathname: p('c', 'ping.bru') },
{ uid: 'r2', collectionUid: 'col1', type: 'http-request', pathname: p('c', 'api', 'users.bru') },
{ uid: 'fs1', collectionUid: 'col1', type: 'folder-settings', pathname: p('c', 'api') },
{ uid: 'cs1', collectionUid: 'col1', type: 'collection-settings' },
{ uid: 'other', collectionUid: 'col2', type: 'http-request', pathname: '/c2/req.bru' }
{ uid: 'other', collectionUid: 'col2', type: 'http-request', pathname: p('c2', 'req.bru') }
],
activeTabUid: 'r1'
});
Expand All @@ -19,16 +22,16 @@ describe('migrateCollectionTabsToYml', () => {
const next = reducer(makeState(), migrateCollectionTabsToYml({ collectionUid: 'col1' }));
const byUid = (uid) => next.tabs.find((t) => t.uid === uid);

expect(byUid('r1').pathname).toBe('/c/ping.yml');
expect(byUid('r2').pathname).toBe('/c/api/users.yml');
expect(byUid('other').pathname).toBe('/c2/req.bru');
expect(byUid('r1').pathname).toBe(p('c', 'ping.yml'));
expect(byUid('r2').pathname).toBe(p('c', 'api', 'users.yml'));
expect(byUid('other').pathname).toBe(p('c2', 'req.bru'));
});

it('leaves folder-settings (directory) paths and tabs without a pathname untouched', () => {
const next = reducer(makeState(), migrateCollectionTabsToYml({ collectionUid: 'col1' }));
const byUid = (uid) => next.tabs.find((t) => t.uid === uid);

expect(byUid('fs1').pathname).toBe('/c/api');
expect(byUid('fs1').pathname).toBe(p('c', 'api'));
expect(byUid('cs1').pathname).toBeUndefined();
});

Expand All @@ -38,3 +41,22 @@ describe('migrateCollectionTabsToYml', () => {
expect(next.activeTabUid).toBe('r1');
});
});

describe('restoreTabs', () => {
it('skips remapped .yml request paths when reopening a bru collection', () => {
const next = reducer(
{ tabs: [], activeTabUid: null, recentlyClosedTabs: [] },
restoreTabs({
collection: { uid: 'col1', format: 'bru', items: [] },
tabs: [
{ type: 'http-request', accessor: 'pathname', pathname: p('c', 'ping.yml'), permanent: true },
{ type: 'collection-settings', accessor: 'type', permanent: true },
{ type: 'folder-settings', accessor: 'pathname', pathname: p('c', 'api'), permanent: true }
],
activeTab: null
})
);

expect(next.tabs.map((t) => t.type)).toEqual(['collection-settings', 'folder-settings']);
});
});
7 changes: 7 additions & 0 deletions packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,14 @@ export const tabsSlice = createSlice({
state.activeTabUid = null;
}

// Drop request tabs remapped by bru↔yml migrate that no longer match collection format
const staleExt = collection.format === 'yml' ? /\.bru$/i : /\.ya?ml$/i;

(snapshotTabs || []).forEach((snapshotTab) => {
if (typeof snapshotTab.pathname === 'string' && staleExt.test(snapshotTab.pathname)) {
return;
}

const tab = deserializeTab(snapshotTab, collection);
state.tabs.push(tab);

Expand Down
Loading