File size: 1,575 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import data from '../../shared/testing/data';
const user = data.users[1];
const communities = data.communities;
const channels = data.channels;
const threads = data.threads;
const publicAuthoredThreads = threads.filter(thread => {
  const community = communities.find(
    community => community.id === thread.communityId
  );
  const channel = channels.find(channel => channel.id === thread.channelId);
  return (
    thread.creatorId === user.id && !community.isPrivate && !channel.isPrivate
  );
});

describe('User View', () => {
  it('should render', () => {
    cy.visit(`/users/${user.username}`);
    cy.get('[data-cy="user-view"]').should('be.visible');
    cy.contains(user.username);
    cy.contains(user.name);
    cy.contains(user.description);
    cy.contains(user.website);
    cy.get('[data-cy="thread-feed"]').should('be.visible');
    publicAuthoredThreads.forEach(thread => {
      cy.contains(thread.content.title);
    });
  });

  it('should list the public communities a user is a member of, including their rep in that community', () => {
    cy.visit(`/users/${user.username}`);
    cy.get('[data-cy="user-view"]').should('be.visible');
    const usersCommunities = data.usersCommunities.filter(
      ({ userId }) => userId === user.id
    );
    const communityIds = usersCommunities.map(({ communityId }) => communityId);
    const communities = data.communities.filter(
      ({ id, isPrivate }) => communityIds.includes(id) && isPrivate !== true
    );
    communities.forEach(community => {
      cy.contains(community.name);
    });
  });
});