@if (content()) {
diff --git a/src/app/shared/components/wiki/view-section/view-section.component.spec.ts b/src/app/shared/components/wiki/view-section/view-section.component.spec.ts
index 7b8efd281..a7988daea 100644
--- a/src/app/shared/components/wiki/view-section/view-section.component.spec.ts
+++ b/src/app/shared/components/wiki/view-section/view-section.component.spec.ts
@@ -1,7 +1,6 @@
import { MockComponent } from 'ng-mocks';
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { provideNoopAnimations } from '@angular/platform-browser/animations';
import { WikiVersion } from '@shared/models/wiki/wiki.model';
@@ -10,6 +9,7 @@ import { MarkdownComponent } from '../../markdown/markdown.component';
import { ViewSectionComponent } from './view-section.component';
import { TranslateServiceMock } from '@testing/mocks/translate.service.mock';
+import { OSFTestingModule } from '@testing/osf.testing.module';
describe('ViewSectionComponent', () => {
let component: ViewSectionComponent;
@@ -33,8 +33,8 @@ describe('ViewSectionComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
- imports: [ViewSectionComponent, MockComponent(MarkdownComponent)],
- providers: [TranslateServiceMock, provideNoopAnimations()],
+ imports: [ViewSectionComponent, OSFTestingModule, MockComponent(MarkdownComponent)],
+ providers: [TranslateServiceMock],
}).compileComponents();
fixture = TestBed.createComponent(ViewSectionComponent);
@@ -105,10 +105,7 @@ describe('ViewSectionComponent', () => {
const mappedVersions = component.mappedVersions();
expect(mappedVersions).toHaveLength(1);
- expect(mappedVersions[0]).toEqual({
- label: 'Preview',
- value: null,
- });
+ expect(mappedVersions[0].value).toBeNull();
});
it('should handle single version', () => {
@@ -118,28 +115,8 @@ describe('ViewSectionComponent', () => {
const mappedVersions = component.mappedVersions();
expect(mappedVersions).toHaveLength(2);
- expect(mappedVersions[0].label).toBe('Preview');
- expect(mappedVersions[1].label).toContain('(Current)');
- });
-
- it('should render loading skeleton when isLoading is true', () => {
- fixture.componentRef.setInput('isLoading', true);
- fixture.detectChanges();
-
- const compiled = fixture.nativeElement;
- const skeletons = compiled.querySelectorAll('p-skeleton');
-
- expect(skeletons.length).toBeGreaterThan(0);
- });
-
- it('should render view panel when not loading', () => {
- fixture.componentRef.setInput('isLoading', false);
- fixture.detectChanges();
-
- const compiled = fixture.nativeElement;
- const panels = compiled.querySelectorAll('p-panel');
-
- expect(panels.length).toBeGreaterThan(0);
+ expect(mappedVersions[0].value).toBeNull();
+ expect(mappedVersions[1].value).toBe('version-1');
});
it('should initialize with null selected version when not viewOnly', () => {
@@ -166,25 +143,4 @@ describe('ViewSectionComponent', () => {
expect(component.selectedVersion()).toBe(null);
expect(emitSpy).toHaveBeenCalledWith(undefined);
});
-
- it('should render markdown component when content exists', () => {
- fixture.componentRef.setInput('previewContent', 'Some content');
- fixture.detectChanges();
-
- const compiled = fixture.nativeElement;
- const markdownComponent = compiled.querySelector('osf-markdown');
-
- expect(markdownComponent).toBeTruthy();
- });
-
- it('should render no content message when content is empty', () => {
- fixture.componentRef.setInput('previewContent', '');
- fixture.componentRef.setInput('versionContent', '');
- fixture.detectChanges();
-
- const compiled = fixture.nativeElement;
- const noContentMessage = compiled.querySelector('p.font-italic');
-
- expect(noContentMessage).toBeTruthy();
- });
});
diff --git a/src/app/shared/components/wiki/view-section/view-section.component.ts b/src/app/shared/components/wiki/view-section/view-section.component.ts
index 1be0f88e9..609d4f7dd 100644
--- a/src/app/shared/components/wiki/view-section/view-section.component.ts
+++ b/src/app/shared/components/wiki/view-section/view-section.component.ts
@@ -1,10 +1,10 @@
-import { TranslatePipe } from '@ngx-translate/core';
+import { TranslatePipe, TranslateService } from '@ngx-translate/core';
import { Panel } from 'primeng/panel';
import { Select } from 'primeng/select';
import { Skeleton } from 'primeng/skeleton';
-import { ChangeDetectionStrategy, Component, computed, effect, input, output, signal } from '@angular/core';
+import { ChangeDetectionStrategy, Component, computed, effect, inject, input, output, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { WikiVersion } from '@osf/shared/models/wiki/wiki.model';
@@ -26,25 +26,22 @@ export class ViewSectionComponent {
versionContent = input.required();
selectVersion = output();
- previewOption = {
- label: 'Preview',
- value: null,
- };
+ translateService = inject(TranslateService);
selectedVersion = signal(null);
content = computed(() => (this.selectedVersion() === null ? this.previewContent() : this.versionContent()));
- mappedVersions = computed(() => [
- this.previewOption,
- ...this.versions().map((version, index) => {
- const labelPrefix = index === 0 ? '(Current)' : `(${this.versions().length - index})`;
+ private readonly previewLabel = this.translateService.instant('project.wiki.version.preview');
+ private readonly currentLabel = this.translateService.instant('project.wiki.version.current');
+ private readonly unknownAuthorLabel = this.translateService.instant('project.wiki.version.unknownAuthor');
- return {
- label: `${labelPrefix} ${version.createdBy}: (${new Date(version.createdAt).toLocaleString()})`,
- value: version.id,
- };
- }),
+ mappedVersions = computed(() => [
+ { label: this.previewLabel, value: null },
+ ...this.versions().map((version, index) => ({
+ label: this.formatVersionLabel(version, index),
+ value: version.id,
+ })),
]);
constructor() {
@@ -59,10 +56,17 @@ export class ViewSectionComponent {
});
}
- onVersionChange(versionId: string): void {
+ onVersionChange(versionId: string | null): void {
this.selectedVersion.set(versionId);
+
if (versionId) {
this.selectVersion.emit(versionId);
}
}
+
+ private formatVersionLabel(version: WikiVersion, index: number): string {
+ const prefix = index === 0 ? `(${this.currentLabel})` : `(${this.versions().length - index})`;
+ const creator = version.createdBy || this.unknownAuthorLabel;
+ return `${prefix} ${creator}: (${new Date(version.createdAt).toLocaleString()})`;
+ }
}
diff --git a/src/app/shared/components/wiki/wiki-list/wiki-list.component.html b/src/app/shared/components/wiki/wiki-list/wiki-list.component.html
index 41f09c1c1..d35962419 100644
--- a/src/app/shared/components/wiki/wiki-list/wiki-list.component.html
+++ b/src/app/shared/components/wiki/wiki-list/wiki-list.component.html
@@ -68,14 +68,15 @@ {{ item.label | translate }}
{{ item.label }}
-
-
+ @if (canEditName(item)) {
+
+ }