Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class TestDataService(
tryUntilItDoesntBreakConstraint {
executeInNewTransaction(transactionManager) {
builder.data.userAccounts.forEach {
userAccountService.findActive(it.self.username)?.let { user ->
userAccountService.findAnyByUsername(it.self.username)?.let { user ->
notificationService.deleteNotificationsOfUser(user.id)
userAccountService.delete(user)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import java.util.Date

class ContributorsTestData {
lateinit var project: Project
lateinit var publicProject: Project
lateinit var publicEmptyProject: Project
lateinit var admin: UserAccount
lateinit var contributor: UserAccount
lateinit var contributor2: UserAccount
Expand Down Expand Up @@ -65,5 +67,17 @@ class ContributorsTestData {
type = ProjectPermissionType.VIEW
}
}.self

publicProject =
addProject(organizationOwner = adminBuilder.defaultOrganizationBuilder.self) {
name = "Contributors public project"
public = true
}.self

publicEmptyProject =
addProject(organizationOwner = adminBuilder.defaultOrganizationBuilder.self) {
name = "Contributors public empty project"
public = true
}.self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ class UserAccountService(
return userAccountRepository.findActiveOrDisabled(username)
}

fun findAnyByUsername(username: String): UserAccount? {
return userAccountRepository.findByExactUsername(username).orElse(null)
}

operator fun get(username: String): UserAccount {
return this.findActive(username) ?: throw NotFoundException(Message.USER_NOT_FOUND)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.tolgee.controllers.internal.e2eData

import io.tolgee.component.CurrentDateProvider
import io.tolgee.controllers.internal.InternalController
import io.tolgee.development.testDataBuilder.builders.TestDataBuilder
import io.tolgee.development.testDataBuilder.data.ContributorsTestData
import io.tolgee.model.activity.ActivityRevision
import jakarta.persistence.EntityManager
import org.springframework.beans.factory.annotation.Autowired
import java.util.Date

@InternalController(["internal/e2e-data/members-community"])
class MembersCommunityE2eDataController : AbstractE2eDataController() {
@Autowired
private lateinit var entityManager: EntityManager

@Autowired
private lateinit var currentDateProvider: CurrentDateProvider

private lateinit var data: ContributorsTestData

override val testData: TestDataBuilder
get() = ContributorsTestData().also { data = it }.root

override fun afterTestDataStored(data: TestDataBuilder) {
try {
listOf(this.data.contributor.id, this.data.contributor2.id).forEach { authorId ->
recordActivity(this.data.publicProject.id, authorId, FIRST_CONTRIBUTION_AT)
recordActivity(this.data.publicProject.id, authorId, LAST_CONTRIBUTION_AT)
}
} finally {
currentDateProvider.forcedDate = null
}
}

private fun recordActivity(
projectId: Long,
authorId: Long,
at: Date,
) {
currentDateProvider.forcedDate = at
entityManager.persist(
ActivityRevision().apply {
this.projectId = projectId
this.authorId = authorId
},
)
entityManager.flush()
}

companion object {
private val FIRST_CONTRIBUTION_AT = Date(1_560_600_000_000)
private val LAST_CONTRIBUTION_AT = Date(1_623_758_400_000)
}
}
2 changes: 2 additions & 0 deletions e2e/cypress/common/apiCalls/testData/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const communityContributionData = generateTestDataObject(
'community-contribution'
);

export const membersCommunityData = generateTestDataObject('members-community');

export const organizationNewTestData =
generateTestDataObject('organization-new');

Expand Down
93 changes: 93 additions & 0 deletions e2e/cypress/e2e/projects/communityMembersTab.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { gcy, gcyAdvanced, visitProjectMembers } from '../../common/shared';
import { login } from '../../common/apiCalls/common';
import {
getProjectByNameFromTestData,
membersCommunityData,
} from '../../common/apiCalls/testData/testData';
import { waitForGlobalLoading } from '../../common/loading';

describe('Community tab on the Members page', () => {
beforeEach(() => {
membersCommunityData.clean();
});

afterEach(() => {
membersCommunityData.clean();
});

it('shows Team and Community tabs on a public project and lists non-member contributors without email', () => {
membersCommunityData.generateStandard().then((res) => {
const project = getProjectByNameFromTestData(
res.body,
'Contributors public project'
);
login('admin@contributors.com');
visitProjectMembers(project.id);
waitForGlobalLoading();

gcy('project-members-tab-team').should('be.visible');
gcy('project-members-tab-community').should('be.visible').click();

gcy('project-contributor-item').should('have.length', 2);
gcyAdvanced({
value: 'project-contributor-item',
name: 'Cora Contributor',
}).should('exist');
gcyAdvanced({
value: 'project-contributor-item',
name: 'Cody Contributor',
}).should('exist');

gcy('project-member-item').should('not.be.visible');

// Dates are seeded 2019 (first) and 2021 (last) by MembersCommunityE2eDataController.
gcy('project-contributor-item-first-contribution')
.first()
.should('be.visible')
.and('contain', '2019');
gcy('project-contributor-item-last-contribution')
.first()
.should('be.visible')
.and('contain', '2021');

cy.contains('contributor@contributors.com').should('not.exist');
cy.contains('contributor2@contributors.com').should('not.exist');

gcy('project-members-tab-team').click();
gcy('project-member-item').should('be.visible');
gcy('project-contributor-item').should('not.exist');
});
});

it('hides the tabs on a public project with no contributors and shows the member list', () => {
membersCommunityData.generateStandard().then((res) => {
const project = getProjectByNameFromTestData(
res.body,
'Contributors public empty project'
);
login('admin@contributors.com');
visitProjectMembers(project.id);
waitForGlobalLoading();

gcy('project-member-item').should('be.visible');
gcy('project-members-tab-team').should('not.exist');
gcy('project-members-tab-community').should('not.exist');
});
});

it('hides the tabs on a private project and shows the member list', () => {
membersCommunityData.generateStandard().then((res) => {
const project = getProjectByNameFromTestData(
res.body,
'Contributors project'
);
login('admin@contributors.com');
visitProjectMembers(project.id);
waitForGlobalLoading();

gcy('project-member-item').should('be.visible');
gcy('project-members-tab-team').should('not.exist');
gcy('project-members-tab-community').should('not.exist');
});
});
});
5 changes: 5 additions & 0 deletions e2e/cypress/support/dataCyType.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ declare namespace DataCy {
"project-branch-merge-change": true;
"project-branch-merge-delete-branch-checkbox": true;
"project-branch-merge-detail": true;
"project-contributor-item": true;
"project-contributor-item-first-contribution": true;
"project-contributor-item-last-contribution": true;
"project-dashboard-activity-chart": true;
"project-dashboard-activity-list": true;
"project-dashboard-base-word-count": true;
Expand Down Expand Up @@ -589,6 +592,8 @@ declare namespace DataCy {
"project-member-item": true;
"project-member-revoke-button": true;
"project-members-invitation-item": true;
"project-members-tab-community": true;
"project-members-tab-team": true;
"project-menu-item": true;
"project-menu-item-ai": true;
"project-menu-item-branches": true;
Expand Down
Loading
Loading