@@ -3,13 +3,14 @@ package create_topic_page
33import (
44 "errors"
55 "fmt"
6- tea "github.com/charmbracelet/bubbletea"
7- "github.com/stretchr/testify/assert"
86 "ktea/kadmin"
97 "ktea/kontext"
108 "ktea/tests"
119 "ktea/ui/pages/nav"
1210 "testing"
11+
12+ tea "github.com/charmbracelet/bubbletea"
13+ "github.com/stretchr/testify/assert"
1314)
1415
1516func batchUpdate (m * Model , cmd tea.Cmd ) {
@@ -170,6 +171,66 @@ func TestCreateTopic(t *testing.T) {
170171 }
171172 m := New (& mockCreator )
172173
174+ // topic name
175+ tests .UpdateKeys (m , "topicA" )
176+ cmd := m .Update (tests .Key (tea .KeyEnter ))
177+ m .Update (cmd ())
178+ // partition count
179+ tests .UpdateKeys (m , "2" )
180+ cmd = m .Update (tests .Key (tea .KeyEnter ))
181+ m .Update (cmd ())
182+ // replication factor
183+ tests .UpdateKeys (m , "3" )
184+ cmd = m .Update (tests .Key (tea .KeyEnter ))
185+ m .Update (cmd ())
186+ // cleanup policy
187+ m .Update (tests .Key (tea .KeyDown ))
188+ cmd = m .Update (tests .Key (tea .KeyEnter ))
189+ m .Update (cmd ())
190+ // config
191+ tests .UpdateKeys (m , "delete.retention.ms=1029394" )
192+ cmd = m .Update (tests .Key (tea .KeyEnter ))
193+ // next field
194+ cmd = m .Update (cmd ())
195+ // next group
196+ m .Update (cmd ())
197+
198+ // actual submit
199+ msgs := tests .Submit (m )
200+
201+ var capturedDetails CapturedTopicCreationDetails
202+ for _ , msg := range msgs {
203+ switch m := msg .(type ) {
204+ case CapturedTopicCreationDetails :
205+ capturedDetails = m
206+ }
207+ }
208+
209+ assert .NotNil (t , capturedDetails )
210+ assert .Equal (t , CapturedTopicCreationDetails {
211+ TopicCreationDetails : kadmin.TopicCreationDetails {
212+ "topicA" ,
213+ 2 ,
214+ map [string ]string {
215+ "cleanup.policy" : "compact" ,
216+ "delete.retention.ms" : "1029394" ,
217+ },
218+ int16 (3 ),
219+ },
220+ }, capturedDetails )
221+ })
222+
223+ t .Run ("create delete,compact topic" , func (t * testing.T ) {
224+ mockCreator := MockTopicCreator {
225+ CreateTopicFunc : func (details kadmin.TopicCreationDetails ) tea.Msg {
226+ if details .Name == "" {
227+ return errors .New ("topic name cannot be empty" )
228+ }
229+ return CapturedTopicCreationDetails {details }
230+ },
231+ }
232+ m := New (& mockCreator )
233+
173234 // topic name
174235 tests .UpdateKeys (m , "topicA" )
175236 cmd := m .Update (tests .Key (tea .KeyEnter ))
@@ -212,13 +273,14 @@ func TestCreateTopic(t *testing.T) {
212273 "topicA" ,
213274 2 ,
214275 map [string ]string {
215- "cleanup.policy" : "delete- compact" ,
276+ "cleanup.policy" : "delete, compact" ,
216277 "delete.retention.ms" : "1029394" ,
217278 },
218279 int16 (3 ),
219280 },
220281 }, capturedDetails )
221282 })
283+
222284}
223285
224286func TestCreateTopic_Validation (t * testing.T ) {
0 commit comments