Skip to content

Commit

Permalink
Adding test for sort list of repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianeMayara committed Sep 17, 2019
1 parent ccb29f3 commit c8ec35f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
46 changes: 45 additions & 1 deletion __mocks__/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,50 @@ const repositories = {
}
};

const sortedRepositories = {
request: {
query: LIST_REPOSITORIES,
variables: {
first: 20,
after: null,
orderBy: 'STARGAZERS',
orderDirection: 'DESC'
}
},
result: {
data: {
user: {
repositories: {
pageInfo: {
hasNextPage: true,
endCursor:
'Y3Vyc29yOnYyOpK5MjAxOS0wMy0yNFQxNTozNjo1OS0wMzowMM4Kk7uL'
},
nodes: [
{
id: 'MDEwOlJlcG9zaXRvcnkyMDc0ODYxMDY=',
name: 'my-repositories',
description: null,
isPrivate: false,
forkCount: 0,
updatedAt: '2019-09-11T06:53:35Z',
url: 'https://github.com/CristianeMayara/my-repositories',
primaryLanguage: {
name: 'JavaScript',
color: '#f1e05a'
},
licenseInfo: null,
stargazers: {
totalCount: 0
}
}
]
}
}
}
}
};

const commits = {
request: {
query: LIST_COMMITS,
Expand Down Expand Up @@ -103,4 +147,4 @@ const commits = {
}
};

export { repositories, commits };
export { repositories, sortedRepositories, commits };
35 changes: 32 additions & 3 deletions src/screens/RepositoryList/RepositoryList.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import React from 'react';
import { MockedProvider } from '@apollo/react-testing';
import { render, cleanup } from '@testing-library/react';
import {
render,
cleanup,
fireEvent,
waitForElement
} from '@testing-library/react';
import wait from 'waait';
import App from '../../App';
import { repositories, commits } from '../../../__mocks__/queries';
import {
sortedRepositories,
repositories,
commits
} from '../../../__mocks__/queries';

describe('RepositoryList component', () => {
afterEach(cleanup);
Expand All @@ -20,13 +29,33 @@ describe('RepositoryList component', () => {
expect(getByText('my-repositories')).toBeInTheDocument();
});
});

describe('when click on sort by startgazers button', () => {
it('should sort the list of repositories', async () => {
const { queryByTestId, getByTestId, getByText } = createComponent();

await waitForElement(() => queryByTestId('list-title'));

fireEvent.click(getByText(/Mais estrelas/i));

await wait(() =>
expect(queryByTestId('loading-icon')).not.toBeInTheDocument()
);

expect(getByTestId('list-title')).toBeInTheDocument();
expect(getByText('my-repositories')).toBeInTheDocument();
});
});
});

function createComponent(props = {}) {
const defaultProps = { ...props };

return render(
<MockedProvider mocks={[repositories, commits]} addTypename={false}>
<MockedProvider
mocks={[repositories, sortedRepositories, commits]}
addTypename={false}
>
<App {...defaultProps} />
</MockedProvider>
);
Expand Down

0 comments on commit c8ec35f

Please sign in to comment.