Skip to content

Commit

Permalink
creator-tools-collab-bug (#226)
Browse files Browse the repository at this point in the history
* Showing more projects button for collaborators and not just creators with tests.
Updated tests with creators so we don't miss any collaborators.
Added a helper User that is a collaborator and not a creator.
  • Loading branch information
eoji committed Mar 21, 2018
1 parent 1cecb8b commit 1ed19cf
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ViewModel(final @NonNull Environment environment) {
final Observable<User> user = this.currentUser.observable();

this.otherProjectsButtonIsGone = user
.map(User::createdProjectsCount)
.map(User::memberProjectsCount)
.filter(ObjectUtils::isNotNull)
.map(count -> count <= 1)
.compose(bindToLifecycle());
Expand Down
8 changes: 8 additions & 0 deletions app/src/test/java/com/kickstarter/factories/UserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ public static User socialUser() {
return user().toBuilder().social(true).build();
}

public static User collaborator() {
return user()
.toBuilder()
.createdProjectsCount(0)
.memberProjectsCount(10)
.build();
}

public static User creator() {
return user()
.toBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected void setUpEnvironment(final @NonNull Environment environment) {
@Test
public void testMessagesButtonIsGone() {
final User creator = UserFactory.creator();
final CurrentUserType currentUser = new MockCurrentUser(UserFactory.user());
final CurrentUserType currentUser = new MockCurrentUser(UserFactory.collaborator());

final Project project = ProjectFactory.project().toBuilder().creator(creator).build();
final ProjectStatsEnvelope projectStatsEnvelope = ProjectStatsEnvelopeFactory.projectStatsEnvelope();
Expand All @@ -64,28 +64,28 @@ public void testMessagesButtonIsGone() {
this.vm.inputs.projectAndStats(Pair.create(project, projectStatsEnvelope));

// Messages button is gone if current user is not the project creator (e.g. a collaborator).
this.messagesButtonIsGone.assertValues(true);
this.messagesButtonIsGone.assertValue(true);
}

@Test
public void testOtherProjectsButtonIsGone_WhenCreatorHas1Project() {
final User creatorWith1Project = UserFactory.creator().toBuilder().createdProjectsCount(1).build();
final CurrentUserType creator = new MockCurrentUser(creatorWith1Project);
public void testOtherProjectsButtonIsGone_isTrue_WhenCollaboratorHas1Project() {
final User collaboratorWith1Project = UserFactory.collaborator().toBuilder().memberProjectsCount(1).build();
final CurrentUserType collaborator = new MockCurrentUser(collaboratorWith1Project);

setUpEnvironment(environment().toBuilder().currentUser(creator).build());
setUpEnvironment(environment().toBuilder().currentUser(collaborator).build());
this.vm.inputs.projectAndStats(Pair.create(ProjectFactory.project(), ProjectStatsEnvelopeFactory.projectStatsEnvelope()));

this.otherProjectsButtonIsGone.assertValues(true);
this.otherProjectsButtonIsGone.assertValue(true);
}

@Test
public void testOtherProjectsButtonIsGone_WhenCreatorHasManyProjects() {
final CurrentUserType creator = new MockCurrentUser(UserFactory.creator());
public void testOtherProjectsButtonIsGone_isFalse_WhenCollaboratorHasManyProjects() {
final CurrentUserType collaborator = new MockCurrentUser(UserFactory.collaborator());

setUpEnvironment(environment().toBuilder().currentUser(creator).build());
setUpEnvironment(environment().toBuilder().currentUser(collaborator).build());
this.vm.inputs.projectAndStats(Pair.create(ProjectFactory.project(), ProjectStatsEnvelopeFactory.projectStatsEnvelope()));

this.otherProjectsButtonIsGone.assertValues(false);
this.otherProjectsButtonIsGone.assertValue(false);
}

@Test
Expand All @@ -95,7 +95,7 @@ public void testProjectBackersCountText() {

setUpEnvironment(environment());
this.vm.inputs.projectAndStats(Pair.create(project, projectStatsEnvelope));
this.projectBackersCountText.assertValues("10");
this.projectBackersCountText.assertValue("10");
}

@Test
Expand All @@ -105,7 +105,7 @@ public void testProjectNameTextViewText() {

setUpEnvironment(environment());
this.vm.inputs.projectAndStats(Pair.create(project, projectStatsEnvelope));
this.projectNameTextViewText.assertValues("somebody once told me");
this.projectNameTextViewText.assertValue("somebody once told me");
}

@Test
Expand All @@ -118,63 +118,63 @@ public void testPercentageFunded() {
final String percentageFundedOutput = NumberUtils.flooredPercentage(project.percentageFunded());
this.percentageFunded.assertValues(percentageFundedOutput);
final int percentageFundedProgressOutput = ProgressBarUtils.progress(project.percentageFunded());
this.percentageFundedProgress.assertValues(percentageFundedProgressOutput);
this.percentageFundedProgress.assertValue(percentageFundedProgressOutput);
}

@Test
public void testProgressBarBackground_LiveProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_LIVE));
this.progressBarBackground.assertValues(R.drawable.progress_bar_green_horizontal);
this.progressBarBackground.assertValue(R.drawable.progress_bar_green_horizontal);
}

@Test
public void testProgressBarBackground_SubmittedProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_SUBMITTED));
this.progressBarBackground.assertValues(R.drawable.progress_bar_green_horizontal);
this.progressBarBackground.assertValue(R.drawable.progress_bar_green_horizontal);
}

@Test
public void testProgressBarBackground_StartedProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_STARTED));
this.progressBarBackground.assertValues(R.drawable.progress_bar_green_horizontal);
this.progressBarBackground.assertValue(R.drawable.progress_bar_green_horizontal);
}

@Test
public void testProgressBarBackground_SuccessfulProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_SUCCESSFUL));
this.progressBarBackground.assertValues(R.drawable.progress_bar_green_horizontal);
this.progressBarBackground.assertValue(R.drawable.progress_bar_green_horizontal);
}

@Test
public void testProgressBarBackground_FailedProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_FAILED));
this.progressBarBackground.assertValues(R.drawable.progress_bar_grey_horizontal);
this.progressBarBackground.assertValue(R.drawable.progress_bar_grey_horizontal);
}

@Test
public void testProgressBarBackground_CanceledProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_CANCELED));
this.progressBarBackground.assertValues(R.drawable.progress_bar_grey_horizontal);
this.progressBarBackground.assertValue(R.drawable.progress_bar_grey_horizontal);
}

@Test
public void testProgressBarBackground_SuspendedProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_SUSPENDED));
this.progressBarBackground.assertValues(R.drawable.progress_bar_grey_horizontal);
this.progressBarBackground.assertValue(R.drawable.progress_bar_grey_horizontal);
}

@Test
Expand All @@ -190,7 +190,7 @@ public void testStartMessagesActivity() {

// Messages button is shown to project creator, messages activity starts.
this.messagesButtonIsGone.assertValues(false);
this.startMessageThreadsActivity.assertValues(Pair.create(project, RefTag.dashboard()));
this.startMessageThreadsActivity.assertValue(Pair.create(project, RefTag.dashboard()));
}

@Test
Expand All @@ -201,7 +201,7 @@ public void testStartProjectActivity() {
setUpEnvironment(environment());
this.vm.inputs.projectAndStats(Pair.create(project, projectStatsEnvelope));
this.vm.inputs.projectButtonClicked();
this.startProjectActivity.assertValues(Pair.create(project, RefTag.dashboard()));
this.startProjectActivity.assertValue(Pair.create(project, RefTag.dashboard()));
}

@Test
Expand All @@ -212,7 +212,7 @@ public void testTimeRemainingText() {
final int deadlineVal = ProjectUtils.deadlineCountdownValue(project);

this.vm.inputs.projectAndStats(Pair.create(project, projectStatsEnvelope));
this.timeRemainingText.assertValues(NumberUtils.format(deadlineVal));
this.timeRemainingText.assertValue(NumberUtils.format(deadlineVal));
}

private Pair<Project, ProjectStatsEnvelope> getProjectAndStats(final String state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void testBuildCheck() {
}

@Test
public void testCreatorDashboardButtonIsGone__notCreatorOrCollaborator() {
public void testCreatorDashboardButtonIsGone_isTrue_WhenCreatorOrCollaborator() {
final User notCreator = UserFactory.user().toBuilder().memberProjectsCount(0).build();
final MockCurrentUser currentUser = new MockCurrentUser(notCreator);

Expand All @@ -71,11 +71,11 @@ public void testCreatorDashboardButtonIsGone__notCreatorOrCollaborator() {

this.vm = new DiscoveryViewModel.ViewModel(env);
this.vm.outputs.creatorDashboardButtonIsGone().subscribe(this.creatorDashboardButtonIsGone);
this.creatorDashboardButtonIsGone.assertValues(true);
this.creatorDashboardButtonIsGone.assertValue(true);
}

@Test
public void testCreatorDashboardButtonIsGone__isCreatorOrCollaborator() {
public void testCreatorDashboardButtonIsGone_isFalse_WhenCreator() {
final User creator = UserFactory.creator();
final MockCurrentUser currentUser = new MockCurrentUser(creator);

Expand All @@ -85,7 +85,21 @@ public void testCreatorDashboardButtonIsGone__isCreatorOrCollaborator() {

this.vm = new DiscoveryViewModel.ViewModel(env);
this.vm.outputs.creatorDashboardButtonIsGone().subscribe(this.creatorDashboardButtonIsGone);
this.creatorDashboardButtonIsGone.assertValues(false);
this.creatorDashboardButtonIsGone.assertValue(false);
}

@Test
public void testCreatorDashboardButtonIsGone_isFalse_WhenCollaborator() {
final User collaborator = UserFactory.collaborator();
final MockCurrentUser currentUser = new MockCurrentUser(collaborator);

final Environment env = environment().toBuilder()
.currentUser(currentUser)
.build();

this.vm = new DiscoveryViewModel.ViewModel(env);
this.vm.outputs.creatorDashboardButtonIsGone().subscribe(this.creatorDashboardButtonIsGone);
this.creatorDashboardButtonIsGone.assertValue(false);
}

@Test
Expand Down

0 comments on commit 1ed19cf

Please sign in to comment.