feat(settings): implement document removal and responsive table layout
Add a confirmation workflow for removing documents and refactor the documents table to support responsive layouts. The table now uses a fixed layout with defined column widths and handles overflow on mobile devices. The redundant filename column has been removed.
This commit is contained in:
@@ -30,12 +30,18 @@ function readyDoc(): DocumentListItem {
|
||||
};
|
||||
}
|
||||
|
||||
const toastr = { success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() };
|
||||
|
||||
const filterSelect = (el: HTMLElement): HTMLSelectElement | null => el.querySelector('.documents-filters select');
|
||||
|
||||
describe('SettingsPage — document filters', () => {
|
||||
let getDocuments: ReturnType<typeof vi.fn>;
|
||||
|
||||
beforeEach(async () => {
|
||||
toastr.success.mockClear();
|
||||
toastr.error.mockClear();
|
||||
toastr.warning.mockClear();
|
||||
toastr.info.mockClear();
|
||||
// Server-side filtering: `all` returns one ready doc; every other status matches none.
|
||||
getDocuments = vi.fn((params: { status?: string } = {}): Observable<DocumentListResponse> => {
|
||||
const items = params.status ? [] : [readyDoc()];
|
||||
@@ -59,7 +65,7 @@ describe('SettingsPage — document filters', () => {
|
||||
{ provide: AuthService, useValue: { getCurrentUserValue: () => ({ role: 'admin' }) } },
|
||||
{ provide: HttpService, useValue: { apiUrl: '/api/v1' } },
|
||||
{ provide: ThemeService, useValue: { isDarkMode: () => false, toggleDarkMode: () => {} } },
|
||||
{ provide: ToastrService, useValue: { success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() } },
|
||||
{ provide: ToastrService, useValue: toastr },
|
||||
],
|
||||
}).compileComponents();
|
||||
});
|
||||
@@ -108,7 +114,91 @@ describe('SettingsPage — document filters', () => {
|
||||
fixture.detectChanges();
|
||||
const rows = (fixture.nativeElement as HTMLElement).querySelectorAll('.documents-table tbody tr');
|
||||
expect(rows.length).toBe(1);
|
||||
expect(rows[0].textContent).toContain('guide.pdf');
|
||||
// نام فایل column was dropped (redundant with عنوان سند); the row shows the title.
|
||||
expect(rows[0].textContent).toContain('سند آزمون');
|
||||
expect(rows[0].textContent).not.toContain('guide.pdf');
|
||||
});
|
||||
|
||||
it('drops the redundant نام فایل column and renders exactly 6 columns', () => {
|
||||
const fixture = TestBed.createComponent(SettingsPage);
|
||||
fixture.detectChanges();
|
||||
const el = fixture.nativeElement as HTMLElement;
|
||||
|
||||
const headers = Array.from(el.querySelectorAll('.documents-table thead th')).map((t) =>
|
||||
t.textContent?.trim(),
|
||||
);
|
||||
expect(headers).toEqual([
|
||||
'عنوان سند',
|
||||
'وضعیت پردازش',
|
||||
'تعداد بخشها',
|
||||
'تاریخ آپلود',
|
||||
'فعالسازی',
|
||||
'عملیات',
|
||||
]);
|
||||
expect(headers).not.toContain('نام فایل');
|
||||
// A data row has exactly 6 cells matching the 6 columns.
|
||||
expect(el.querySelector('.documents-table tbody tr')?.children.length).toBe(6);
|
||||
});
|
||||
|
||||
it('confirms before removing: the bin button opens a modal, cancel keeps the doc, confirm shows the MVP notice', () => {
|
||||
const fixture = TestBed.createComponent(SettingsPage);
|
||||
fixture.detectChanges();
|
||||
const el = fixture.nativeElement as HTMLElement;
|
||||
|
||||
const openRemoveModal = () => {
|
||||
const row = el.querySelector('.documents-table tbody tr') as HTMLElement;
|
||||
const remove = Array.from(row.querySelectorAll('button')).find((b) =>
|
||||
(b.getAttribute('aria-label') ?? '').includes('حذف سند'),
|
||||
) as HTMLButtonElement;
|
||||
remove.click();
|
||||
fixture.detectChanges();
|
||||
};
|
||||
|
||||
openRemoveModal();
|
||||
const modal = el.querySelector('[role="alertdialog"]') as HTMLElement;
|
||||
expect(modal).toBeTruthy();
|
||||
expect(modal.textContent).toContain('سند آزمون');
|
||||
expect(modal.textContent).toContain('مطمئن هستید');
|
||||
expect(toastr.info).not.toHaveBeenCalled(); // nothing happens until confirmed
|
||||
|
||||
// Cancel closes the modal and keeps the document, with no notice.
|
||||
(modal.querySelector('.btn--outline') as HTMLButtonElement).click();
|
||||
fixture.detectChanges();
|
||||
expect(el.querySelector('[role="alertdialog"]')).toBeNull();
|
||||
expect(el.querySelectorAll('.documents-table tbody tr').length).toBe(1);
|
||||
expect(toastr.info).not.toHaveBeenCalled();
|
||||
|
||||
// Confirm closes the modal and surfaces the MVP notice (deletion is not yet implemented);
|
||||
// the row is left in place and no backend delete call is made.
|
||||
openRemoveModal();
|
||||
(el.querySelector('[role="alertdialog"] .btn--primary') as HTMLButtonElement).click();
|
||||
fixture.detectChanges();
|
||||
expect(toastr.info).toHaveBeenCalledTimes(1);
|
||||
expect(el.querySelector('[role="alertdialog"]')).toBeNull();
|
||||
expect(el.querySelectorAll('.documents-table tbody tr').length).toBe(1);
|
||||
});
|
||||
|
||||
it('renders OCR and FAQ admin-approval toggles in the app settings and toggles FAQ', () => {
|
||||
const fixture = TestBed.createComponent(SettingsPage);
|
||||
fixture.detectChanges();
|
||||
const component = fixture.componentInstance;
|
||||
component.selectTab('app');
|
||||
fixture.detectChanges();
|
||||
const el = fixture.nativeElement as HTMLElement;
|
||||
|
||||
const labels = Array.from(el.querySelectorAll('.setting-info label')).map((l) =>
|
||||
l.textContent?.trim(),
|
||||
);
|
||||
expect(labels).toContain('نیاز به تأیید ادمین برای اسناد OCR شده');
|
||||
expect(labels).toContain('نیاز به تأیید ادمین برای اسناد FAQ');
|
||||
|
||||
// Toggles in order: dark mode, OCR, FAQ. The FAQ toggle flips its own signal.
|
||||
const switches = el.querySelectorAll('.setting-control .toggle-switch');
|
||||
expect(switches.length).toBe(3);
|
||||
expect(component.faqAdminApproval()).toBe(false);
|
||||
(switches[2].querySelector('input') as HTMLInputElement).click();
|
||||
fixture.detectChanges();
|
||||
expect(component.faqAdminApproval()).toBe(true);
|
||||
});
|
||||
|
||||
it('hasActiveFilters reflects the active status/active-only filters', () => {
|
||||
|
||||
Reference in New Issue
Block a user