Skip to content

Commit

Permalink
fix add question
Browse files Browse the repository at this point in the history
  • Loading branch information
siltomato committed Jan 22, 2025
1 parent 4f60099 commit 4c2eeb0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class QuestionDialogComponent extends SubscriptionDisposable implements O
this.scriptureEnd.setValue(endVerseRef.toString());
}
this.updateSelection();
} else if (this.data.defaultVerse != null) {
} else if (this.data.defaultVerse != null && this.data.defaultVerse.bookNum > 0) {
const { startVerseRef, endVerseRef } = toStartAndEndVerseRefs(this.data.defaultVerse);
this.scriptureStart.setValue(startVerseRef.toString());
if (endVerseRef != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
Question,
QUESTIONS_COLLECTION
} from 'realtime-server/lib/esm/scriptureforge/models/question';
import { SFProject } from 'realtime-server/lib/esm/scriptureforge/models/sf-project';
import { SFProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project';
import { SFProjectRole } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-role';
import { createTestProject } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-test-data';
import { createTestProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-test-data';
import { TextInfo } from 'realtime-server/lib/esm/scriptureforge/models/text-info';
import { fromVerseRef } from 'realtime-server/lib/esm/scriptureforge/models/verse-ref-data';
import { of } from 'rxjs';
Expand All @@ -24,7 +24,7 @@ import { configureTestingModule, TestTranslocoModule } from 'xforge-common/test-
import { UICommonModule } from 'xforge-common/ui-common.module';
import { UserService } from 'xforge-common/user.service';
import { QuestionDoc } from '../../core/models/question-doc';
import { SFProjectDoc } from '../../core/models/sf-project-doc';
import { SFProjectProfileDoc } from '../../core/models/sf-project-profile-doc';
import { SF_TYPE_REGISTRY } from '../../core/models/sf-type-registry';
import { TextsByBookId } from '../../core/models/texts-by-book-id';
import { SFProjectService } from '../../core/sf-project.service';
Expand Down Expand Up @@ -167,7 +167,7 @@ class TestEnvironment {
readonly service: QuestionDialogService;
readonly mockedDialogRef = mock<MatDialogRef<QuestionDialogComponent, QuestionDialogResult | 'close'>>(MatDialogRef);
textsByBookId: TextsByBookId;
projectDoc: SFProjectDoc;
projectProfileDoc: SFProjectProfileDoc;
matthewText: TextInfo = {
bookNum: 40,
hasSource: false,
Expand All @@ -180,31 +180,31 @@ class TestEnvironment {
readonly PROJECT01: string = 'project01';
adminUser: UserInfo = { id: 'user01', role: SFProjectRole.ParatextAdministrator };

private testProject: SFProject = createTestProject({
private testProjectProfile: SFProjectProfile = createTestProjectProfile({
texts: [this.matthewText],
userRoles: {
[this.adminUser.id]: this.adminUser.role
},
paratextUsers: [
{ sfUserId: this.adminUser.id, username: `pt${this.adminUser.id}`, opaqueUserId: `opaque${this.adminUser.id}` }
]
}
});
private readonly realtimeService: TestRealtimeService = TestBed.inject<TestRealtimeService>(TestRealtimeService);

constructor() {
this.service = TestBed.inject(QuestionDialogService);
this.textsByBookId = { ['MAT']: this.matthewText };

this.realtimeService.addSnapshot<SFProject>(SFProjectDoc.COLLECTION, {
this.realtimeService.addSnapshot<SFProjectProfile>(SFProjectProfileDoc.COLLECTION, {
id: this.PROJECT01,
data: this.testProject
data: this.testProjectProfile
});
this.projectDoc = this.realtimeService.get<SFProjectDoc>(SFProjectDoc.COLLECTION, this.PROJECT01);
this.projectProfileDoc = this.realtimeService.get<SFProjectProfileDoc>(
SFProjectProfileDoc.COLLECTION,
this.PROJECT01
);

when(mockedDialogService.openMatDialog(anything(), anything())).thenReturn(instance(this.mockedDialogRef));
when(mockedUserService.currentUserId).thenReturn(this.adminUser.id);
when(mockedProjectService.get(anything())).thenCall(id =>
this.realtimeService.subscribe(SFProjectDoc.COLLECTION, id)
when(mockedProjectService.getProfile(anything())).thenCall(id =>
this.realtimeService.subscribe(SFProjectProfileDoc.COLLECTION, id)
);
}

Expand Down Expand Up @@ -233,14 +233,22 @@ class TestEnvironment {
}

getQuestionDialogData(questionDoc?: QuestionDoc): QuestionDialogData {
return { questionDoc, projectDoc: this.projectDoc, textsByBookId: this.textsByBookId, projectId: this.PROJECT01 };
return {
questionDoc,
projectDoc: this.projectProfileDoc,
textsByBookId: this.textsByBookId,
projectId: this.PROJECT01
};
}

updateUserRole(role: string): void {
const projectDoc = this.realtimeService.get<SFProjectDoc>(SFProjectDoc.COLLECTION, this.PROJECT01);
const userRole = projectDoc.data!.userRoles;
const projectProfileDoc = this.realtimeService.get<SFProjectProfileDoc>(
SFProjectProfileDoc.COLLECTION,
this.PROJECT01
);
const userRole = projectProfileDoc.data!.userRoles;
userRole[this.adminUser.id] = role;
projectDoc.submitJson0Op(op => {
projectProfileDoc.submitJson0Op(op => {
op.set(p => p.userRoles, userRole);
}, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class QuestionDialogService {

private async canCreateAndEditQuestions(projectId: string): Promise<boolean> {
const userId = this.userService.currentUserId;
const project = (await this.projectService.get(projectId)).data;
const project = (await this.projectService.getProfile(projectId)).data;
return (
project != null &&
SF_PROJECT_RIGHTS.hasRight(project, userId, SFProjectDomain.Questions, Operation.Create) &&
Expand Down

0 comments on commit 4c2eeb0

Please sign in to comment.