* feat: v1 of the profile form * feat: fix inputs and create a handleChange event * feat: update the submit values to represent values from the form * feat: ensure that errors and success is handled on send * refactor: remove unused code * feat: replace the old profile form with a new one * fix: use the renames file * refactor: safety net for groups * chore: fix code climate issue * tests: amend + add tests * test: fix broken spec * feat: update the setup for the test * tests: refactored them to move the fake response into the before all * feat: clunky way to quickly cater for color field since it was a quick and easy implementation * feat: add a field.description to the color field * refactor: pull some duplicate code into a new function * chore: cater for a textarea field * overflow issue * refactor: use FormField instead of manual divs * Update spec/requests/users_onboarding_spec.rb Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com> * Update spec/requests/users_onboarding_spec.rb Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com> * refactor: move out of method and into a constant * refactor: user_onboarding_update to be more readable * refactor: use current.save instead of declaring a new variable * refactor: remove explicit check for bookean * refactor: use request from '@utilities/http' instead :) * refactor: no need for if with destructured groups * refactor: move color field to its own component * chore: remove colorfield now thats its a component * fix: forgot about field * feat: a text area component * chore: remove textField function in favor of component * refactor: checkbox refactor * refactor: add a switch statement * chore: move into a more organized folder * fix: move the handler to props and off from field * fix: add a conditional so we dont hit an error undefined method `success?' for nil:NilClass * refactor: change from component to function * feat: add a key attribute * refactor: add role for readers * refactor: remove unnecessary guard clauses * refactor: use function instead of an arrow * chore: document components * test * padding * fixes * test: fix the tests by using more general matchers Co-authored-by: Paweł Ludwiczak <ludwiczakpawel@gmail.com> Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
160 lines
4.3 KiB
JavaScript
160 lines
4.3 KiB
JavaScript
import { h } from 'preact';
|
|
import { render } from '@testing-library/preact';
|
|
import fetch from 'jest-fetch-mock';
|
|
import '@testing-library/jest-dom';
|
|
|
|
import { axe } from 'jest-axe';
|
|
import FollowUsers from '../FollowUsers';
|
|
|
|
global.fetch = fetch;
|
|
|
|
describe('FollowUsers', () => {
|
|
const renderFollowUsers = () =>
|
|
render(
|
|
<FollowUsers
|
|
next={jest.fn()}
|
|
prev={jest.fn()}
|
|
currentSlideIndex={3}
|
|
slidesCount={5}
|
|
communityConfig={{
|
|
communityName: 'Community Name',
|
|
communityLogo: '/x.png',
|
|
communityBackground: '/y.jpg',
|
|
communityDescription: 'Some community description',
|
|
}}
|
|
previousLocation={null}
|
|
/>,
|
|
);
|
|
|
|
const getUserData = () =>
|
|
JSON.stringify({
|
|
followed_tag_names: ['javascript'],
|
|
profile_image_90: 'mock_url_link',
|
|
name: 'firstname lastname',
|
|
username: 'username',
|
|
});
|
|
|
|
const fakeUsersResponse = JSON.stringify([
|
|
{
|
|
id: 1,
|
|
name: 'Ben Halpern',
|
|
profile_image_url: 'apple-icon.png',
|
|
},
|
|
{
|
|
id: 2,
|
|
name: 'Krusty the Clown',
|
|
profile_image_url: 'clown.jpg',
|
|
},
|
|
{
|
|
id: 3,
|
|
name: 'dev.to staff',
|
|
profile_image_url: 'dev.jpg',
|
|
},
|
|
]);
|
|
|
|
beforeAll(() => {
|
|
document.head.innerHTML =
|
|
'<meta name="csrf-token" content="some-csrf-token" />';
|
|
document.body.setAttribute('data-user', getUserData());
|
|
});
|
|
|
|
it('should have no a11y violations when rendering users', async () => {
|
|
fetch.mockResponseOnce(fakeUsersResponse);
|
|
|
|
const { container } = renderFollowUsers();
|
|
const results = await axe(container);
|
|
|
|
expect(results).toHaveNoViolations();
|
|
});
|
|
|
|
it('should render the correct users', async () => {
|
|
fetch.mockResponseOnce(fakeUsersResponse);
|
|
const { findByText } = renderFollowUsers();
|
|
|
|
const user1 = await findByText(/Ben Halpern/i);
|
|
const user2 = await findByText(/Krusty the Clown/i);
|
|
const user3 = await findByText(/dev.to staff/i);
|
|
|
|
expect(user1).toBeInTheDocument();
|
|
expect(user2).toBeInTheDocument();
|
|
expect(user3).toBeInTheDocument();
|
|
});
|
|
|
|
it('should render the correct navigation button on first load', () => {
|
|
fetch.mockResponseOnce(fakeUsersResponse);
|
|
|
|
const { queryByText } = renderFollowUsers();
|
|
|
|
expect(queryByText(/skip for now/i)).toBeDefined();
|
|
});
|
|
|
|
it('should update the navigation button text and follow status when you follow users', async () => {
|
|
fetch.mockResponse(fakeUsersResponse);
|
|
|
|
const { queryByText, findByText, findAllByTestId } = renderFollowUsers();
|
|
|
|
const userButtons = await findAllByTestId('onboarding-user-button');
|
|
|
|
expect(queryByText(/skip for now/i)).toBeDefined();
|
|
expect(queryByText(/You're not following anyone/i)).toBeDefined();
|
|
|
|
// follow the first user
|
|
const firstUser = userButtons[0];
|
|
firstUser.click();
|
|
|
|
await findByText('Following');
|
|
|
|
expect(queryByText(/You're following 1 person/i)).toBeDefined();
|
|
expect(queryByText(/continue/i)).toBeDefined();
|
|
|
|
// follow the second user
|
|
const secondUser = userButtons[1];
|
|
secondUser.click();
|
|
|
|
await findByText('Following');
|
|
|
|
expect(queryByText(/You're following 2 people/i)).toBeDefined();
|
|
expect(queryByText(/continue/i)).toBeDefined();
|
|
});
|
|
|
|
it('should have a functioning de/select all toggle', async () => {
|
|
fetch.mockResponse(fakeUsersResponse);
|
|
const {
|
|
getByText,
|
|
queryByText,
|
|
findByText,
|
|
findAllByText,
|
|
} = renderFollowUsers();
|
|
|
|
// select all then test following count
|
|
const followAllSelector = await findByText(/Select all 3 people/i);
|
|
|
|
followAllSelector.click();
|
|
|
|
await findAllByText('Following');
|
|
|
|
expect(queryByText('Follow')).toBeNull();
|
|
queryByText(/You're following 3 people (everyone)/i);
|
|
|
|
// deselect all then test following count
|
|
const deselecAllSelector = await findByText(/Deselect all/i);
|
|
|
|
deselecAllSelector.click();
|
|
await findAllByText('Follow');
|
|
|
|
expect(queryByText('Following')).toBeNull();
|
|
getByText(/You're not following anyone/i);
|
|
});
|
|
|
|
it('should render a stepper', () => {
|
|
const { queryByTestId } = renderFollowUsers();
|
|
|
|
expect(queryByTestId('stepper')).toBeDefined();
|
|
});
|
|
|
|
it('should render a back button', () => {
|
|
const { queryByTestId } = renderFollowUsers();
|
|
|
|
expect(queryByTestId('back-button')).toBeDefined();
|
|
});
|
|
});
|