Skip to content

Commit

Permalink
Use the new URL in the browse list for pasted items. (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
bosschaert authored Jul 9, 2024
1 parent 673f5f4 commit a803d77
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion blocks/browse/da-browse/da-browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ export default class DaBrowse extends LitElement {
const opts = { method: 'POST', body: formData };
await daFetch(`${DA_ORIGIN}/copy${item.path}`, opts);
item.isChecked = false;
this._listItems.unshift(item);

const pastedItem = { ...item, path: item.destination, isChecked: false };
this._listItems.unshift(pastedItem);
this.requestUpdate();
}
this._canPaste = false;
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/tests/copy_rename.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ test('Copy and Rename with Versioned document', async ({ page }, workerInfo) =>

await page.getByRole('button', { name: 'Paste' }).click();
await page.waitForTimeout(3000);
const link = await page.getByRole('link', { name: orgPageName });
const href = await link.getAttribute('href');
await expect(href).toEqual(`/edit#/da-sites/da-status/tests/${copyFolderName}/${orgPageName}`);

// go back to the original to rename it
// Go to the directory view
Expand Down
53 changes: 53 additions & 0 deletions test/unit/blocks/browse/da_browse/da_browse.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
eslint-disable no-underscore-dangle
*/
import { expect } from '@esm-bundle/chai';

// This is needed to make a dynamic import work that is indirectly referenced
// from da-browse.js
const { setNx } = await import('../../../../../scripts/utils.js');
setNx('/bheuaark/', { hostname: 'localhost' });

const { default: DaBrowse } = await import('../../../../../blocks/browse/da-browse/da-browse.js');

describe('Browse', () => {
it('Pasted item uses the target URL', async () => {
const daBrowse = new DaBrowse();

const fetchedArgs = [];
const mockFetch = async (url, opts) => {
fetchedArgs.push({ url, opts });
return { ok: true };
};

const item = {
path: '/myorg/mysite/myroot/srcdir/d1.html',
ext: 'html',
isChecked: true,
name: 'd1',
};
daBrowse._listItems = [];
daBrowse._selectedItems = [item];
daBrowse.details = { fullpath: '/myorg/mysite/myroot/destdir' };

const orgFetch = window.fetch;
try {
window.fetch = mockFetch;
await daBrowse.handlePaste();

expect(daBrowse._listItems.length).to.equal(1);
expect(daBrowse._listItems[0].path).to.equal('/myorg/mysite/myroot/destdir/d1.html');
expect(daBrowse._listItems[0].ext).to.equal('html');
expect(daBrowse._listItems[0].isChecked).to.be.false;
expect(daBrowse._listItems[0].name).to.equal('d1');
expect(daBrowse._canPaste).to.be.false;

expect(fetchedArgs.length).to.equal(1);
expect(fetchedArgs[0].url).to.equal('https://admin.da.live/copy/myorg/mysite/myroot/srcdir/d1.html');
expect(fetchedArgs[0].opts.body.get('destination')).to.equal('/myorg/mysite/myroot/destdir/d1.html');
expect(fetchedArgs[0].opts.method).to.equal('POST');
} finally {
window.fetch = orgFetch;
}
});
});

0 comments on commit a803d77

Please sign in to comment.