|
7 | 7 | translateDisplayNameForK8s, |
8 | 8 | translateDisplayNameForK8sAndReport, |
9 | 9 | } from '~/concepts/k8s/utils'; |
| 10 | +import { K8_NOTEBOOK_RESOURCE_NAME_VALIDATOR } from '~/pages/projects/screens/spawner/const'; |
10 | 11 |
|
11 | 12 | describe('getDisplayNameFromK8sResource', () => { |
12 | 13 | it('gets the display name when present', () => { |
@@ -49,6 +50,10 @@ describe('translateDisplayNameForK8s', () => { |
49 | 50 | expect(translateDisplayNameForK8s('-1234', { safeK8sPrefix: 'wb-' })).toBe('wb-1234'); |
50 | 51 | expect(translateDisplayNameForK8s('-1-', { safeK8sPrefix: 'wb-' })).toBe('wb-1'); |
51 | 52 | expect(translateDisplayNameForK8s('1-', { safeK8sPrefix: 'wb-' })).toBe('wb-1'); |
| 53 | + expect(translateDisplayNameForK8s('213-workbench-1-tls', { safeK8sPrefix: 'wb-' })).toBe( |
| 54 | + 'wb-213-workbench-1-tls', |
| 55 | + ); |
| 56 | + expect(translateDisplayNameForK8s('$-12hello', { safeK8sPrefix: 'wb-' })).toBe('wb-12hello'); |
52 | 57 | expect(translateDisplayNameForK8s('-validcharacters')).toBe(`validcharacters`); |
53 | 58 | }); |
54 | 59 | }); |
@@ -160,3 +165,37 @@ describe('isValidK8sName', () => { |
160 | 165 | expect(isValidK8sName('ymbols--capitals-and-spaces-these-are-invalid')).toBe(true); |
161 | 166 | }); |
162 | 167 | }); |
| 168 | + |
| 169 | +describe('isValidK8sName for Notebook resource names', () => { |
| 170 | + it('identifies invalid names', () => { |
| 171 | + expect(isValidK8sName('', K8_NOTEBOOK_RESOURCE_NAME_VALIDATOR)).toBe(false); |
| 172 | + expect(isValidK8sName('Test Project 1', K8_NOTEBOOK_RESOURCE_NAME_VALIDATOR)).toBe(false); |
| 173 | + expect(isValidK8sName("John Doe's Cool Project!", K8_NOTEBOOK_RESOURCE_NAME_VALIDATOR)).toBe( |
| 174 | + false, |
| 175 | + ); |
| 176 | + expect( |
| 177 | + isValidK8sName( |
| 178 | + '$ymbols & Capitals and Spaces! (These are invalid!)', |
| 179 | + K8_NOTEBOOK_RESOURCE_NAME_VALIDATOR, |
| 180 | + ), |
| 181 | + ).toBe(false); |
| 182 | + expect(isValidK8sName('--213-workbench-1-tls', K8_NOTEBOOK_RESOURCE_NAME_VALIDATOR)).toBe( |
| 183 | + false, |
| 184 | + ); |
| 185 | + expect(isValidK8sName('1234', K8_NOTEBOOK_RESOURCE_NAME_VALIDATOR)).toBe(false); |
| 186 | + expect(isValidK8sName('213-workbench-1-tls', K8_NOTEBOOK_RESOURCE_NAME_VALIDATOR)).toBe(false); |
| 187 | + }); |
| 188 | + |
| 189 | + it('identifies valid names', () => { |
| 190 | + expect(isValidK8sName('test-project-1', K8_NOTEBOOK_RESOURCE_NAME_VALIDATOR)).toBe(true); |
| 191 | + expect(isValidK8sName('john-does-cool-project', K8_NOTEBOOK_RESOURCE_NAME_VALIDATOR)).toBe( |
| 192 | + true, |
| 193 | + ); |
| 194 | + expect( |
| 195 | + isValidK8sName( |
| 196 | + 'ymbols--capitals-and-spaces-these-are-invalid', |
| 197 | + K8_NOTEBOOK_RESOURCE_NAME_VALIDATOR, |
| 198 | + ), |
| 199 | + ).toBe(true); |
| 200 | + }); |
| 201 | +}); |
0 commit comments