• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geonetwork / geonetwork-ui / 14085439403

26 Mar 2025 02:11PM UTC coverage: 81.86% (-0.02%) from 81.881%
14085439403

push

github

web-flow
Merge pull request #1190 from geonetwork/bug-first-letter-deleted

[Editor]: Clear input on protocol switch but don't eat up letters

1833 of 2572 branches covered (71.27%)

Branch coverage included in aggregate %.

3 of 5 new or added lines in 2 files covered. (60.0%)

6064 of 7075 relevant lines covered (85.71%)

9.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/libs/ui/inputs/src/lib/url-input/url-input.component.ts
1
import {
2✔
2
  ChangeDetectionStrategy,
3
  ChangeDetectorRef,
4
  Component,
5
  EventEmitter,
6
  Input,
7
  OnChanges,
8
  Output,
9
  SimpleChanges,
10
} from '@angular/core'
11
import { CommonModule } from '@angular/common'
2✔
12
import { ButtonComponent } from '../button/button.component'
2✔
13
import {
2✔
14
  NgIconComponent,
15
  provideIcons,
16
  provideNgIconsConfig,
17
} from '@ng-icons/core'
18
import { iconoirArrowUp, iconoirLink } from '@ng-icons/iconoir'
2✔
19

20
@Component({
21
  selector: 'gn-ui-url-input',
22
  templateUrl: './url-input.component.html',
23
  styleUrls: ['./url-input.component.css'],
24
  standalone: true,
25
  imports: [CommonModule, ButtonComponent, NgIconComponent],
26
  providers: [
27
    provideIcons({ iconoirLink, iconoirArrowUp }),
28
    provideNgIconsConfig({
29
      size: '1.5em',
30
    }),
31
  ],
32
  changeDetection: ChangeDetectionStrategy.OnPush,
33
})
34
export class UrlInputComponent implements OnChanges {
2✔
35
  @Input() set value(v: string) {
36
    // we're making sure to only update the input if the URL representation of it has changed; otherwise we keep it identical
37
    // to avoid glitches when starting to write a URL and having some characters added/replaced automatically
38
    if (!v || !this.isValidUrl(v)) return
4✔
39
    if (
2✔
40
      this.isValidUrl(this.inputValue) &&
4✔
41
      new URL(v).toString() === new URL(this.inputValue).toString()
42
    )
43
      return
1✔
44
    this.inputValue = v
1✔
45
    this.cd.markForCheck()
1✔
46
  }
47
  @Input() extraClass = ''
23✔
48
  @Input() placeholder = 'https://'
23✔
49
  @Input() disabled: boolean
50
  @Input() showValidateButton = true
23✔
51
  @Input() resetUrlOnChange: number
52

53
  /**
54
   * This will emit null if the field is emptied
55
   */
56
  @Output() valueChange = new EventEmitter<string | null>()
23✔
57
  @Output() uploadClick = new EventEmitter<string>()
23✔
58

59
  inputValue = ''
23✔
60

61
  constructor(private cd: ChangeDetectorRef) {}
23!
62

63
  ngOnChanges(changes: SimpleChanges) {
64
    if (changes['resetUrlOnChange']) {
7!
NEW
65
      this.inputValue = ''
×
66
    }
67
  }
68

69
  handleInput(event: Event) {
70
    const value = (event.target as HTMLInputElement).value
11✔
71
    this.inputValue = value
11✔
72
    if (!value || !this.isValidUrl(value)) {
11✔
73
      this.valueChange.next(null)
6✔
74
      return
6✔
75
    }
76
    this.cd.markForCheck()
5✔
77
    this.valueChange.next(value)
5✔
78
  }
79

80
  handleUpload(element: HTMLInputElement) {
81
    const value = element.value
8✔
82
    if (!value || !this.isValidUrl(value)) return
8✔
83
    this.uploadClick.next(value)
7✔
84
  }
85

86
  isValidUrl(url: string): boolean {
87
    try {
24✔
88
      new URL(url)
24✔
89
      return true
19✔
90
    } catch (e) {
91
      return false
5✔
92
    }
93
  }
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc