-
Notifications
You must be signed in to change notification settings - Fork 23
[ENG-9548] fix(wiki-list): Make rename wiki #738
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
Merged
brianjgeiger
merged 3 commits into
CenterForOpenScience:feature/pbs-25.04
from
bodintsov:fix/unable-to-rename-wiki
Nov 6, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/app/shared/components/wiki/rename-wiki-dialog/rename-wiki-dialog.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <form [formGroup]="renameWikiForm" (ngSubmit)="submitForm()"> | ||
| <osf-text-input | ||
| [control]="renameWikiForm.controls['name']" | ||
| [placeholder]="'project.wiki.addNewWikiPlaceholder'" | ||
| [maxLength]="inputLimits.fullName.maxLength" | ||
| > | ||
| </osf-text-input> | ||
|
|
||
| <div class="flex justify-content-end gap-2 mt-4"> | ||
| <p-button [label]="'common.buttons.cancel' | translate" severity="info" (onClick)="dialogRef.close()" /> | ||
| <p-button | ||
| [label]="'common.buttons.rename' | translate" | ||
| type="submit" | ||
| [loading]="isSubmitting()" | ||
| [disabled]="renameWikiForm.invalid" | ||
| /> | ||
| </div> | ||
| </form> |
Empty file.
121 changes: 121 additions & 0 deletions
121
src/app/shared/components/wiki/rename-wiki-dialog/rename-wiki-dialog.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { MockComponent, MockProvider } from 'ng-mocks'; | ||
|
|
||
| import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog'; | ||
|
|
||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { ToastService } from '@osf/shared/services/toast.service'; | ||
| import { WikiSelectors } from '@osf/shared/stores/wiki'; | ||
|
|
||
| import { TextInputComponent } from '../../text-input/text-input.component'; | ||
|
|
||
| import { RenameWikiDialogComponent } from './rename-wiki-dialog.component'; | ||
|
|
||
| import { TranslateServiceMock } from '@testing/mocks/translate.service.mock'; | ||
| import { provideMockStore } from '@testing/providers/store-provider.mock'; | ||
|
|
||
| describe('RenameWikiDialogComponent', () => { | ||
| let component: RenameWikiDialogComponent; | ||
| let fixture: ComponentFixture<RenameWikiDialogComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [RenameWikiDialogComponent, MockComponent(TextInputComponent)], | ||
| providers: [ | ||
| TranslateServiceMock, | ||
| MockProvider(DynamicDialogRef), | ||
| MockProvider(DynamicDialogConfig, { | ||
| data: { | ||
| resourceId: 'project-123', | ||
| wikiName: 'Wiki Name', | ||
| }, | ||
| }), | ||
| MockProvider(ToastService), | ||
| provideMockStore({ | ||
| selectors: [{ selector: WikiSelectors.getWikiSubmitting, value: false }], | ||
| }), | ||
| ], | ||
| }).compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(RenameWikiDialogComponent); | ||
| component = fixture.componentInstance; | ||
|
|
||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should initialize form with current name', () => { | ||
| expect(component.renameWikiForm.get('name')?.value).toBe('Wiki Name'); | ||
| }); | ||
|
|
||
| it('should have required validation on name field', () => { | ||
| const nameControl = component.renameWikiForm.get('name'); | ||
| nameControl?.setValue(''); | ||
|
|
||
| expect(nameControl?.hasError('required')).toBe(true); | ||
| }); | ||
|
|
||
| it('should validate name field with valid input', () => { | ||
| const nameControl = component.renameWikiForm.get('name'); | ||
| nameControl?.setValue('Test Wiki Name'); | ||
|
|
||
| expect(nameControl?.valid).toBe(true); | ||
| }); | ||
|
|
||
| it('should validate name field with whitespace only', () => { | ||
| const nameControl = component.renameWikiForm.get('name'); | ||
| nameControl?.setValue(' '); | ||
|
|
||
| expect(nameControl?.hasError('required')).toBe(true); | ||
| }); | ||
|
|
||
| it('should validate name field with max length', () => { | ||
| const nameControl = component.renameWikiForm.get('name'); | ||
| const longName = 'a'.repeat(256); | ||
| nameControl?.setValue(longName); | ||
|
|
||
| expect(nameControl?.hasError('maxlength')).toBe(true); | ||
| }); | ||
|
|
||
| it('should close dialog on cancel', () => { | ||
| const dialogRef = TestBed.inject(DynamicDialogRef); | ||
| const closeSpy = jest.spyOn(dialogRef, 'close'); | ||
|
|
||
| dialogRef.close(); | ||
|
|
||
| expect(closeSpy).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should not submit form when invalid', () => { | ||
| const dialogRef = TestBed.inject(DynamicDialogRef); | ||
| const toastService = TestBed.inject(ToastService); | ||
|
|
||
| const closeSpy = jest.spyOn(dialogRef, 'close'); | ||
| const showSuccessSpy = jest.spyOn(toastService, 'showSuccess'); | ||
|
|
||
| component.renameWikiForm.patchValue({ name: '' }); | ||
|
|
||
| component.submitForm(); | ||
|
|
||
| expect(showSuccessSpy).not.toHaveBeenCalled(); | ||
| expect(closeSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should handle form submission with empty name', () => { | ||
| const dialogRef = TestBed.inject(DynamicDialogRef); | ||
| const toastService = TestBed.inject(ToastService); | ||
|
|
||
| const closeSpy = jest.spyOn(dialogRef, 'close'); | ||
| const showSuccessSpy = jest.spyOn(toastService, 'showSuccess'); | ||
|
|
||
| component.renameWikiForm.patchValue({ name: ' ' }); | ||
|
|
||
| component.submitForm(); | ||
|
|
||
| expect(showSuccessSpy).not.toHaveBeenCalled(); | ||
| expect(closeSpy).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
56 changes: 56 additions & 0 deletions
56
src/app/shared/components/wiki/rename-wiki-dialog/rename-wiki-dialog.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { createDispatchMap, select } from '@ngxs/store'; | ||
|
|
||
| import { TranslatePipe } from '@ngx-translate/core'; | ||
|
|
||
| import { Button } from 'primeng/button'; | ||
| import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog'; | ||
|
|
||
| import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; | ||
| import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; | ||
|
|
||
| import { InputLimits } from '@osf/shared/constants/input-limits.const'; | ||
| import { CustomValidators } from '@osf/shared/helpers/custom-form-validators.helper'; | ||
| import { ToastService } from '@osf/shared/services/toast.service'; | ||
| import { RenameWiki, WikiSelectors } from '@osf/shared/stores/wiki'; | ||
|
|
||
| import { TextInputComponent } from '../../text-input/text-input.component'; | ||
|
|
||
| @Component({ | ||
| selector: 'osf-rename-wiki-dialog-component', | ||
| imports: [Button, ReactiveFormsModule, TranslatePipe, TextInputComponent], | ||
| templateUrl: './rename-wiki-dialog.component.html', | ||
| styleUrl: './rename-wiki-dialog.component.scss', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| }) | ||
| export class RenameWikiDialogComponent { | ||
| readonly dialogRef = inject(DynamicDialogRef); | ||
| readonly config = inject(DynamicDialogConfig); | ||
| private toastService = inject(ToastService); | ||
|
|
||
| actions = createDispatchMap({ renameWiki: RenameWiki }); | ||
| isSubmitting = select(WikiSelectors.getWikiSubmitting); | ||
| inputLimits = InputLimits; | ||
|
|
||
| renameWikiForm = new FormGroup({ | ||
| name: new FormControl(this.config.data.wikiName, { | ||
| nonNullable: true, | ||
| validators: [CustomValidators.requiredTrimmed(), Validators.maxLength(InputLimits.fullName.maxLength)], | ||
| }), | ||
| }); | ||
|
|
||
| submitForm(): void { | ||
| if (this.renameWikiForm.valid) { | ||
| this.actions.renameWiki(this.config.data.wikiId, this.renameWikiForm.value.name ?? '').subscribe({ | ||
| next: () => { | ||
| this.toastService.showSuccess('project.wiki.renameWikiSuccess'); | ||
| this.dialogRef.close(true); | ||
| }, | ||
| error: (err) => { | ||
| if (err?.status === 409) { | ||
| this.toastService.showError('project.wiki.renameWikiConflict'); | ||
| } | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,4 @@ | |
| min-width: 300px; | ||
| width: 300px; | ||
| } | ||
|
|
||
| .active { | ||
| background-color: var(--pr-blue-1); | ||
| color: var(--white); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.