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
b2b527a6
Commit
b2b527a6
authored
Jul 07, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests to test what the component renders and what the clicks calls
parent
e354b6d3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
179 additions
and
161 deletions
+179
-161
app/assets/javascripts/vue_shared/components/table_pagination.vue
...ts/javascripts/vue_shared/components/table_pagination.vue
+10
-4
spec/javascripts/lib/utils/common_utils_spec.js
spec/javascripts/lib/utils/common_utils_spec.js
+1
-0
spec/javascripts/vue_shared/components/table_pagination_spec.js
...avascripts/vue_shared/components/table_pagination_spec.js
+168
-157
No files found.
app/assets/javascripts/vue_shared/components/table_pagination.vue
View file @
b2b527a6
...
@@ -84,7 +84,9 @@ export default {
...
@@ -84,7 +84,9 @@ export default {
const
page
=
this
.
pageInfo
.
page
;
const
page
=
this
.
pageInfo
.
page
;
const
items
=
[];
const
items
=
[];
if
(
page
>
1
)
items
.
push
({
title
:
FIRST
});
if
(
page
>
1
)
{
items
.
push
({
title
:
FIRST
,
first
:
true
});
}
if
(
page
>
1
)
{
if
(
page
>
1
)
{
items
.
push
({
title
:
PREV
,
prev
:
true
});
items
.
push
({
title
:
PREV
,
prev
:
true
});
...
@@ -112,7 +114,9 @@ export default {
...
@@ -112,7 +114,9 @@ export default {
items
.
push
({
title
:
NEXT
,
next
:
true
});
items
.
push
({
title
:
NEXT
,
next
:
true
});
}
}
if
(
total
-
page
>=
1
)
items
.
push
({
title
:
LAST
,
last
:
true
});
if
(
total
-
page
>=
1
)
{
items
.
push
({
title
:
LAST
,
last
:
true
});
}
return
items
;
return
items
;
},
},
...
@@ -126,8 +130,10 @@ export default {
...
@@ -126,8 +130,10 @@ export default {
v-for=
"item in getItems"
v-for=
"item in getItems"
:class=
"
{
:class=
"
{
page: item.page,
page: item.page,
prev: item.prev,
'js-previous-button': item.prev,
next: item.next,
'js-next-button': item.next,
'js-last-button': item.last,
'js-first-button': item.first,
separator: item.separator,
separator: item.separator,
active: item.active,
active: item.active,
disabled: item.disabled
disabled: item.disabled
...
...
spec/javascripts/lib/utils/common_utils_spec.js
View file @
b2b527a6
...
@@ -143,6 +143,7 @@ import '~/lib/utils/common_utils';
...
@@ -143,6 +143,7 @@ import '~/lib/utils/common_utils';
it
(
'
should return valid parameter
'
,
()
=>
{
it
(
'
should return valid parameter
'
,
()
=>
{
const
value
=
gl
.
utils
.
getParameterByName
(
'
scope
'
);
const
value
=
gl
.
utils
.
getParameterByName
(
'
scope
'
);
expect
(
gl
.
utils
.
getParameterByName
(
'
p
'
)).
toEqual
(
'
2
'
);
expect
(
value
).
toBe
(
'
all
'
);
expect
(
value
).
toBe
(
'
all
'
);
});
});
...
...
spec/javascripts/vue_shared/components/table_pagination_spec.js
View file @
b2b527a6
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
paginationComp
from
'
~/vue_shared/components/table_pagination.vue
'
;
import
paginationComp
from
'
~/vue_shared/components/table_pagination.vue
'
;
import
'
~/lib/utils/common_utils
'
;
describe
(
'
Pagination component
'
,
()
=>
{
describe
(
'
Pagination component
'
,
()
=>
{
let
component
;
let
component
;
let
PaginationComponent
;
let
PaginationComponent
;
let
spy
;
const
changeChanges
=
{
let
mountComponet
;
one
:
''
,
};
const
change
=
(
one
)
=>
{
changeChanges
.
one
=
one
;
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
spy
=
jasmine
.
createSpy
(
'
spy
'
);
PaginationComponent
=
Vue
.
extend
(
paginationComp
);
PaginationComponent
=
Vue
.
extend
(
paginationComp
);
mountComponet
=
function
(
props
)
{
return
new
PaginationComponent
({
propsData
:
props
,
}).
$mount
();
};
});
});
it
(
'
should render and start at page 1
'
,
()
=>
{
describe
(
'
render
'
,
()
=>
{
component
=
new
PaginationComponent
({
describe
(
'
prev button
'
,
()
=>
{
propsData
:
{
it
(
'
should be disabled and non clickable
'
,
()
=>
{
component
=
mountComponet
({
pageInfo
:
{
pageInfo
:
{
totalPages
:
10
,
nextPage
:
2
,
nextPage
:
2
,
previousPage
:
''
,
page
:
1
,
},
perPage
:
20
,
change
,
previousPage
:
NaN
,
total
:
84
,
totalPages
:
5
,
},
},
}).
$mount
();
change
:
spy
,
});
expect
(
component
.
$el
.
classList
).
toContain
(
'
gl-pagination
'
);
expect
(
component
.
$el
.
querySelector
(
'
.js-previous-button
'
).
classList
.
contains
(
'
disabled
'
),
).
toEqual
(
true
);
component
.
changePage
({
target
:
{
innerText
:
'
1
'
}
}
);
component
.
$el
.
querySelector
(
'
.js-previous-button a
'
).
click
(
);
expect
(
changeChanges
.
one
).
toEqual
(
1
);
expect
(
spy
).
not
.
toHaveBeenCalled
(
);
});
});
it
(
'
should go to the previous page
'
,
()
=>
{
it
(
'
should be enabled and clickable
'
,
()
=>
{
component
=
new
PaginationComponent
({
component
=
mountComponet
({
propsData
:
{
pageInfo
:
{
pageInfo
:
{
totalPages
:
10
,
nextPage
:
3
,
nextPage
:
3
,
page
:
2
,
perPage
:
20
,
previousPage
:
1
,
previousPage
:
1
,
total
:
84
,
totalPages
:
5
,
},
},
change
,
change
:
spy
,
},
});
}).
$mount
();
component
.
changePage
({
target
:
{
innerText
:
'
Prev
'
}
}
);
component
.
$el
.
querySelector
(
'
.js-previous-button a
'
).
click
(
);
expect
(
changeChanges
.
one
).
toEqual
(
1
);
expect
(
spy
).
toHaveBeenCalledWith
(
1
);
});
});
});
it
(
'
should go to the next page
'
,
()
=>
{
describe
(
'
first button
'
,
()
=>
{
component
=
new
PaginationComponent
(
{
it
(
'
should call the change callback with the first page
'
,
()
=>
{
propsData
:
{
component
=
mountComponet
(
{
pageInfo
:
{
pageInfo
:
{
totalPages
:
10
,
nextPage
:
3
,
nextPage
:
5
,
page
:
2
,
previousPage
:
3
,
perPage
:
20
,
},
previousPage
:
1
,
change
,
total
:
84
,
totalPages
:
5
,
},
},
}).
$mount
();
change
:
spy
,
});
const
button
=
component
.
$el
.
querySelector
(
'
.js-first-button a
'
);
component
.
changePage
({
target
:
{
innerText
:
'
Next
'
}
}
);
expect
(
button
.
textContent
.
trim
()).
toEqual
(
'
« First
'
);
expect
(
changeChanges
.
one
).
toEqual
(
5
);
button
.
click
();
expect
(
spy
).
toHaveBeenCalledWith
(
1
);
});
});
});
it
(
'
should go to the last page
'
,
()
=>
{
describe
(
'
last button
'
,
()
=>
{
component
=
new
PaginationComponent
(
{
it
(
'
should call the change callback with the last page
'
,
()
=>
{
propsData
:
{
component
=
mountComponet
(
{
pageInfo
:
{
pageInfo
:
{
totalPages
:
10
,
nextPage
:
3
,
nextPage
:
5
,
page
:
2
,
previousPage
:
3
,
perPage
:
20
,
},
previousPage
:
1
,
change
,
total
:
84
,
totalPages
:
5
,
},
},
}).
$mount
();
change
:
spy
,
});
const
button
=
component
.
$el
.
querySelector
(
'
.js-last-button a
'
);
expect
(
button
.
textContent
.
trim
()).
toEqual
(
'
Last »
'
);
component
.
changePage
({
target
:
{
innerText
:
'
Last »
'
}
}
);
button
.
click
(
);
expect
(
changeChanges
.
one
).
toEqual
(
10
);
expect
(
spy
).
toHaveBeenCalledWith
(
5
);
});
});
});
it
(
'
should go to the first page
'
,
()
=>
{
describe
(
'
next button
'
,
()
=>
{
component
=
new
PaginationComponent
(
{
it
(
'
should be disabled and non clickable
'
,
()
=>
{
propsData
:
{
component
=
mountComponet
(
{
pageInfo
:
{
pageInfo
:
{
totalPages
:
10
,
nextPage
:
5
,
nextPage
:
5
,
previousPage
:
3
,
page
:
5
,
},
perPage
:
20
,
change
,
previousPage
:
1
,
total
:
84
,
totalPages
:
5
,
},
},
}).
$mount
();
change
:
spy
,
});
component
.
changePage
({
target
:
{
innerText
:
'
« First
'
}
});
expect
(
component
.
$el
.
querySelector
(
'
.js-next-button
'
).
textContent
.
trim
(),
).
toEqual
(
'
Next
'
);
expect
(
changeChanges
.
one
).
toEqual
(
1
);
component
.
$el
.
querySelector
(
'
.js-next-button a
'
).
click
();
});
it
(
'
should not call change callback if clicked link is disabled
'
,
()
=>
{
expect
(
spy
).
not
.
toHaveBeenCalled
();
const
spy
=
jasmine
.
createSpy
(
'
spy
'
);
}
);
component
=
new
PaginationComponent
(
{
it
(
'
should be enabled and clickable
'
,
()
=>
{
propsData
:
{
component
=
mountComponet
(
{
pageInfo
:
{
pageInfo
:
{
nextPage
:
2
,
nextPage
:
4
,
page
:
1
,
page
:
3
,
perPage
:
20
,
perPage
:
20
,
previousPage
:
NaN
,
previousPage
:
2
,
total
:
84
,
total
:
84
,
totalPages
:
5
,
totalPages
:
5
,
},
},
change
:
spy
,
change
:
spy
,
},
});
}).
$mount
();
component
.
$el
.
querySelector
(
'
a
'
).
click
();
component
.
$el
.
querySelector
(
'
.js-next-button
a
'
).
click
();
expect
(
spy
).
not
.
toHaveBeenCalled
();
expect
(
spy
).
toHaveBeenCalledWith
(
4
);
});
});
});
it
(
'
should call change callback when link is clicked
'
,
()
=>
{
describe
(
'
numbered buttons
'
,
()
=>
{
const
spy
=
jasmine
.
createSpy
(
'
spy
'
);
it
(
'
should render 5 pages
'
,
()
=>
{
component
=
mountComponet
({
component
=
new
PaginationComponent
({
propsData
:
{
pageInfo
:
{
pageInfo
:
{
nextPage
:
3
,
nextPage
:
4
,
page
:
2
,
page
:
3
,
perPage
:
20
,
perPage
:
20
,
previousPage
:
1
,
previousPage
:
2
,
total
:
84
,
total
:
84
,
totalPages
:
5
,
totalPages
:
5
,
},
},
change
:
spy
,
change
:
spy
,
},
}).
$mount
();
component
.
$el
.
querySelector
(
'
a
'
).
click
();
expect
(
spy
).
toHaveBeenCalled
();
});
});
});
describe
(
'
paramHelper
'
,
()
=>
{
expect
(
component
.
$el
.
querySelectorAll
(
'
.page
'
).
length
).
toEqual
(
5
);
afterEach
(()
=>
{
window
.
history
.
pushState
({},
null
,
''
);
});
});
it
(
'
can parse url parameters correctly
'
,
()
=>
{
window
.
history
.
pushState
({},
null
,
'
?scope=all&p=2
'
);
const
scope
=
gl
.
utils
.
getParameterByName
(
'
scope
'
);
const
p
=
gl
.
utils
.
getParameterByName
(
'
p
'
);
expect
(
scope
).
toEqual
(
'
all
'
);
expect
(
p
).
toEqual
(
'
2
'
);
});
});
it
(
'
returns null if param not in url
'
,
()
=>
{
it
(
'
should render the spread operator
'
,
()
=>
{
window
.
history
.
pushState
({},
null
,
'
?p=2
'
);
component
=
mountComponet
({
pageInfo
:
{
const
scope
=
gl
.
utils
.
getParameterByName
(
'
scope
'
);
nextPage
:
4
,
const
p
=
gl
.
utils
.
getParameterByName
(
'
p
'
);
page
:
3
,
perPage
:
20
,
previousPage
:
2
,
total
:
84
,
totalPages
:
10
,
},
change
:
spy
,
});
expect
(
scope
).
toEqual
(
null
);
expect
(
component
.
$el
.
querySelector
(
'
.separator
'
).
textContent
.
trim
()).
toEqual
(
'
...
'
);
expect
(
p
).
toEqual
(
'
2
'
);
}
);
});
});
});
});
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