Skip to content

Commit

Permalink
update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH committed Aug 15, 2024
1 parent 6e231c1 commit 29d89f7
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions pkg/ysk/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,75 @@ func TestJsonIsSame(t *testing.T) {
assert.NilError(t, err)
assert.Equal(t, equal, true)
}

func TestWithFunc(t *testing.T) {
t.Run("WithId", func(t *testing.T) {
card := ysk.YSKCard{}
updatedCard := card.WithId("test-id")
assert.Equal(t, "test-id", updatedCard.Id)
})

t.Run("WithTaskContent", func(t *testing.T) {
card := ysk.YSKCard{}
updatedCard := card.WithTaskContent(ysk.FileIcon, "Test Title")
assert.Equal(t, ysk.FileIcon, updatedCard.Content.TitleIcon)
assert.Equal(t, "Test Title", updatedCard.Content.TitleText)
})

t.Run("WithProgress", func(t *testing.T) {
card := ysk.YSKCard{
Content: ysk.YSKCardContent{
BodyProgress: &ysk.YSKCardProgress{
Label: "hello",
Progress: 20,
},
},
}
updatedCard := card.WithProgress("Progress", 50)
assert.Assert(t, updatedCard.Content.BodyProgress != nil)
assert.Equal(t, "Progress", updatedCard.Content.BodyProgress.Label)
assert.Equal(t, 50, updatedCard.Content.BodyProgress.Progress)
})

t.Run("WithList", func(t *testing.T) {
card := ysk.YSKCard{}
listItems := []ysk.YSKCardListItem{
{Icon: ysk.FileIcon, Description: "Item 1", RightText: "Right Text 1"},
{Icon: ysk.DiskIcon, Description: "Item 2", RightText: "Right Text 2"},
}
updatedCard := card.WithList(listItems)
assert.DeepEqual(t, listItems, updatedCard.Content.BodyList)
})

t.Run("WithIconText", func(t *testing.T) {
card := ysk.YSKCard{}
updatedCard := card.WithIconText(ysk.StorageIcon, "Storage Description")
assert.Assert(t, updatedCard.Content.BodyIconWithText != nil)
assert.Equal(t, ysk.StorageIcon, updatedCard.Content.BodyIconWithText.Icon)
assert.Equal(t, "Storage Description", updatedCard.Content.BodyIconWithText.Description)
})

t.Run("WithFooterActions", func(t *testing.T) {
card := ysk.YSKCard{}
actions := []ysk.YSKCardFooterAction{
{Side: ysk.ActionPositionLeft, Style: "primary", Text: "Confirm", MessageBus: ysk.YSKCardMessageBusAction{Key: "action1", Payload: "payload1"}},
{Side: ysk.ActionPositionRight, Style: "secondary", Text: "Cancel", MessageBus: ysk.YSKCardMessageBusAction{Key: "action2", Payload: "payload2"}},
}
updatedCard := card.WithFooterActions(actions)
assert.DeepEqual(t, actions, updatedCard.Content.FooterActions)
})

t.Run("UpsertFooterAction", func(t *testing.T) {
card := ysk.YSKCard{
Content: ysk.YSKCardContent{
FooterActions: []ysk.YSKCardFooterAction{
{Side: ysk.ActionPositionLeft, Style: "primary", Text: "Old Button", MessageBus: ysk.YSKCardMessageBusAction{Key: "old", Payload: "old"}},
},
},
}
newAction := ysk.YSKCardFooterAction{Side: ysk.ActionPositionLeft, Style: "primary", Text: "New Button", MessageBus: ysk.YSKCardMessageBusAction{Key: "new", Payload: "new"}}
updatedCard := card.UpsertFooterAction(newAction)
assert.Equal(t, 1, len(updatedCard.Content.FooterActions))
assert.DeepEqual(t, newAction, updatedCard.Content.FooterActions[0])
})
}

0 comments on commit 29d89f7

Please sign in to comment.