mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-19 11:02:45 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80c3b6490c | ||
|
|
14252054a1 |
No files matched your search
@@ -0,0 +1,90 @@
|
||||
import { provideHttpClient } from '@angular/common/http'
|
||||
import { provideHttpClientTesting } from '@angular/common/http/testing'
|
||||
import { Component } from '@angular/core'
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||
import { FormControl, ReactiveFormsModule } from '@angular/forms'
|
||||
import { NumberComponent } from './number/number.component'
|
||||
import { TextComponent } from './text/text.component'
|
||||
import { TextAreaComponent } from './textarea/textarea.component'
|
||||
import { UrlComponent } from './url/url.component'
|
||||
|
||||
@Component({
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
TextComponent,
|
||||
NumberComponent,
|
||||
TextAreaComponent,
|
||||
UrlComponent,
|
||||
],
|
||||
template: `
|
||||
<pngx-input-text [formControl]="control" />
|
||||
<pngx-input-number [formControl]="control" [showAdd]="false" />
|
||||
<pngx-input-textarea [formControl]="control" />
|
||||
<pngx-input-url [formControl]="control" />
|
||||
`,
|
||||
})
|
||||
class InputEventsHostComponent {
|
||||
control = new FormControl<string | number | null>(null)
|
||||
}
|
||||
|
||||
describe.each([
|
||||
['text', 'pngx-input-text input', 'Edited text', 'Edited text'],
|
||||
['number', 'pngx-input-number input', '42', 42],
|
||||
['textarea', 'pngx-input-textarea textarea', 'Edited\ntext', 'Edited\ntext'],
|
||||
['url', 'pngx-input-url input', 'https://example.com', 'https://example.com'],
|
||||
])(
|
||||
'%s input events',
|
||||
(_type, selector: string, text: string, value: string | number) => {
|
||||
let fixture: ComponentFixture<InputEventsHostComponent>
|
||||
let control: FormControl<string | number | null>
|
||||
let input: HTMLInputElement | HTMLTextAreaElement
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [InputEventsHostComponent],
|
||||
providers: [provideHttpClient(), provideHttpClientTesting()],
|
||||
})
|
||||
fixture = TestBed.createComponent(InputEventsHostComponent)
|
||||
control = fixture.componentInstance.control
|
||||
})
|
||||
|
||||
async function render() {
|
||||
fixture.detectChanges()
|
||||
await fixture.whenStable()
|
||||
input = fixture.nativeElement.querySelector(selector)
|
||||
}
|
||||
|
||||
it('updates the form while typing and marks it touched only on blur', async () => {
|
||||
await render()
|
||||
const changed = jest.fn()
|
||||
control.valueChanges.subscribe(changed)
|
||||
input.value = text
|
||||
input.dispatchEvent(new Event('input'))
|
||||
expect(control.value).toBe(value)
|
||||
expect(control.dirty).toBe(true)
|
||||
expect(control.touched).toBe(false)
|
||||
|
||||
input.dispatchEvent(new Event('change'))
|
||||
input.dispatchEvent(new Event('blur'))
|
||||
expect(control.touched).toBe(true)
|
||||
expect(changed).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('honors an explicit updateOn blur strategy', async () => {
|
||||
control = new FormControl<string | number | null>(null, {
|
||||
updateOn: 'blur',
|
||||
})
|
||||
fixture.componentInstance.control = control
|
||||
await render()
|
||||
input.value = text
|
||||
input.dispatchEvent(new Event('input'))
|
||||
expect(control.value).toBeNull()
|
||||
expect(control.pristine).toBe(true)
|
||||
|
||||
input.dispatchEvent(new Event('blur'))
|
||||
expect(control.value).toBe(value)
|
||||
expect(control.dirty).toBe(true)
|
||||
expect(control.touched).toBe(true)
|
||||
})
|
||||
}
|
||||
)
|
||||
@@ -12,7 +12,7 @@
|
||||
</div>
|
||||
<div class="position-relative" [class.col-md-9]="horizontal">
|
||||
<div class="input-group" [class.is-invalid]="error">
|
||||
<input #inputField type="number" class="form-control" [step]="step" [id]="inputId" [(ngModel)]="value" [ngModelOptions]="{standalone: true}" (change)="onChange(value)" [class.is-invalid]="error" [disabled]="disabled">
|
||||
<input #inputField type="number" class="form-control" [step]="step" [id]="inputId" [(ngModel)]="value" [ngModelOptions]="{standalone: true}" (ngModelChange)="onChange($event)" (blur)="onTouched()" [class.is-invalid]="error" [disabled]="disabled">
|
||||
@if (showAdd) {
|
||||
<button class="btn btn-outline-secondary" type="button" id="button-addon1" (click)="nextAsn()" [disabled]="disabled">+1</button>
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
}
|
||||
</div>
|
||||
<div class="position-relative" [class.col-md-9]="horizontal">
|
||||
<input #inputField type="text" class="form-control" [class.is-invalid]="error" [id]="inputId" [(ngModel)]="value" [ngModelOptions]="{standalone: true}" (change)="onChange(value)" [disabled]="disabled" [autocomplete]="autocomplete" [placeholder]="placeholder">
|
||||
<input #inputField type="text" class="form-control" [class.is-invalid]="error" [id]="inputId" [(ngModel)]="value" [ngModelOptions]="{standalone: true}" (ngModelChange)="onChange($event)" (blur)="onTouched()" [disabled]="disabled" [autocomplete]="autocomplete" [placeholder]="placeholder">
|
||||
@if (hint) {
|
||||
<small class="form-text text-muted" [innerHTML]="hint"></small>
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
[class.font-monospace]="monospace"
|
||||
[(ngModel)]="value"
|
||||
[ngModelOptions]="{standalone: true}"
|
||||
(change)="onChange(value)"
|
||||
(ngModelChange)="onChange($event)"
|
||||
(blur)="onTouched()"
|
||||
[disabled]="disabled"
|
||||
[placeholder]="placeholder"
|
||||
rows="4">
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</div>
|
||||
<div [class.col-md-9]="horizontal">
|
||||
<div class="input-group" [class.is-invalid]="error">
|
||||
<input #inputField type="url" class="form-control" [class.is-invalid]="error" placeholder="https://" [id]="inputId" [(ngModel)]="value" [ngModelOptions]="{standalone: true}" (change)="onChange(value)" [disabled]="disabled">
|
||||
<input #inputField type="url" class="form-control" [class.is-invalid]="error" placeholder="https://" [id]="inputId" [(ngModel)]="value" [ngModelOptions]="{standalone: true}" (ngModelChange)="onChange($event)" (blur)="onTouched()" [disabled]="disabled">
|
||||
<a class="btn btn-outline-secondary rounded-end" title="Open link" i18n-title [href]="value" target="_blank">
|
||||
<pngx-bs-icon width="1.2em" height="1.2em" name="box-arrow-up-right"></pngx-bs-icon>
|
||||
</a>
|
||||
|
||||
@@ -390,14 +390,12 @@ describe('DocumentDetailComponent', () => {
|
||||
expect(component.documentForm.get('title').value).toEqual('Foo Bar')
|
||||
})
|
||||
|
||||
it('should update title before doc change if was not updated via debounce', () => {
|
||||
it('should update the title form value without waiting for debounce or blur', () => {
|
||||
jest.useFakeTimers()
|
||||
initNormally()
|
||||
component.titleInput.value = 'Foo Bar'
|
||||
component.titleInput.inputField.nativeElement.dispatchEvent(
|
||||
new Event('change')
|
||||
)
|
||||
jest.advanceTimersByTime(1000)
|
||||
const input = component.titleInput.inputField.nativeElement
|
||||
input.value = 'Foo Bar'
|
||||
input.dispatchEvent(new Event('input'))
|
||||
expect(component.documentForm.get('title').value).toEqual('Foo Bar')
|
||||
})
|
||||
|
||||
|
||||
+23
-7
@@ -5318,6 +5318,8 @@ class CustomFieldViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet[Custom
|
||||
class SystemStatusView(PassUserMixin):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
TASK_SUMMARY_DAYS = 30
|
||||
# Seconds to wait on the broker before reporting it as unreachable
|
||||
BROKER_SOCKET_TIMEOUT = 5
|
||||
|
||||
def get(self, request, format=None):
|
||||
if not has_system_status_permission(request.user):
|
||||
@@ -5363,7 +5365,11 @@ class SystemStatusView(PassUserMixin):
|
||||
if redis_url_parsed.hostname is not None:
|
||||
redis_constructed_url += f":{redis_url_parsed.port}"
|
||||
redis_error = None
|
||||
with Redis.from_url(url=redis_url) as client:
|
||||
with Redis.from_url(
|
||||
url=redis_url,
|
||||
socket_timeout=self.BROKER_SOCKET_TIMEOUT,
|
||||
socket_connect_timeout=self.BROKER_SOCKET_TIMEOUT,
|
||||
) as client:
|
||||
try:
|
||||
client.ping()
|
||||
redis_status = "OK"
|
||||
@@ -5378,12 +5384,22 @@ class SystemStatusView(PassUserMixin):
|
||||
celery_url = None
|
||||
try:
|
||||
celery_ping = None
|
||||
for ping_attempt in range(3):
|
||||
celery_ping = celery_app.control.inspect().ping()
|
||||
if celery_ping:
|
||||
break
|
||||
if ping_attempt < 2:
|
||||
sleep(0.25)
|
||||
# Use a dedicated connection with socket timeouts. Without them a
|
||||
# stalled broker blocks this request (and its DB connection) forever
|
||||
with celery_app.connection_for_read(
|
||||
transport_options={
|
||||
"socket_timeout": self.BROKER_SOCKET_TIMEOUT,
|
||||
"socket_connect_timeout": self.BROKER_SOCKET_TIMEOUT,
|
||||
},
|
||||
) as celery_connection:
|
||||
for ping_attempt in range(3):
|
||||
celery_ping = celery_app.control.inspect(
|
||||
connection=celery_connection,
|
||||
).ping()
|
||||
if celery_ping:
|
||||
break
|
||||
if ping_attempt < 2:
|
||||
sleep(0.25)
|
||||
|
||||
if not celery_ping:
|
||||
celery_active = "WARNING"
|
||||
|
||||
Reference in new issue
Block a user