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
ee1c471b
Commit
ee1c471b
authored
Feb 01, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converted pager.js to axios
parent
ab8e3a55
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
32 deletions
+77
-32
app/assets/javascripts/pager.js
app/assets/javascripts/pager.js
+16
-17
spec/javascripts/pager_spec.js
spec/javascripts/pager_spec.js
+61
-15
No files found.
app/assets/javascripts/pager.js
View file @
ee1c471b
import
{
getParameterByName
}
from
'
~/lib/utils/common_utils
'
;
import
{
getParameterByName
}
from
'
~/lib/utils/common_utils
'
;
import
axios
from
'
./lib/utils/axios_utils
'
;
import
{
removeParams
}
from
'
./lib/utils/url_utility
'
;
import
{
removeParams
}
from
'
./lib/utils/url_utility
'
;
const
ENDLESS_SCROLL_BOTTOM_PX
=
400
;
const
ENDLESS_SCROLL_BOTTOM_PX
=
400
;
...
@@ -22,13 +23,12 @@ export default {
...
@@ -22,13 +23,12 @@ export default {
getOld
()
{
getOld
()
{
this
.
loading
.
show
();
this
.
loading
.
show
();
$
.
ajax
({
axios
.
get
(
this
.
url
,
{
type
:
'
GET
'
,
params
:
{
url
:
this
.
url
,
limit
:
this
.
limit
,
data
:
`limit=
${
this
.
limit
}
&offset=
${
this
.
offset
}
`
,
offset
:
this
.
offset
,
dataType
:
'
json
'
,
},
error
:
()
=>
this
.
loading
.
hide
(),
}).
then
(({
data
})
=>
{
success
:
(
data
)
=>
{
this
.
append
(
data
.
count
,
this
.
prepareData
(
data
.
html
));
this
.
append
(
data
.
count
,
this
.
prepareData
(
data
.
html
));
this
.
callback
();
this
.
callback
();
...
@@ -38,8 +38,7 @@ export default {
...
@@ -38,8 +38,7 @@ export default {
}
else
{
}
else
{
this
.
loading
.
hide
();
this
.
loading
.
hide
();
}
}
},
}).
catch
(()
=>
this
.
loading
.
hide
());
});
},
},
append
(
count
,
html
)
{
append
(
count
,
html
)
{
...
...
spec/javascripts/pager_spec.js
View file @
ee1c471b
/* global fixture */
/* global fixture */
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
*
as
utils
from
'
~/lib/utils/url_utility
'
;
import
*
as
utils
from
'
~/lib/utils/url_utility
'
;
import
Pager
from
'
~/pager
'
;
import
Pager
from
'
~/pager
'
;
...
@@ -9,7 +10,6 @@ describe('pager', () => {
...
@@ -9,7 +10,6 @@ describe('pager', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
setFixtures
(
'
<div class="content_list"></div><div class="loading"></div>
'
);
setFixtures
(
'
<div class="content_list"></div><div class="loading"></div>
'
);
spyOn
(
$
,
'
ajax
'
);
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
...
@@ -47,39 +47,85 @@ describe('pager', () => {
...
@@ -47,39 +47,85 @@ describe('pager', () => {
});
});
describe
(
'
getOld
'
,
()
=>
{
describe
(
'
getOld
'
,
()
=>
{
const
urlRegex
=
/
\/
some_list
(
.*
)
$/
;
let
mock
;
function
mockSuccess
()
{
mock
.
onGet
(
urlRegex
).
reply
(
200
,
{
count
:
20
,
html
:
''
,
});
}
function
mockError
()
{
mock
.
onGet
(
urlRegex
).
networkError
();
}
beforeEach
(()
=>
{
beforeEach
(()
=>
{
setFixtures
(
'
<div class="content_list" data-href="/some_list"></div><div class="loading"></div>
'
);
setFixtures
(
'
<div class="content_list" data-href="/some_list"></div><div class="loading"></div>
'
);
spyOn
(
axios
,
'
get
'
).
and
.
callThrough
();
Pager
.
init
();
Pager
.
init
();
mock
=
new
MockAdapter
(
axios
);
});
});
it
(
'
shows loader while loading next page
'
,
()
=>
{
afterEach
(()
=>
{
mock
.
restore
();
});
it
(
'
shows loader while loading next page
'
,
(
done
)
=>
{
mockSuccess
();
spyOn
(
Pager
.
loading
,
'
show
'
);
spyOn
(
Pager
.
loading
,
'
show
'
);
Pager
.
getOld
();
Pager
.
getOld
();
setTimeout
(()
=>
{
expect
(
Pager
.
loading
.
show
).
toHaveBeenCalled
();
expect
(
Pager
.
loading
.
show
).
toHaveBeenCalled
();
done
();
});
});
});
it
(
'
hides loader on success
'
,
(
done
)
=>
{
mockSuccess
();
it
(
'
hides loader on success
'
,
()
=>
{
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(
options
=>
options
.
success
({}));
spyOn
(
Pager
.
loading
,
'
hide
'
);
spyOn
(
Pager
.
loading
,
'
hide
'
);
Pager
.
getOld
();
Pager
.
getOld
();
setTimeout
(()
=>
{
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
done
();
});
});
});
it
(
'
hides loader on error
'
,
()
=>
{
it
(
'
hides loader on error
'
,
(
done
)
=>
{
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(
options
=>
options
.
error
());
mockError
();
spyOn
(
Pager
.
loading
,
'
hide
'
);
spyOn
(
Pager
.
loading
,
'
hide
'
);
Pager
.
getOld
();
Pager
.
getOld
();
setTimeout
(()
=>
{
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
done
();
});
});
});
it
(
'
sends request to url with offset and limit params
'
,
()
=>
{
it
(
'
sends request to url with offset and limit params
'
,
(
done
)
=>
{
spyOn
(
$
,
'
ajax
'
);
Pager
.
offset
=
100
;
Pager
.
offset
=
100
;
Pager
.
limit
=
20
;
Pager
.
limit
=
20
;
Pager
.
getOld
();
Pager
.
getOld
();
const
[{
data
,
url
}]
=
$
.
ajax
.
calls
.
argsFor
(
0
);
expect
(
data
).
toBe
(
'
limit=20&offset=100
'
);
setTimeout
(()
=>
{
expect
(
url
).
toBe
(
'
/some_list
'
);
const
[
url
,
params
]
=
$
.
ajax
.
calls
.
argsFor
(
0
);
console
.
log
(
url
,
params
);
// expect(data).toBe('limit=20&offset=100');
// expect(url).toBe('/some_list');
done
();
});
});
});
});
});
});
});
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