Skip to content

Commit f70d422

Browse files
authored
Merge pull request #2213 from MetRonnie/cycle-validation
Fix mutation form cycle point validation
1 parent 684bbe9 commit f70d422

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed

src/components/graphqlFormGenerator/components/vuetify.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
33
*
44
* This program is free software: you can redistribute it and/or modify
@@ -34,8 +34,8 @@ const NumberFieldProps = {
3434
}
3535
}
3636

37-
const RE = {
38-
cyclePoint: '\\d+(T\\d+(Z|[+-]\\d+)?)?'
37+
export const RE = {
38+
cyclePoint: String.raw`\d+[\dW-]*(T\d+[\d:]*(Z|[+-]\d+[\d:]*)?)?`,
3939
}
4040

4141
export const RULES = {
@@ -110,7 +110,7 @@ export default {
110110
rules: [
111111
RULES.noSpaces,
112112
// character whitelist
113-
x => Boolean(!x || x.match(`^${RE.cyclePoint}$`)) || 'Invalid Cycle Point'
113+
x => Boolean(!x || x.match(String.raw`^${RE.cyclePoint}$`)) || 'Invalid Cycle Point'
114114
]
115115
},
116116
CyclePointGlob: {
@@ -127,7 +127,7 @@ export default {
127127
BroadcastCyclePoint: {
128128
is: VTextField,
129129
rules: [
130-
x => Boolean(!x || x.match(`^(${RE.cyclePoint}|\\*)$`)) || 'Must be "*" or a valid cycle point'
130+
x => Boolean(!x || x.match(String.raw`^(${RE.cyclePoint}|\*)$`)) || 'Must be "*" or a valid cycle point'
131131
]
132132
},
133133
// TaskStatus
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
import { RE } from '@/components/graphqlFormGenerator/components/vuetify'
18+
19+
describe('RE', () => {
20+
describe('cyclePoint', () => {
21+
const regex = new RegExp(String.raw`^${RE.cyclePoint}$`)
22+
it.for([
23+
// Integer
24+
'1',
25+
'105',
26+
'999999999',
27+
// Calendar date
28+
'2025',
29+
'20250619',
30+
'20250619T15',
31+
'20250619T153045',
32+
'20250619T153045Z',
33+
'20250619T153045+01',
34+
'20250619T153045-0500',
35+
'2025-06-19',
36+
'2025-06-19T15',
37+
'2025-06-19T15Z',
38+
'2025-06-19T15:30:45',
39+
'2025-06-19T15:30:45Z',
40+
'2025-06-19T15:30:45+01',
41+
'2025-06-19T15:30:45-05:00',
42+
// Week date
43+
'2015W534',
44+
'2015W534T0631',
45+
'2015-W53-4',
46+
'2015-W53-4T06:31',
47+
'2015W534T0631+02',
48+
'2015-W53-4T06:31+02',
49+
// Ordinal date
50+
'2025170',
51+
'2025-170',
52+
'2025170T15:30',
53+
'2025-170T15:30:45+00:00',
54+
])('matches %s', (str) => {
55+
expect(regex.test(str)).toBe(true)
56+
})
57+
})
58+
})

0 commit comments

Comments
 (0)