Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
608a6484
Commit
608a6484
authored
Mar 27, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added specs
parent
babb90a7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
229 additions
and
16 deletions
+229
-16
app/assets/javascripts/ide/stores/mutations/file.js
app/assets/javascripts/ide/stores/mutations/file.js
+16
-10
spec/javascripts/ide/components/commit_sidebar/list_item_spec.js
...vascripts/ide/components/commit_sidebar/list_item_spec.js
+9
-6
spec/javascripts/ide/stores/actions/file_spec.js
spec/javascripts/ide/stores/actions/file_spec.js
+125
-0
spec/javascripts/ide/stores/mutations/file_spec.js
spec/javascripts/ide/stores/mutations/file_spec.js
+79
-0
No files found.
app/assets/javascripts/ide/stores/mutations/file.js
View file @
608a6484
...
...
@@ -114,24 +114,30 @@ export default {
}),
});
}
else
{
Object
.
assign
(
state
,
{
entries
:
Object
.
assign
(
state
.
entries
,
{
[
file
.
path
]:
Object
.
assign
(
state
.
entries
[
file
.
path
],
{
opened
:
false
,
}),
}),
openFiles
:
state
.
openFiles
.
map
(
f
=>
{
const
openFile
=
state
.
openFiles
.
find
(
f
=>
f
.
path
===
file
.
path
);
const
openFiles
=
state
.
openFiles
.
concat
(
openFile
?
null
:
file
)
.
filter
(
f
=>
f
)
.
reduce
((
acc
,
f
)
=>
{
if
(
f
.
path
===
file
.
path
)
{
return
{
return
acc
.
concat
(
{
...
f
,
active
:
true
,
pending
:
true
,
key
:
`pending-
${
f
.
key
}
`
,
};
}
)
;
}
return
f
;
return
acc
.
concat
(
f
);
},
[]);
Object
.
assign
(
state
,
{
entries
:
Object
.
assign
(
state
.
entries
,
{
[
file
.
path
]:
Object
.
assign
(
state
.
entries
[
file
.
path
],
{
opened
:
false
,
}),
}),
openFiles
,
});
}
},
...
...
spec/javascripts/ide/components/commit_sidebar/list_item_spec.js
View file @
608a6484
...
...
@@ -14,6 +14,8 @@ describe('Multi-file editor commit sidebar list item', () => {
f
=
file
(
'
test-file
'
);
store
.
state
.
entries
[
f
.
path
]
=
f
;
vm
=
createComponentWithStore
(
Component
,
store
,
{
file
:
f
,
}).
$mount
();
...
...
@@ -24,9 +26,7 @@ describe('Multi-file editor commit sidebar list item', () => {
});
it
(
'
renders file path
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.multi-file-commit-list-path
'
).
textContent
.
trim
(),
).
toBe
(
f
.
path
);
expect
(
vm
.
$el
.
querySelector
(
'
.multi-file-commit-list-path
'
).
textContent
.
trim
()).
toBe
(
f
.
path
);
});
it
(
'
calls discardFileChanges when clicking discard button
'
,
()
=>
{
...
...
@@ -39,7 +39,6 @@ describe('Multi-file editor commit sidebar list item', () => {
it
(
'
opens a closed file in the editor when clicking the file path
'
,
done
=>
{
spyOn
(
vm
,
'
openFileInEditor
'
).
and
.
callThrough
();
spyOn
(
vm
,
'
updateViewer
'
).
and
.
callThrough
();
spyOn
(
router
,
'
push
'
);
vm
.
$el
.
querySelector
(
'
.multi-file-commit-list-path
'
).
click
();
...
...
@@ -52,14 +51,18 @@ describe('Multi-file editor commit sidebar list item', () => {
});
});
it
(
'
calls updateViewer with diff when clicking file
'
,
()
=>
{
it
(
'
calls updateViewer with diff when clicking file
'
,
done
=>
{
spyOn
(
vm
,
'
openFileInEditor
'
).
and
.
callThrough
();
spyOn
(
vm
,
'
updateViewer
'
).
and
.
callThrough
();
spyOn
(
router
,
'
push
'
);
vm
.
$el
.
querySelector
(
'
.multi-file-commit-list-path
'
).
click
();
expect
(
vm
.
updateViewer
).
toHaveBeenCalledWith
(
'
diff
'
);
setTimeout
(()
=>
{
expect
(
vm
.
updateViewer
).
toHaveBeenCalledWith
(
'
diff
'
);
done
();
});
});
describe
(
'
computed
'
,
()
=>
{
...
...
spec/javascripts/ide/stores/actions/file_spec.js
View file @
608a6484
...
...
@@ -74,6 +74,22 @@ describe('Multi-file store file actions', () => {
})
.
catch
(
done
.
fail
);
});
it
(
'
removes file if it pending
'
,
done
=>
{
store
.
state
.
openFiles
.
push
({
...
localFile
,
pending
:
true
,
});
store
.
dispatch
(
'
closeFile
'
,
localFile
)
.
then
(()
=>
{
expect
(
store
.
state
.
openFiles
.
length
).
toBe
(
0
);
done
();
})
.
catch
(
done
.
fail
);
});
});
describe
(
'
setFileActive
'
,
()
=>
{
...
...
@@ -418,4 +434,113 @@ describe('Multi-file store file actions', () => {
.
catch
(
done
.
fail
);
});
});
describe
(
'
openPendingTab
'
,
()
=>
{
let
f
;
beforeEach
(()
=>
{
f
=
{
...
file
(),
projectId
:
'
123
'
,
};
store
.
state
.
entries
[
f
.
path
]
=
f
;
});
it
(
'
makes file pending in openFiles
'
,
done
=>
{
store
.
dispatch
(
'
openPendingTab
'
,
f
)
.
then
(()
=>
{
expect
(
store
.
state
.
openFiles
[
0
].
pending
).
toBe
(
true
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
returns true when opened
'
,
done
=>
{
store
.
dispatch
(
'
openPendingTab
'
,
f
)
.
then
(
added
=>
{
expect
(
added
).
toBe
(
true
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
pushes router URL when added
'
,
done
=>
{
store
.
state
.
currentBranchId
=
'
master
'
;
store
.
dispatch
(
'
openPendingTab
'
,
f
)
.
then
(()
=>
{
expect
(
router
.
push
).
toHaveBeenCalledWith
(
'
/project/123/tree/master/
'
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
calls scrollToTab
'
,
done
=>
{
const
scrollToTabSpy
=
jasmine
.
createSpy
(
'
scrollToTab
'
);
const
oldScrollToTab
=
store
.
_actions
.
scrollToTab
;
// eslint-disable-line
store
.
_actions
.
scrollToTab
=
[
scrollToTabSpy
];
// eslint-disable-line
store
.
dispatch
(
'
openPendingTab
'
,
f
)
.
then
(()
=>
{
expect
(
scrollToTabSpy
).
toHaveBeenCalled
();
store
.
_actions
.
scrollToTab
=
oldScrollToTab
;
// eslint-disable-line
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
returns false when passed in file is active & viewer is diff
'
,
done
=>
{
f
.
active
=
true
;
store
.
state
.
openFiles
.
push
(
f
);
store
.
state
.
viewer
=
'
diff
'
;
store
.
dispatch
(
'
openPendingTab
'
,
f
)
.
then
(
added
=>
{
expect
(
added
).
toBe
(
false
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
describe
(
'
removePendingTab
'
,
()
=>
{
let
f
;
beforeEach
(()
=>
{
spyOn
(
eventHub
,
'
$emit
'
);
f
=
{
...
file
(
'
pendingFile
'
),
pending
:
true
,
};
});
it
(
'
removes pending file from open files
'
,
done
=>
{
store
.
state
.
openFiles
.
push
(
f
);
store
.
dispatch
(
'
removePendingTab
'
,
f
)
.
then
(()
=>
{
expect
(
store
.
state
.
openFiles
.
length
).
toBe
(
0
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
emits event to dispose model
'
,
done
=>
{
store
.
dispatch
(
'
removePendingTab
'
,
f
)
.
then
(()
=>
{
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
`editor.update.model.dispose.
${
f
.
key
}
`
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
});
spec/javascripts/ide/stores/mutations/file_spec.js
View file @
608a6484
...
...
@@ -22,6 +22,20 @@ describe('Multi-file store file mutations', () => {
expect
(
localFile
.
active
).
toBeTruthy
();
});
it
(
'
sets pending tab as not active
'
,
()
=>
{
localState
.
openFiles
.
push
({
...
localFile
,
pending
:
true
,
});
mutations
.
SET_FILE_ACTIVE
(
localState
,
{
path
:
localFile
.
path
,
active
:
true
,
});
expect
(
localState
.
openFiles
[
0
].
active
).
toBe
(
false
);
});
});
describe
(
'
TOGGLE_FILE_OPEN
'
,
()
=>
{
...
...
@@ -154,4 +168,69 @@ describe('Multi-file store file mutations', () => {
expect
(
localFile
.
changed
).
toBeTruthy
();
});
});
describe
(
'
ADD_PENDING_TAB
'
,
()
=>
{
beforeEach
(()
=>
{
const
f
=
{
...
file
(
'
openFile
'
),
path
:
'
openFile
'
,
active
:
true
,
opened
:
true
,
};
localState
.
entries
[
f
.
path
]
=
f
;
localState
.
openFiles
.
push
(
f
);
});
it
(
'
adds file into openFiles as pending
'
,
()
=>
{
mutations
.
ADD_PENDING_TAB
(
localState
,
localFile
);
expect
(
localState
.
openFiles
.
length
).
toBe
(
2
);
expect
(
localState
.
openFiles
[
1
].
pending
).
toBe
(
true
);
expect
(
localState
.
openFiles
[
1
].
key
).
toBe
(
`pending-
${
localFile
.
key
}
`
);
});
it
(
'
updates open file to pending
'
,
()
=>
{
mutations
.
ADD_PENDING_TAB
(
localState
,
localState
.
openFiles
[
0
]);
expect
(
localState
.
openFiles
.
length
).
toBe
(
1
);
});
it
(
'
updates pending open file to active
'
,
()
=>
{
localState
.
openFiles
.
push
({
...
localFile
,
pending
:
true
,
});
mutations
.
ADD_PENDING_TAB
(
localState
,
localFile
);
expect
(
localState
.
openFiles
[
1
].
pending
).
toBe
(
true
);
expect
(
localState
.
openFiles
[
1
].
active
).
toBe
(
true
);
});
it
(
'
sets all openFiles to not active
'
,
()
=>
{
mutations
.
ADD_PENDING_TAB
(
localState
,
localFile
);
expect
(
localState
.
openFiles
.
length
).
toBe
(
2
);
localState
.
openFiles
.
forEach
(
f
=>
{
if
(
f
.
pending
)
{
expect
(
f
.
active
).
toBe
(
true
);
}
else
{
expect
(
f
.
active
).
toBe
(
false
);
}
});
});
});
describe
(
'
REMOVE_PENDING_TAB
'
,
()
=>
{
it
(
'
removes pending tab from openFiles
'
,
()
=>
{
localFile
.
key
=
'
testing
'
;
localState
.
openFiles
.
push
(
localFile
);
mutations
.
REMOVE_PENDING_TAB
(
localState
,
localFile
);
expect
(
localState
.
openFiles
.
length
).
toBe
(
0
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment