Add status change Word form and align form fields
This commit is contained in:
1 parent
298c8ccf4b
commit
53fd0db7b1
4 files changed
+110
-9
No files matched your search
@@ -19,6 +19,52 @@ namespace Jiaowu.Api.Tests;
|
||||
|
||||
public sealed class ApprovalsControllerTests
|
||||
{
|
||||
[Fact]
|
||||
public void Approval_form_centers_labels_and_short_values_but_left_aligns_comments()
|
||||
{
|
||||
var bytes = Jiaowu.Api.Infrastructure.Approvals.ApprovalFormWordGenerator.Generate("示例大学", "学籍异动申请表",
|
||||
[("姓名", "张同学"), ("学号", "20260001"), ("申请理由", "申请休学"), ("辅导员通过", "同意申请")], DateTimeOffset.UtcNow);
|
||||
using var doc = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(new MemoryStream(bytes), false);
|
||||
var cells = doc.MainDocumentPart!.Document!.Body!.Descendants<DocumentFormat.OpenXml.Wordprocessing.TableCell>().ToList();
|
||||
DocumentFormat.OpenXml.Wordprocessing.JustificationValues? Alignment(int index) => cells[index].GetFirstChild<DocumentFormat.OpenXml.Wordprocessing.Paragraph>()!.ParagraphProperties!.Justification!.Val!.Value;
|
||||
Assert.Equal(DocumentFormat.OpenXml.Wordprocessing.JustificationValues.Center, Alignment(0));
|
||||
Assert.Equal(DocumentFormat.OpenXml.Wordprocessing.JustificationValues.Center, Alignment(1));
|
||||
Assert.Equal(DocumentFormat.OpenXml.Wordprocessing.JustificationValues.Center, Alignment(2));
|
||||
Assert.Equal(DocumentFormat.OpenXml.Wordprocessing.JustificationValues.Center, Alignment(4));
|
||||
Assert.Equal(DocumentFormat.OpenXml.Wordprocessing.JustificationValues.Left, Alignment(5));
|
||||
Assert.Equal(DocumentFormat.OpenXml.Wordprocessing.JustificationValues.Center, Alignment(6));
|
||||
Assert.Equal(DocumentFormat.OpenXml.Wordprocessing.JustificationValues.Left, Alignment(7));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Status_change_form_shows_saved_stages_and_denies_other_students()
|
||||
{
|
||||
await using var fixture = await ApprovalFixture.CreateAsync();
|
||||
var change = new StudentStatusChange { StudentId = fixture.Student.Id, Type = StudentStatusChangeType.Suspension,
|
||||
OriginalStatus = StudentStatus.Active, TargetStatus = StudentStatus.Suspended, Reason = "申请休学",
|
||||
State = StudentStatusChangeState.CollegeApproved };
|
||||
var first = new StudentStatusChangeEvent { StudentStatusChangeId = change.Id, FromState = StudentStatusChangeState.Submitted,
|
||||
ToState = StudentStatusChangeState.CounselorApproved, ActorUserId = fixture.Student.UserId!.Value, OccurredAt = DateTime.UtcNow.AddMinutes(-2), Comment = "辅导员意见" };
|
||||
var second = new StudentStatusChangeEvent { StudentStatusChangeId = change.Id, FromState = StudentStatusChangeState.CounselorApproved,
|
||||
ToState = StudentStatusChangeState.CollegeApproved, ActorUserId = fixture.Student.UserId.Value, OccurredAt = DateTime.UtcNow.AddMinutes(-1), Comment = "学院意见" };
|
||||
fixture.Db.AddRange(change, first, second);
|
||||
await fixture.Db.SaveChangesAsync();
|
||||
var student = new ApprovalsController(fixture.Db, new StudentDataScope(fixture.Student.UserId.Value));
|
||||
var file = Assert.IsType<FileContentResult>(await student.DownloadApprovalForm("StudentStatusChange", change.Id, CancellationToken.None));
|
||||
using var word = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(new MemoryStream(file.FileContents), false);
|
||||
var text = word.MainDocumentPart!.Document!.Body!.InnerText;
|
||||
Assert.Contains("辅导员意见", text);
|
||||
Assert.Contains("学院意见", text);
|
||||
Assert.Contains("测试学生", text);
|
||||
var outsider = new ApprovalsController(fixture.Db, new StudentDataScope(Guid.NewGuid()));
|
||||
Assert.IsType<NotFoundResult>(await outsider.DownloadApprovalForm("StudentStatusChange", change.Id, CancellationToken.None));
|
||||
fixture.Db.StudentStatusChangeEvents.Remove(first);
|
||||
await fixture.Db.SaveChangesAsync();
|
||||
var legacyFile = Assert.IsType<FileContentResult>(await student.DownloadApprovalForm("StudentStatusChange", change.Id, CancellationToken.None));
|
||||
using var legacy = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(new MemoryStream(legacyFile.FileContents), false);
|
||||
Assert.Contains("历史审核记录不完整", legacy.MainDocumentPart!.Document!.Body!.InnerText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Student_leave_word_form_includes_review_and_respects_access_scope()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user