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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
f3006b6a
Commit
f3006b6a
authored
Feb 21, 2019
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move gfm_auto_complete_spec.js to Jest
parent
948df0e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
38 deletions
+47
-38
spec/frontend/gfm_auto_complete_spec.js
spec/frontend/gfm_auto_complete_spec.js
+47
-38
No files found.
spec/
javascripts
/gfm_auto_complete_spec.js
→
spec/
frontend
/gfm_auto_complete_spec.js
View file @
f3006b6a
...
@@ -6,58 +6,62 @@ import GfmAutoComplete from '~/gfm_auto_complete';
...
@@ -6,58 +6,62 @@ import GfmAutoComplete from '~/gfm_auto_complete';
import
'
vendor/jquery.caret
'
;
import
'
vendor/jquery.caret
'
;
import
'
vendor/jquery.atwho
'
;
import
'
vendor/jquery.atwho
'
;
describe
(
'
GfmAutoComplete
'
,
function
()
{
describe
(
'
GfmAutoComplete
'
,
()
=>
{
const
gfmAutoCompleteCallbacks
=
GfmAutoComplete
.
prototype
.
getDefaultCallbacks
.
call
({
const
gfmAutoCompleteCallbacks
=
GfmAutoComplete
.
prototype
.
getDefaultCallbacks
.
call
({
fetchData
:
()
=>
{},
fetchData
:
()
=>
{},
});
});
describe
(
'
DefaultOptions.sorter
'
,
function
()
{
let
atwhoInstance
;
describe
(
'
assets loading
'
,
function
()
{
let
items
;
beforeEach
(
function
()
{
let
sorterValue
;
spyOn
(
GfmAutoComplete
,
'
isLoading
'
).
and
.
returnValue
(
true
);
this
.
atwhoInstance
=
{
setting
:
{}
};
describe
(
'
DefaultOptions.sorter
'
,
()
=>
{
this
.
items
=
[];
describe
(
'
assets loading
'
,
()
=>
{
beforeEach
(()
=>
{
jest
.
spyOn
(
GfmAutoComplete
,
'
isLoading
'
).
mockReturnValue
(
true
);
this
.
sorterValue
=
gfmAutoCompleteCallbacks
.
sorter
.
call
(
this
.
atwhoInstance
,
''
,
this
.
items
);
atwhoInstance
=
{
setting
:
{}
};
items
=
[];
sorterValue
=
gfmAutoCompleteCallbacks
.
sorter
.
call
(
atwhoInstance
,
''
,
items
);
});
});
it
(
'
should disable highlightFirst
'
,
function
()
{
it
(
'
should disable highlightFirst
'
,
()
=>
{
expect
(
this
.
atwhoInstance
.
setting
.
highlightFirst
).
toBe
(
false
);
expect
(
atwhoInstance
.
setting
.
highlightFirst
).
toBe
(
false
);
});
});
it
(
'
should return the passed unfiltered items
'
,
function
()
{
it
(
'
should return the passed unfiltered items
'
,
()
=>
{
expect
(
this
.
sorterValue
).
toEqual
(
this
.
items
);
expect
(
sorterValue
).
toEqual
(
items
);
});
});
});
});
describe
(
'
assets finished loading
'
,
function
()
{
describe
(
'
assets finished loading
'
,
()
=>
{
beforeEach
(
function
()
{
beforeEach
(
()
=>
{
spyOn
(
GfmAutoComplete
,
'
isLoading
'
).
and
.
r
eturnValue
(
false
);
jest
.
spyOn
(
GfmAutoComplete
,
'
isLoading
'
).
mockR
eturnValue
(
false
);
spyOn
(
$
.
fn
.
atwho
.
default
.
callbacks
,
'
sorter
'
);
jest
.
spyOn
(
$
.
fn
.
atwho
.
default
.
callbacks
,
'
sorter
'
).
mockImplementation
(()
=>
{}
);
});
});
it
(
'
should enable highlightFirst if alwaysHighlightFirst is set
'
,
function
()
{
it
(
'
should enable highlightFirst if alwaysHighlightFirst is set
'
,
()
=>
{
const
atwhoInstance
=
{
setting
:
{
alwaysHighlightFirst
:
true
}
};
atwhoInstance
=
{
setting
:
{
alwaysHighlightFirst
:
true
}
};
gfmAutoCompleteCallbacks
.
sorter
.
call
(
atwhoInstance
);
gfmAutoCompleteCallbacks
.
sorter
.
call
(
atwhoInstance
);
expect
(
atwhoInstance
.
setting
.
highlightFirst
).
toBe
(
true
);
expect
(
atwhoInstance
.
setting
.
highlightFirst
).
toBe
(
true
);
});
});
it
(
'
should enable highlightFirst if a query is present
'
,
function
()
{
it
(
'
should enable highlightFirst if a query is present
'
,
()
=>
{
const
atwhoInstance
=
{
setting
:
{}
};
atwhoInstance
=
{
setting
:
{}
};
gfmAutoCompleteCallbacks
.
sorter
.
call
(
atwhoInstance
,
'
query
'
);
gfmAutoCompleteCallbacks
.
sorter
.
call
(
atwhoInstance
,
'
query
'
);
expect
(
atwhoInstance
.
setting
.
highlightFirst
).
toBe
(
true
);
expect
(
atwhoInstance
.
setting
.
highlightFirst
).
toBe
(
true
);
});
});
it
(
'
should call the default atwho sorter
'
,
function
()
{
it
(
'
should call the default atwho sorter
'
,
()
=>
{
const
atwhoInstance
=
{
setting
:
{}
};
atwhoInstance
=
{
setting
:
{}
};
const
query
=
'
query
'
;
const
query
=
'
query
'
;
const
items
=
[];
items
=
[];
const
searchKey
=
'
searchKey
'
;
const
searchKey
=
'
searchKey
'
;
gfmAutoCompleteCallbacks
.
sorter
.
call
(
atwhoInstance
,
query
,
items
,
searchKey
);
gfmAutoCompleteCallbacks
.
sorter
.
call
(
atwhoInstance
,
query
,
items
,
searchKey
);
...
@@ -71,7 +75,9 @@ describe('GfmAutoComplete', function() {
...
@@ -71,7 +75,9 @@ describe('GfmAutoComplete', function() {
const
beforeInsert
=
(
context
,
value
)
=>
const
beforeInsert
=
(
context
,
value
)
=>
gfmAutoCompleteCallbacks
.
beforeInsert
.
call
(
context
,
value
);
gfmAutoCompleteCallbacks
.
beforeInsert
.
call
(
context
,
value
);
const
atwhoInstance
=
{
setting
:
{
skipSpecialCharacterTest
:
false
}
};
beforeEach
(()
=>
{
atwhoInstance
=
{
setting
:
{
skipSpecialCharacterTest
:
false
}
};
});
it
(
'
should not quote if value only contains alphanumeric charecters
'
,
()
=>
{
it
(
'
should not quote if value only contains alphanumeric charecters
'
,
()
=>
{
expect
(
beforeInsert
(
atwhoInstance
,
'
@user1
'
)).
toBe
(
'
@user1
'
);
expect
(
beforeInsert
(
atwhoInstance
,
'
@user1
'
)).
toBe
(
'
@user1
'
);
...
@@ -96,7 +102,7 @@ describe('GfmAutoComplete', function() {
...
@@ -96,7 +102,7 @@ describe('GfmAutoComplete', function() {
});
});
});
});
describe
(
'
DefaultOptions.matcher
'
,
function
()
{
describe
(
'
DefaultOptions.matcher
'
,
()
=>
{
const
defaultMatcher
=
(
context
,
flag
,
subtext
)
=>
const
defaultMatcher
=
(
context
,
flag
,
subtext
)
=>
gfmAutoCompleteCallbacks
.
matcher
.
call
(
context
,
flag
,
subtext
);
gfmAutoCompleteCallbacks
.
matcher
.
call
(
context
,
flag
,
subtext
);
...
@@ -108,7 +114,10 @@ describe('GfmAutoComplete', function() {
...
@@ -108,7 +114,10 @@ describe('GfmAutoComplete', function() {
hash
[
el
]
=
null
;
hash
[
el
]
=
null
;
return
hash
;
return
hash
;
},
{});
},
{});
const
atwhoInstance
=
{
setting
:
{},
app
:
{
controllers
:
flagsHash
}
};
beforeEach
(()
=>
{
atwhoInstance
=
{
setting
:
{},
app
:
{
controllers
:
flagsHash
}
};
});
const
minLen
=
1
;
const
minLen
=
1
;
const
maxLen
=
20
;
const
maxLen
=
20
;
...
@@ -182,38 +191,38 @@ describe('GfmAutoComplete', function() {
...
@@ -182,38 +191,38 @@ describe('GfmAutoComplete', function() {
});
});
});
});
describe
(
'
isLoading
'
,
function
()
{
describe
(
'
isLoading
'
,
()
=>
{
it
(
'
should be true with loading data object item
'
,
function
()
{
it
(
'
should be true with loading data object item
'
,
()
=>
{
expect
(
GfmAutoComplete
.
isLoading
({
name
:
'
loading
'
})).
toBe
(
true
);
expect
(
GfmAutoComplete
.
isLoading
({
name
:
'
loading
'
})).
toBe
(
true
);
});
});
it
(
'
should be true with loading data array
'
,
function
()
{
it
(
'
should be true with loading data array
'
,
()
=>
{
expect
(
GfmAutoComplete
.
isLoading
([
'
loading
'
])).
toBe
(
true
);
expect
(
GfmAutoComplete
.
isLoading
([
'
loading
'
])).
toBe
(
true
);
});
});
it
(
'
should be true with loading data object array
'
,
function
()
{
it
(
'
should be true with loading data object array
'
,
()
=>
{
expect
(
GfmAutoComplete
.
isLoading
([{
name
:
'
loading
'
}])).
toBe
(
true
);
expect
(
GfmAutoComplete
.
isLoading
([{
name
:
'
loading
'
}])).
toBe
(
true
);
});
});
it
(
'
should be false with actual array data
'
,
function
()
{
it
(
'
should be false with actual array data
'
,
()
=>
{
expect
(
expect
(
GfmAutoComplete
.
isLoading
([{
title
:
'
Foo
'
},
{
title
:
'
Bar
'
},
{
title
:
'
Qux
'
}]),
GfmAutoComplete
.
isLoading
([{
title
:
'
Foo
'
},
{
title
:
'
Bar
'
},
{
title
:
'
Qux
'
}]),
).
toBe
(
false
);
).
toBe
(
false
);
});
});
it
(
'
should be false with actual data item
'
,
function
()
{
it
(
'
should be false with actual data item
'
,
()
=>
{
expect
(
GfmAutoComplete
.
isLoading
({
title
:
'
Foo
'
})).
toBe
(
false
);
expect
(
GfmAutoComplete
.
isLoading
({
title
:
'
Foo
'
})).
toBe
(
false
);
});
});
});
});
describe
(
'
Issues.insertTemplateFunction
'
,
function
()
{
describe
(
'
Issues.insertTemplateFunction
'
,
()
=>
{
it
(
'
should return default template
'
,
function
()
{
it
(
'
should return default template
'
,
()
=>
{
expect
(
GfmAutoComplete
.
Issues
.
insertTemplateFunction
({
id
:
5
,
title
:
'
Some Issue
'
})).
toBe
(
expect
(
GfmAutoComplete
.
Issues
.
insertTemplateFunction
({
id
:
5
,
title
:
'
Some Issue
'
})).
toBe
(
'
${atwho-at}${id}
'
,
// eslint-disable-line no-template-curly-in-string
'
${atwho-at}${id}
'
,
// eslint-disable-line no-template-curly-in-string
);
);
});
});
it
(
'
should return reference when reference is set
'
,
function
()
{
it
(
'
should return reference when reference is set
'
,
()
=>
{
expect
(
expect
(
GfmAutoComplete
.
Issues
.
insertTemplateFunction
({
GfmAutoComplete
.
Issues
.
insertTemplateFunction
({
id
:
5
,
id
:
5
,
...
@@ -224,14 +233,14 @@ describe('GfmAutoComplete', function() {
...
@@ -224,14 +233,14 @@ describe('GfmAutoComplete', function() {
});
});
});
});
describe
(
'
Issues.templateFunction
'
,
function
()
{
describe
(
'
Issues.templateFunction
'
,
()
=>
{
it
(
'
should return html with id and title
'
,
function
()
{
it
(
'
should return html with id and title
'
,
()
=>
{
expect
(
GfmAutoComplete
.
Issues
.
templateFunction
({
id
:
5
,
title
:
'
Some Issue
'
})).
toBe
(
expect
(
GfmAutoComplete
.
Issues
.
templateFunction
({
id
:
5
,
title
:
'
Some Issue
'
})).
toBe
(
'
<li><small>5</small> Some Issue</li>
'
,
'
<li><small>5</small> Some Issue</li>
'
,
);
);
});
});
it
(
'
should replace id with reference if reference is set
'
,
function
()
{
it
(
'
should replace id with reference if reference is set
'
,
()
=>
{
expect
(
expect
(
GfmAutoComplete
.
Issues
.
templateFunction
({
GfmAutoComplete
.
Issues
.
templateFunction
({
id
:
5
,
id
:
5
,
...
...
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