Fixed test

This commit is contained in:
Benoit Schweblin 2018-08-09 16:42:17 +01:00
parent 952ceaa76c
commit bdb01f407b
8 changed files with 41 additions and 40 deletions

View File

@ -198,7 +198,7 @@ export default {
.modal__inner-2 { .modal__inner-2 {
margin: 40px 10px 100px; margin: 40px 10px 100px;
background-color: #f8f8f8; background-color: #f8f8f8;
padding: 40px 50px 30px; padding: 50px 50px 40px;
border-radius: $border-radius-base; border-radius: $border-radius-base;
position: relative; position: relative;
overflow: hidden; overflow: hidden;

View File

@ -10,7 +10,7 @@
<menu-entry @click.native="addCouchdbWorkspace"> <menu-entry @click.native="addCouchdbWorkspace">
<icon-provider slot="icon" provider-id="couchdbWorkspace"></icon-provider> <icon-provider slot="icon" provider-id="couchdbWorkspace"></icon-provider>
<div>CouchDB workspace</div> <div>CouchDB workspace</div>
<span>Add a workspace synced with your CouchDB database.</span> <span>Add a workspace synced with a CouchDB database.</span>
</menu-entry> </menu-entry>
<menu-entry @click.native="addGithubWorkspace"> <menu-entry @click.native="addGithubWorkspace">
<icon-provider slot="icon" provider-id="githubWorkspace"></icon-provider> <icon-provider slot="icon" provider-id="githubWorkspace"></icon-provider>

View File

@ -51,7 +51,7 @@
</div> </div>
</div> </div>
<div class="modal__info"> <div class="modal__info">
<b>ProTip:</b> Workspaces are accessible <b>offline</b> after their first use. <b>ProTip:</b> A workspace is accessible <b>offline</b> once it has been opened for the first time.
</div> </div>
</div> </div>
<div class="modal__button-bar"> <div class="modal__button-bar">

View File

@ -51,11 +51,11 @@ export default {
.modal__close-button { .modal__close-button {
position: absolute; position: absolute;
top: 7px; top: 8px;
right: 7px; right: 8px;
color: rgba(0, 0, 0, 0.5); color: rgba(0, 0, 0, 0.5);
width: 30px; width: 32px;
height: 30px; height: 32px;
padding: 2px; padding: 2px;
&:active, &:active,

View File

@ -144,11 +144,11 @@ export default new Provider({
let itemId = idsByPath[path]; let itemId = idsByPath[path];
if (!itemId) { if (!itemId) {
const existingItemId = itemIdsByGitPath[path]; const existingItemId = itemIdsByGitPath[path];
// We can replace the item only if it was already synced
if (existingItemId if (existingItemId
&& (syncDataByPath[path] // Reuse a file ID only if it has already been synced
// Content may have already be synced && (!isFile || syncDataByPath[path]
|| (isFile && syncDataByPath[`/${path}`])) // Content may have already been synced
|| syncDataByPath[`/${path}`])
) { ) {
itemId = existingItemId; itemId = existingItemId;
} else { } else {
@ -332,7 +332,7 @@ export default new Provider({
// Files and folders are not in git, only contents // Files and folders are not in git, only contents
if (item.type === 'file' || item.type === 'folder') { if (item.type === 'file' || item.type === 'folder') {
return syncData; return { syncData };
} }
// locations are stored as paths, so we upload an empty file // locations are stored as paths, so we upload an empty file
@ -346,9 +346,7 @@ export default new Provider({
}); });
// Return sync data to save // Return sync data to save
return { return { syncData };
syncData,
};
}, },
async removeWorkspaceItem({ syncData }) { async removeWorkspaceItem({ syncData }) {
if (treeShaMap[syncData.id]) { if (treeShaMap[syncData.id]) {

View File

@ -649,19 +649,22 @@ const syncWorkspace = async (skipContents = false) => {
}; };
const syncDataByItemId = store.getters['data/syncDataByItemId']; const syncDataByItemId = store.getters['data/syncDataByItemId'];
const isGit = !!store.getters['workspace/currentWorkspaceIsGit'];
const [changedItem, syncDataToUpdate] = utils.someResult( const [changedItem, syncDataToUpdate] = utils.someResult(
Object.entries(storeItemMap), Object.entries(storeItemMap),
([id, item]) => { ([id, item]) => {
const syncData = syncDataByItemId[id]; const syncData = syncDataByItemId[id];
if ((!syncData || syncData.hash !== item.hash) if ((syncData && syncData.hash === item.hash)
// Add file/folder if parent has been added // Add file/folder only if parent folder has been added
&& (!storeItemMap[item.parentId] || syncDataByItemId[item.parentId]) || (!isGit && storeItemMap[item.parentId] && !syncDataByItemId[item.parentId])
// Add file if content has been added // Don't create folder if it's a git workspace
&& (item.type !== 'file' || syncDataByItemId[`${id}/content`]) || (isGit && item.type === 'folder')
// Add file only if content has been added
|| (item.type === 'file' && !syncDataByItemId[`${id}/content`])
) { ) {
return [item, syncData];
}
return null; return null;
}
return [item, syncData];
}, },
) || []; ) || [];
@ -695,16 +698,15 @@ const syncWorkspace = async (skipContents = false) => {
const syncDataToRemove = utils.deepCopy(utils.someResult( const syncDataToRemove = utils.deepCopy(utils.someResult(
Object.values(syncDataById), Object.values(syncDataById),
(syncData) => { (syncData) => {
if (!getItem(syncData) if (getItem(syncData)
// We don't want to delete data items, especially on first sync // We don't want to delete data items, especially on first sync
&& syncData.type !== 'data' || syncData.type === 'data'
// Remove content only if file has been removed // Remove content only if file has been removed
&& (syncData.type !== 'content' || (syncData.type === 'content' && getFileItem(syncData))
|| !getFileItem(syncData))
) { ) {
return syncData;
}
return null; return null;
}
return syncData;
}, },
)); ));
@ -714,9 +716,9 @@ const syncWorkspace = async (skipContents = false) => {
syncData: syncDataToRemove, syncData: syncDataToRemove,
ifNotTooLate, ifNotTooLate,
}); });
const syncDataCopy = { ...store.getters['data/syncDataById'] }; const syncDataByIdCopy = { ...store.getters['data/syncDataById'] };
delete syncDataCopy[syncDataToRemove.id]; delete syncDataByIdCopy[syncDataToRemove.id];
store.dispatch('data/setSyncDataById', syncDataCopy); store.dispatch('data/setSyncDataById', syncDataByIdCopy);
return true; return true;
})); }));

View File

@ -11,6 +11,7 @@ const select = (id) => {
}; };
const ensureExists = file => expect(store.getters.allItemsById).toHaveProperty(file.id); const ensureExists = file => expect(store.getters.allItemsById).toHaveProperty(file.id);
const ensureNotExists = file => expect(store.getters.allItemsById).not.toHaveProperty(file.id); const ensureNotExists = file => expect(store.getters.allItemsById).not.toHaveProperty(file.id);
const refreshItem = item => store.getters.allItemsById[item.id];
describe('Explorer.vue', () => { describe('Explorer.vue', () => {
it('should create new files in the root folder', () => { it('should create new files in the root folder', () => {
@ -25,7 +26,7 @@ describe('Explorer.vue', () => {
}); });
it('should create new files in a folder', async () => { it('should create new files in a folder', async () => {
const folder = await fileSvc.storeItem({ type: 'folder' }); const folder = await workspaceSvc.storeItem({ type: 'folder' });
const wrapper = mount(); const wrapper = mount();
select(folder.id); select(folder.id);
wrapper.find('.side-title__button--new-file').trigger('click'); wrapper.find('.side-title__button--new-file').trigger('click');
@ -94,7 +95,7 @@ describe('Explorer.vue', () => {
select(file.id); select(file.id);
wrapper.find('.side-title__button--delete').trigger('click'); wrapper.find('.side-title__button--delete').trigger('click');
ensureExists(file); ensureExists(file);
expect(file.parentId).toEqual('trash'); expect(refreshItem(file).parentId).toEqual('trash');
}); });
it('should not delete the trash folder', async () => { it('should not delete the trash folder', async () => {
@ -142,7 +143,7 @@ describe('Explorer.vue', () => {
ensureNotExists(folder); ensureNotExists(folder);
// Make sure file has been moved to Trash // Make sure file has been moved to Trash
ensureExists(file); ensureExists(file);
expect(file.parentId).toEqual('trash'); expect(refreshItem(file).parentId).toEqual('trash');
}); });
it('should rename files', async () => { it('should rename files', async () => {

View File

@ -81,16 +81,16 @@ describe('ExplorerNode.vue', () => {
const wrapper = mount(node); const wrapper = mount(node);
wrapper.trigger('contextmenu'); wrapper.trigger('contextmenu');
await specUtils.resolveContextMenu('New file'); await specUtils.resolveContextMenu('New file');
expect(wrapper.contains('.explorer-node__new-child--file')).toBe(true); expect(wrapper.contains('.explorer-node__new-child')).toBe(true);
store.commit('explorer/setNewItemName', modifiedName); store.commit('explorer/setNewItemName', modifiedName);
wrapper.find('.explorer-node__new-child--file .text-input').trigger('blur'); wrapper.find('.explorer-node__new-child .text-input').trigger('blur');
await new Promise(resolve => setTimeout(resolve, 1)); await new Promise(resolve => setTimeout(resolve, 1));
expect(store.getters['explorer/selectedNode'].item).toMatchObject({ expect(store.getters['explorer/selectedNode'].item).toMatchObject({
name: modifiedName, name: modifiedName,
type: 'file', type: 'file',
parentId: node.item.id, parentId: node.item.id,
}); });
expect(wrapper.contains('.explorer-node__new-child--file')).toBe(false); expect(wrapper.contains('.explorer-node__new-child')).toBe(false);
}); });
it('should cancel a file creation on escape', async () => { it('should cancel a file creation on escape', async () => {
@ -98,9 +98,9 @@ describe('ExplorerNode.vue', () => {
const wrapper = mount(node); const wrapper = mount(node);
wrapper.trigger('contextmenu'); wrapper.trigger('contextmenu');
await specUtils.resolveContextMenu('New file'); await specUtils.resolveContextMenu('New file');
expect(wrapper.contains('.explorer-node__new-child--file')).toBe(true); expect(wrapper.contains('.explorer-node__new-child')).toBe(true);
store.commit('explorer/setNewItemName', modifiedName); store.commit('explorer/setNewItemName', modifiedName);
wrapper.find('.explorer-node__new-child--file .text-input').trigger('keydown', { wrapper.find('.explorer-node__new-child .text-input').trigger('keydown', {
keyCode: 27, keyCode: 27,
}); });
await new Promise(resolve => setTimeout(resolve, 1)); await new Promise(resolve => setTimeout(resolve, 1));
@ -109,7 +109,7 @@ describe('ExplorerNode.vue', () => {
type: 'file', type: 'file',
parentId: node.item.id, parentId: node.item.id,
}); });
expect(wrapper.contains('.explorer-node__new-child--file')).toBe(false); expect(wrapper.contains('.explorer-node__new-child')).toBe(false);
}); });
it('should not create new files in a file', async () => { it('should not create new files in a file', async () => {