1
1
import { screen , waitFor } from "@testing-library/react"
2
2
import userEvent from "@testing-library/user-event"
3
3
import React from "react"
4
- import { reach , StringSchema } from "yup"
5
4
import * as API from "../../api/api"
6
5
import { Language as FooterLanguage } from "../../components/FormFooter/FormFooter"
7
6
import { MockTemplate , MockWorkspace } from "../../testHelpers/entities"
8
7
import { renderWithAuth } from "../../testHelpers/renderHelpers"
8
+ import { Language as FormLanguage } from "../../util/formUtils"
9
9
import CreateWorkspacePage from "./CreateWorkspacePage"
10
- import { Language , validationSchema } from "./CreateWorkspacePageView"
10
+ import { Language } from "./CreateWorkspacePageView"
11
11
12
12
const renderCreateWorkspacePage = ( ) => {
13
13
return renderWithAuth ( < CreateWorkspacePage /> , {
@@ -23,8 +23,6 @@ const fillForm = async ({ name = "example" }: { name?: string }) => {
23
23
await userEvent . click ( submitButton )
24
24
}
25
25
26
- const nameSchema = reach ( validationSchema , "name" ) as StringSchema
27
-
28
26
describe ( "CreateWorkspacePage" , ( ) => {
29
27
it ( "renders" , async ( ) => {
30
28
renderCreateWorkspacePage ( )
@@ -35,7 +33,7 @@ describe("CreateWorkspacePage", () => {
35
33
it ( "shows validation error message" , async ( ) => {
36
34
renderCreateWorkspacePage ( )
37
35
await fillForm ( { name : "$$$" } )
38
- const errorMessage = await screen . findByText ( Language . nameMatches )
36
+ const errorMessage = await screen . findByText ( FormLanguage . nameInvalidChars ( Language . nameLabel ) )
39
37
expect ( errorMessage ) . toBeDefined ( )
40
38
} )
41
39
@@ -47,38 +45,4 @@ describe("CreateWorkspacePage", () => {
47
45
// Check if the request was made
48
46
await waitFor ( ( ) => expect ( API . createWorkspace ) . toBeCalledTimes ( 1 ) )
49
47
} )
50
-
51
- describe ( "validationSchema" , ( ) => {
52
- it ( "allows a 1-letter name" , ( ) => {
53
- const validate = ( ) => nameSchema . validateSync ( "t" )
54
- expect ( validate ) . not . toThrow ( )
55
- } )
56
-
57
- it ( "allows a 32-letter name" , ( ) => {
58
- const input = Array ( 32 ) . fill ( "a" ) . join ( "" )
59
- const validate = ( ) => nameSchema . validateSync ( input )
60
- expect ( validate ) . not . toThrow ( )
61
- } )
62
-
63
- it ( "allows 'test-3' to be used as name" , ( ) => {
64
- const validate = ( ) => nameSchema . validateSync ( "test-3" )
65
- expect ( validate ) . not . toThrow ( )
66
- } )
67
-
68
- it ( "allows '3-test' to be used as a name" , ( ) => {
69
- const validate = ( ) => nameSchema . validateSync ( "3-test" )
70
- expect ( validate ) . not . toThrow ( )
71
- } )
72
-
73
- it ( "disallows a 33-letter name" , ( ) => {
74
- const input = Array ( 33 ) . fill ( "a" ) . join ( "" )
75
- const validate = ( ) => nameSchema . validateSync ( input )
76
- expect ( validate ) . toThrow ( )
77
- } )
78
-
79
- it ( "disallows a space" , ( ) => {
80
- const validate = ( ) => nameSchema . validateSync ( "test 3" )
81
- expect ( validate ) . toThrow ( )
82
- } )
83
- } )
84
48
} )
0 commit comments