Skip to content

Commit cff9216

Browse files
committed
Prevent current page button to emit event
1 parent 6a9fe19 commit cff9216

4 files changed

+46
-1
lines changed

src/RenderlessPagination.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default {
115115
this.selectPage((this.currentPage + 1));
116116
},
117117
selectPage (page) {
118-
if (page === '...') {
118+
if (page === '...' || page === this.currentPage) {
119119
return;
120120
}
121121

tests/unit/Bootstrap4Pagination.spec.mjs

+15
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ test('has correct DOM structure when on page 2', function () {
146146
});
147147

148148
test('emits correct event', function () {
149+
exampleData.current_page = 1;
149150
const wrapper = mount(Bootstrap4Pagination, {
150151
props: {
151152
data: exampleData,
@@ -159,6 +160,20 @@ test('emits correct event', function () {
159160
expect(event[0]).toEqual([2]);
160161
});
161162

163+
test('does not emit event on current page', function () {
164+
exampleData.current_page = 1;
165+
const wrapper = mount(Bootstrap4Pagination, {
166+
props: {
167+
data: exampleData,
168+
},
169+
});
170+
171+
wrapper.findAll('li').at(1).find('a').trigger('click');
172+
173+
const event = wrapper.emitted('pagination-change-page');
174+
expect(event).toBeUndefined();
175+
});
176+
162177
test('has correct DOM structure when using slots', function () {
163178
const wrapper = mount(Bootstrap4Pagination, {
164179
props: { data: exampleData },

tests/unit/Bootstrap5Pagination.spec.mjs

+15
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ test('has correct DOM structure when on page 2', function () {
146146
});
147147

148148
test('emits correct event', function () {
149+
exampleData.current_page = 1;
149150
const wrapper = mount(Bootstrap5Pagination, {
150151
props: {
151152
data: exampleData,
@@ -159,6 +160,20 @@ test('emits correct event', function () {
159160
expect(event[0]).toEqual([2]);
160161
});
161162

163+
test('does not emit event on current page', function () {
164+
exampleData.current_page = 1;
165+
const wrapper = mount(Bootstrap5Pagination, {
166+
props: {
167+
data: exampleData,
168+
},
169+
});
170+
171+
wrapper.findAll('li').at(1).find('a').trigger('click');
172+
173+
const event = wrapper.emitted('pagination-change-page');
174+
expect(event).toBeUndefined();
175+
});
176+
162177
test('has correct DOM structure when using slots', function () {
163178
const wrapper = mount(Bootstrap5Pagination, {
164179
props: { data: exampleData },

tests/unit/TailwindPagination.spec.mjs

+15
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ test('has correct DOM structure when on page 2', function () {
118118
});
119119

120120
test('emits correct event', function () {
121+
exampleData.current_page = 1;
121122
const wrapper = mount(TailwindPagination, {
122123
props: {
123124
data: exampleData,
@@ -131,6 +132,20 @@ test('emits correct event', function () {
131132
expect(event[0]).toEqual([2]);
132133
});
133134

135+
test('does not emit event on current page', function () {
136+
exampleData.current_page = 1;
137+
const wrapper = mount(TailwindPagination, {
138+
props: {
139+
data: exampleData,
140+
},
141+
});
142+
143+
wrapper.findAll('button').at(1).trigger('click');
144+
145+
const event = wrapper.emitted('pagination-change-page');
146+
expect(event).toBeUndefined();
147+
});
148+
134149
test('has correct DOM structure when using slots', function () {
135150
const wrapper = mount(TailwindPagination, {
136151
props: { data: exampleData },

0 commit comments

Comments
 (0)