Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Num 2255 part2 #486

Merged
merged 2 commits into from
Sep 5, 2023
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 @@ -34,7 +34,7 @@ export class ProjectEditorAccordionComponent {
@Input() isResearchersDisabled: boolean
@Input() isGeneralInfoDisabled: boolean
@Input() isCohortBuilderDisabled: boolean

@Input() isUserProjectAdmin: boolean
@Input() project: ProjectUiModel
@Input() projectForm: FormGroup
@Input() cohortGroup: CohortGroupUiModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
projectStatus === possibleStatus.Draft ||
projectStatus === possibleStatus.ChangeRequest ||
projectStatus === possibleStatus.Approved
)
) || !isUserProjectAdmin
"
*numUserHasRole="[availableRoles.StudyCoordinator]"
data-test="project-editor__buttons__start-edit-button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ describe('ProjectEditorButtonsComponent', () => {
const previewCases = [
{
status: ProjectStatus.Draft,
disabled: false,
disabled: true,
text: 'BUTTON.EDIT',
},
{
status: ProjectStatus.ChangeRequest,
disabled: false,
disabled: true,
text: 'BUTTON.EDIT',
},
{
status: ProjectStatus.Approved,
disabled: false,
disabled: true,
text: 'BUTTON.EDIT_RESEARCHERS',
},
{
Expand Down Expand Up @@ -145,7 +145,6 @@ describe('ProjectEditorButtonsComponent', () => {
text: 'BUTTON.EDIT',
},
]

test.each(previewCases)('shoud behave as expected', (testcase) => {
component.projectStatus = testcase.status
fixture.detectChanges()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ export class ProjectEditorButtonsComponent {
@Input() isResearchersDefined: boolean
@Input() isTemplatesDefined: boolean
@Input() isCohortDefined: boolean
@Input() isCohortValid: boolean
@Input() approverForm: FormGroup
@Input() isExportLoading: boolean
@Input() isSavedProject: boolean
@Input() isUserProjectAdmin: boolean

@Output() saveAll = new EventEmitter()
@Output() saveResearchers = new EventEmitter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import { AqlUiModel } from 'src/app/shared/models/aql/aql-ui.model'
import { mockAql1, mockAql3 } from 'src/mocks/data-mocks/aqls.mock'
import { IDetermineHits } from 'src/app/shared/components/editor-determine-hits/determine-hits.interface'
import { HttpErrorResponse } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { ProfileService } from 'src/app/core/services/profile/profile.service'

describe('ProjectEditorComponent On Creation', () => {
let component: ProjectEditorComponent
Expand Down Expand Up @@ -84,11 +86,16 @@ describe('ProjectEditorComponent On Creation', () => {
openToast: jest.fn(),
} as unknown as ToastMessageService

const profileService = {
apiBase: jest.fn(),
get: jest.fn(),
}

@Component({ selector: 'num-project-editor-accordion', template: '' })
class StubProjectEditorAccordionComponent {
@Input() isResearchersFetched: boolean
@Input() isCohortsFetched: boolean

@Input() isUserProjectAdmin: boolean
@Input() isTemplatesDisabled: boolean
@Input() isResearchersDisabled: boolean
@Input() isGeneralInfoDisabled: boolean
Expand Down Expand Up @@ -160,6 +167,7 @@ describe('ProjectEditorComponent On Creation', () => {
MaterialModule,
ReactiveFormsModule,
FontAwesomeTestingModule,
HttpClientTestingModule,
TranslateModule.forRoot(),
RouterTestingModule.withRoutes([{ path: '**', redirectTo: '' }]),
],
Expand All @@ -184,12 +192,31 @@ describe('ProjectEditorComponent On Creation', () => {
provide: ToastMessageService,
useValue: mockToastMessageService,
},
{
provide: ProfileService,
useValue: profileService,
},
],
}).compileComponents()
})

beforeEach(() => {
jest.spyOn(mockToastMessageService, 'openToast').mockImplementation()
jest.spyOn(profileService, 'apiBase').mockReturnValue('something')
jest.spyOn(profileService, 'get').mockImplementation(() => {
return of({
id: 'string',
username: 'string',
firstName: 'string',
lastName: 'string',
email: 'string',
createdTimestamp: 1,
roles: null,
approved: true,
organization: null,
})
})

TestBed.inject(Router)
fixture = TestBed.createComponent(ProjectEditorComponent)
component = fixture.componentInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ jest.mock('src/app/core/utils/download-file.utils', () => ({
downloadFile: jest.fn().mockImplementation(() => ''),
}))
import { downloadFile } from 'src/app/core/utils/download-file.utils'
import { ProfileService } from 'src/app/core/services/profile/profile.service'
import { HttpClientTestingModule } from '@angular/common/http/testing'

describe('ProjectEditorComponent', () => {
let component: ProjectEditorComponent
let fixture: ComponentFixture<ProjectEditorComponent>
let router: Router

const mockProfileService = {
get: jest.fn(),
} as unknown as ProfileService

const projectService = {
create: jest.fn(),
update: jest.fn(),
Expand Down Expand Up @@ -179,6 +185,7 @@ describe('ProjectEditorComponent', () => {
ProjectEditorApprovalStubComponent,
],
imports: [
HttpClientTestingModule,
BrowserAnimationsModule,
MaterialModule,
ReactiveFormsModule,
Expand Down Expand Up @@ -211,6 +218,10 @@ describe('ProjectEditorComponent', () => {
provide: ToastMessageService,
useValue: mockToast,
},
{
provide: ProfileService,
useValue: mockProfileService,
},
],
}).compileComponents()
})
Expand All @@ -229,6 +240,19 @@ describe('ProjectEditorComponent', () => {
jest.spyOn(projectService, 'update').mockImplementation(() => of(mockProject1))
jest.spyOn(projectService, 'updateStatusById').mockImplementation(() => of(mockProject1))
jest.spyOn(projectService, 'exportPrint').mockImplementation(() => of(''))
jest.spyOn(mockProfileService, 'get').mockImplementation(() =>
of({
id: 'string',
username: 'string',
firstName: 'string',
lastName: 'string',
email: 'string',
createdTimestamp: 1,
roles: null,
approved: true,
organization: null,
})
)
})

describe('When the components gets initialized and the cohortId is not specified', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h2>{{ 'NAVIGATION.DEFINE_PROJECT' | translate }}</h2>
<num-project-editor-buttons
[editorMode]="mode"
[projectStatus]="project.status"
[isUserProjectAdmin]="isUserProjectAdmin"
[isFormValid]="projectForm.valid"
[approverForm]="approverForm"
[isResearchersDefined]="project.researchers.length"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { ToastMessageType } from 'src/app/shared/models/toast-message-type.enum'
import { downloadFile } from 'src/app/core/utils/download-file.utils'
import { TranslateService } from '@ngx-translate/core'
import { ConnectorNodeType } from '../../../../shared/models/connector-node-type.enum'
import { ProfileService } from 'src/app/core/services/profile/profile.service'

@Component({
selector: 'num-project-editor',
Expand Down Expand Up @@ -84,6 +85,8 @@ export class ProjectEditorComponent implements OnInit, OnDestroy {

isCohortValid: any

isUserProjectAdmin: boolean

constructor(
private router: Router,
private route: ActivatedRoute,
Expand All @@ -92,7 +95,8 @@ export class ProjectEditorComponent implements OnInit, OnDestroy {
private adminService: AdminService,
private dialogService: DialogService,
private toast: ToastMessageService,
private translateService: TranslateService
private translateService: TranslateService,
private profileService: ProfileService
) {}

ngOnInit(): void {
Expand All @@ -116,6 +120,9 @@ export class ProjectEditorComponent implements OnInit, OnDestroy {
this.determineHitsContent = {
defaultMessage: 'PROJECT.HITS.MESSAGE_SET_ALL_PARAMETERS',
}
this.profileService.get().subscribe((user) => {
this.isUserProjectAdmin = user.id === this.project.coordinator.id
})
}

updateDetermineHits(count?: number | null, message?: string, isLoading = false): void {
Expand Down