it('calls service getTreeData', (done) => { store.dispatch('getTreeData') .then(() => { expect(service.getTreeData).toHaveBeenCalledWith('rootEndpoint'); done(); }).catch(done.fail); });
it('sets page title', (done) => { store.dispatch('getTreeData') .then(() => { expect(document.title).toBe('test'); done(); }).catch(done.fail); });
it('toggles loading for row', (done) => { store.dispatch('clickedTreeRow', row) .then(() => { expect(row.loading).toBeTruthy(); done(); }).catch(done.fail); });
it('calls service', (done) => { store.dispatch('commitChanges', { payload, newMr: false }) .then(() => { expect(service.commit).toHaveBeenCalledWith(123, payload); done(); }).catch(done.fail); });
it('scrolls to top of page', (done) => { store.dispatch('commitChanges', { payload, newMr: false }) .then(() => { expect(window.scrollTo).toHaveBeenCalledWith(0, 0); done(); }).catch(done.fail); });
it('updates commit ref', (done) => { store.dispatch('commitChanges', { payload, newMr: false }) .then(() => { expect(store.state.currentRef).toBe('123456'); done(); }).catch(done.fail); });
it('opens submodule URL', (done) => { store.dispatch('clickedTreeRow', row) .then(() => { expect(gl.utils.visitUrl).toHaveBeenCalledWith('submoduleurl'); done(); }).catch(done.fail); });
it('commits initial data', (done) => { store.dispatch('setInitialData', { canCommit: true }) .then(() => { expect(store.state.canCommit).toBeTruthy(); done(); }) .catch(done.fail); });
it('calls service with lastCommitPath', (done) => { store.dispatch('getLastCommitData') .then(() => { expect(service.getTreeLastCommit).toHaveBeenCalledWith('lastcommitpath'); done(); }).catch(done.fail); });
it('closes all open files', (done) => { store.dispatch('closeAllFiles') .then(() => { expect(store.state.openFiles.length).toBe(0); done(); }) .catch(done.fail); });
it('creates .gitkeep file in temp tree', (done) => { store.dispatch('createTempTree', 'test') .then(() => { expect(store.state.tree[0].tree[0].tempFile).toBeTruthy(); expect(store.state.tree[0].tree[0].name).toBe('.gitkeep'); done(); }).catch(done.fail); });
it('sets parent tree URL', (done) => { store.dispatch('getTreeData') .then(Vue.nextTick) .then(() => { expect(store.state.parentTreeUrl).toBe('parent_tree_url'); done(); }).catch(done.fail); });
it('sets last commit path', (done) => { store.dispatch('getTreeData') .then(Vue.nextTick) .then(() => { expect(store.state.lastCommitPath).toBe('last_commit_path'); done(); }).catch(done.fail); });
it('closes the discard popup', (done) => { store.dispatch('closeDiscardPopup', false) .then(() => { expect(store.state.discardPopupOpen).toBeFalsy(); done(); }) .catch(done.fail); });
it('updates trees last commit data', (done) => { store.dispatch('getLastCommitData') .then(Vue.nextTick) .then(() => { expect(store.state.tree[0].lastCommit.message).toBe('commit message'); done(); }).catch(done.fail); });
it('sets preview mode view if not in edit mode', (done) => { store.dispatch('toggleBlobView') .then(() => { expect(store.state.currentBlobView).toBe('repo-preview'); done(); }) .catch(done.fail); });
it('calls pushState with endpoint', (done) => { store.dispatch('getTreeData') .then(Vue.nextTick) .then(() => { expect(history.pushState).toHaveBeenCalledWith(jasmine.anything(), '', 'rootEndpoint'); done(); }).catch(done.fail); });
it('toggles edit mode', (done) => { store.state.editMode = true; store.dispatch('commitChanges', { payload, newMr: false }) .then(() => { expect(store.state.editMode).toBeFalsy(); done(); }).catch(done.fail); });
it('toggles edit mode', (done) => { store.state.editMode = true; store.dispatch('toggleEditMode') .then(() => { expect(store.state.editMode).toBeFalsy(); done(); }).catch(done.fail); });
it('toggles the tree open', (done) => { store.dispatch('toggleTreeOpen', { endpoint: 'test', tree, }).then(() => { expect(tree.opened).toBeTruthy(); done(); }).catch(done.fail); });
it('sets edit mode view if in edit mode', (done) => { store.state.editMode = true; store.dispatch('toggleBlobView') .then(() => { expect(store.state.currentBlobView).toBe('repo-editor'); done(); }) .catch(done.fail); });
it('calls visitUrl', (done) => { spyOn(gl.utils, 'visitUrl'); store.dispatch('redirectToUrl', 'test') .then(() => { expect(gl.utils.visitUrl).toHaveBeenCalledWith('test'); done(); }) .catch(done.fail); });
it('does not update entry if not found', (done) => { store.state.tree[0].name = 'a'; store.dispatch('getLastCommitData') .then(Vue.nextTick) .then(() => { expect(store.state.tree[0].lastCommit.message).not.toBe('commit message'); done(); }).catch(done.fail); });
it('opens discard popup if there are changed files', (done) => { store.state.editMode = true; store.state.openFiles.push(file()); store.state.openFiles[0].changed = true; store.dispatch('toggleEditMode') .then(() => { expect(store.state.discardPopupOpen).toBeTruthy(); done(); }).catch(done.fail); });
it('sets root if not currently at root', (done) => { store.state.isInitialRoot = false; store.dispatch('getTreeData') .then(Vue.nextTick) .then(() => { expect(store.state.isInitialRoot).toBeTruthy(); expect(store.state.isRoot).toBeTruthy(); done(); }).catch(done.fail); });
it('closes all files', (done) => { store.state.openFiles.push(file()); store.state.openFiles[0].opened = true; store.dispatch('commitChanges', { payload, newMr: false }) .then(Vue.nextTick) .then(() => { expect(store.state.openFiles.length).toBe(0); done(); }).catch(done.fail); });
it('redirects to new merge request page', (done) => { spyOn(gl.utils, 'visitUrl'); store.state.endpoints.newMergeRequestUrl = 'newMergeRequestUrl?branch='; store.dispatch('commitChanges', { payload, newMr: true }) .then(() => { expect(gl.utils.visitUrl).toHaveBeenCalledWith('newMergeRequestUrl?branch=master'); done(); }).catch(done.fail); });
it('shows failed message', (done) => { store.dispatch('commitChanges', { payload, newMr: false }) .then(() => { const alert = document.querySelector('.flash-container'); expect(alert.textContent.trim()).toBe( 'failed message', ); done(); }).catch(done.fail); });
it('sets preview mode', (done) => { store.state.currentBlobView = 'repo-editor'; store.state.editMode = true; store.dispatch('toggleEditMode') .then(Vue.nextTick) .then(() => { expect(store.state.currentBlobView).toBe('repo-preview'); done(); }).catch(done.fail); });
it('adds data into tree', (done) => { store.dispatch('getTreeData') .then(Vue.nextTick) .then(() => { expect(store.state.tree.length).toBe(3); expect(store.state.tree[0].type).toBe('tree'); expect(store.state.tree[1].type).toBe('submodule'); expect(store.state.tree[2].type).toBe('blob'); done(); }).catch(done.fail); });