-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout de la pagination sur la page /exploitations
- Loading branch information
1 parent
037c32c
commit fe03189
Showing
5 changed files
with
183 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { describe, it, expect } from 'vitest'; | ||
import Pagination from '@/components/widgets/Pagination.vue'; | ||
|
||
describe('Pagination.vue', () => { | ||
const getWrapper = (page) => | ||
mount(Pagination, { | ||
props: { | ||
currentPage: page, | ||
maxPage: 5, | ||
}, | ||
}); | ||
|
||
it('renders correctly', () => { | ||
const wrapper = getWrapper(1); | ||
expect(wrapper.find('.fr-btns-group--pagination').exists()).toBe(true); | ||
}); | ||
|
||
it('emits changePage event with correct value when select option is changed', async () => { | ||
const wrapper = getWrapper(1); | ||
const select = wrapper.find('select'); | ||
await select.setValue(3); | ||
expect(wrapper.emitted().changePage[0]).toEqual([3]); | ||
expect(select.element.value).toBe('3'); | ||
}); | ||
|
||
it('emits changePage event with correct value when previous button is clicked', async () => { | ||
const wrapper = getWrapper(2); | ||
const prevButton = wrapper.find('.pagination-page-previous'); | ||
await prevButton.trigger('click'); | ||
expect(wrapper.emitted().changePage[0]).toEqual([1]); | ||
}); | ||
|
||
it('emits changePage event with correct value when next button is clicked', async () => { | ||
const wrapper = getWrapper(2); | ||
const nextButton = wrapper.find('.pagination-page-next'); | ||
await nextButton.trigger('click'); | ||
expect(wrapper.emitted().changePage[0]).toEqual([3]); | ||
}); | ||
|
||
it('disables previous button on the first page', () => { | ||
const wrapper = getWrapper(1); | ||
const prevButton = wrapper.find('.pagination-page-previous'); | ||
expect(prevButton.attributes('disabled')).not.toBeUndefined(); | ||
}); | ||
|
||
it('disables next button on the last page', () => { | ||
const wrapper = getWrapper(5); | ||
const nextButton = wrapper.find('.pagination-page-next'); | ||
expect(nextButton.attributes('disabled')).not.toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<template> | ||
<ul class="fr-btns-group fr-btns-group--center fr-btns-group--inline fr-btns-group--pagination"> | ||
<li> | ||
<div class="fr-select-group fr-select-group--inline"> | ||
<select | ||
class="fr-select" | ||
id="search-results-page-selector" | ||
name="page" | ||
:value="currentPage" | ||
@change="(event) => $emit('changePage', parseInt(event.target.value))" | ||
> | ||
<option value="" disabled hidden>Sélectionner un numéro de pagination</option> | ||
<option :value="page" :key="page" v-for="page in maxPage">{{ page }}</option> | ||
</select> | ||
<label class="fr-label" for="search-results-page-selector"> sur {{ maxPage }} pages </label> | ||
</div> | ||
</li> | ||
<li> | ||
<button | ||
class="fr-btn fr-btn--tertiary-no-outline fr-icon-arrow-left-s-line pagination-page-previous" | ||
:disabled="maxPage < 2 || currentPage === 1" | ||
@click="$emit('changePage', currentPage - 1)" | ||
> | ||
Page précédente | ||
</button> | ||
</li> | ||
<li> | ||
<button | ||
class="fr-btn fr-btn--tertiary-no-outline fr-icon-arrow-right-s-line pagination-page-next" | ||
:disabled="maxPage < 2 || currentPage === maxPage" | ||
@click="$emit('changePage', currentPage + 1)" | ||
> | ||
Page suivante | ||
</button> | ||
</li> | ||
</ul> | ||
</template> | ||
|
||
<script setup> | ||
defineProps(['currentPage', 'maxPage']); | ||
defineEmits('changePage'); | ||
</script> | ||
|
||
<style scoped> | ||
.fr-btns-group--pagination { | ||
.fr-label, .fr-select { | ||
font-size: inherit; /* reset size so as they are consistent */ | ||
} | ||
.fr-btn { | ||
margin: 0; | ||
} | ||
} | ||
.fr-select-group--inline { | ||
display: flex; | ||
align-items: center; | ||
select { | ||
background-color: transparent; | ||
box-shadow: none; | ||
text-align: right; | ||
width: 6rem; /* up to 3 digits, so 999 pages */ | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters