-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f75f7d
commit 7be3b2d
Showing
9 changed files
with
148 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import getFirstItem from '../get-first-item'; | ||
|
||
const pages = 7; | ||
|
||
describe('getFirstItem function', () => { | ||
it('should return 1 if the activeItem is 1', () => { | ||
const result = getFirstItem(pages, 1); | ||
expect(result).toEqual(1); | ||
}); | ||
it('should return 1 if the activeItem is 2', () => { | ||
const result = getFirstItem(pages, 2); | ||
expect(result).toEqual(1); | ||
}); | ||
it('should return 3 if the activeItem is 7', () => { | ||
const result = getFirstItem(pages, 7); | ||
expect(result).toEqual(3); | ||
}); | ||
it('should return 3 if the activeItem is 6', () => { | ||
const result = getFirstItem(pages, 6); | ||
expect(result).toEqual(3); | ||
}); | ||
it('should return 2 if the activeItem is 4', () => { | ||
const result = getFirstItem(pages, 4); | ||
expect(result).toEqual(2); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
src/components/Pagination/__test__/navigationButton.spec.js
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,21 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import NavigationButton from '../navigationButton'; | ||
|
||
const onCkickMockFn = jest.fn(); | ||
|
||
describe('<NavigationButton />', () => { | ||
it('should call the onClick function when clicked', () => { | ||
const component = mount(<NavigationButton onClick={onCkickMockFn} icon={<span />} />); | ||
const anchor = component.find('a'); | ||
anchor.simulate('click'); | ||
expect(onCkickMockFn).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should set the aria-disabled to the anchor element if disabled', () => { | ||
const component = mount( | ||
<NavigationButton onClick={onCkickMockFn} icon={<span />} disabled />, | ||
); | ||
const anchor = component.find('a'); | ||
expect(anchor.prop('aria-disabled')).toBe(true); | ||
}); | ||
}); |
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,43 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import PageButtons from '../pageButtons'; | ||
|
||
describe('<PageButtons />', () => { | ||
it('should render 5 children if pages is grater than 4', () => { | ||
const component = mount(<PageButtons pages={7} onChange={() => {}} activePage={3} />); | ||
const buttons = component.find('li'); | ||
expect(buttons.length).toBe(5); | ||
}); | ||
it('should render as many children as pages if pages is less than 4', () => { | ||
const component = mount(<PageButtons pages={4} onChange={() => {}} activePage={3} />); | ||
const buttons = component.find('li'); | ||
expect(buttons.length).toBe(4); | ||
}); | ||
it('should set the right className to the active page button', () => { | ||
const component = mount(<PageButtons pages={7} onChange={() => {}} activePage={3} />); | ||
const pageButtons = component.find('li.rainbow-pagination_button'); | ||
expect(pageButtons.get(2).props.className).toBe('rainbow-pagination_button rainbow-pagination_button--active'); | ||
}); | ||
it('should set aria-current to "page" to the active anchor element', () => { | ||
const component = mount(<PageButtons pages={7} onChange={() => {}} activePage={3} />); | ||
const pageButtons = component.find('a'); | ||
expect(pageButtons.get(2).props['aria-current']).toBe('page'); | ||
}); | ||
it('should set aria-current to undefined to the anchor element if is not active', () => { | ||
const component = mount(<PageButtons pages={7} onChange={() => {}} activePage={3} />); | ||
const pageButtons = component.find('a'); | ||
expect(pageButtons.get(1).props['aria-current']).toBe(undefined); | ||
}); | ||
it('should set aria-label to the anchor elements', () => { | ||
const component = mount(<PageButtons pages={7} onChange={() => {}} activePage={3} />); | ||
const pageButtons = component.find('a'); | ||
expect(pageButtons.get(1).props['aria-label']).toBe('Goto Page 2'); | ||
}); | ||
it('should call onChange if a page button is clicked', () => { | ||
const onChangeMockFn = jest.fn(); | ||
const component = mount(<PageButtons pages={1} onChange={onChangeMockFn} activePage={1} />); | ||
const anchor = component.find('a'); | ||
anchor.simulate('click'); | ||
expect(onChangeMockFn).toHaveBeenCalledWith(expect.any(Object), 1); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/components/Pagination/__test__/pagination.a11y.spec.js
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,13 @@ | ||
import ReactDOMServer from 'react-dom/server'; | ||
import { axe } from 'jest-axe'; | ||
import React from 'react'; | ||
import Pagination from '../'; | ||
|
||
describe('<Pagination/>', () => { | ||
it('should be accessible', async () => { | ||
expect.assertions(1); | ||
const html = ReactDOMServer.renderToString(<Pagination pages={5} activePage={3} />); | ||
const results = await axe(html); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
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,35 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import Pagination from '../'; | ||
|
||
describe('<Pagination />', () => { | ||
it('should disable the previous button if the active page is the first', () => { | ||
const component = mount(<Pagination pages={5} activePage={1} />); | ||
const navButtons = component.find('NavigationButton'); | ||
expect(navButtons.get(0).props.disabled).toBe(true); | ||
}); | ||
it('should disable the next button if the active page is the last', () => { | ||
const component = mount(<Pagination pages={5} activePage={5} />); | ||
const navButtons = component.find('NavigationButton'); | ||
expect(navButtons.get(1).props.disabled).toBe(true); | ||
}); | ||
it('should set aria-label to pagination', () => { | ||
const component = mount(<Pagination pages={5} activePage={1} />); | ||
expect(component.find('nav').prop('aria-label')).toBe('pagination'); | ||
}); | ||
it('shold call the onClick function with the right arguments when the previous page button is clicked', () => { | ||
const onChangeMockFn = jest.fn(); | ||
const component = mount(<Pagination pages={5} activePage={5} onChange={onChangeMockFn} />); | ||
const previousButton = component.find('[data-id="previous-page-button"]'); | ||
previousButton.simulate('click'); | ||
expect(onChangeMockFn).toHaveBeenCalledWith(expect.any(Object), 4); | ||
}); | ||
it('shold call the onClick function with the right arguments when the next page button is clicked', () => { | ||
const onChangeMockFn = jest.fn(); | ||
const component = mount(<Pagination pages={5} activePage={1} onChange={onChangeMockFn} />); | ||
const previousButton = component.find('[data-id="next-page-button"]'); | ||
previousButton.simulate('click'); | ||
expect(onChangeMockFn).toHaveBeenCalledWith(expect.any(Object), 2); | ||
}); | ||
}); | ||
|
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
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