Skip to content

Commit

Permalink
Update unit tests to assert on ID()
Browse files Browse the repository at this point in the history
  • Loading branch information
samstarling committed Dec 7, 2024
1 parent 0b0f28b commit fdb5665
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 44 deletions.
6 changes: 3 additions & 3 deletions block_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
)

func TestNewActionBlock(t *testing.T) {

approveBtnTxt := NewTextBlockObject("plain_text", "Approve", false, false)
approveBtn := NewButtonBlockElement("", "click_me_123", approveBtnTxt)

actionBlock := NewActionBlock("test", approveBtn)

assert.Equal(t, actionBlock.BlockType(), MBTAction)
assert.Equal(t, string(actionBlock.Type), "actions")
assert.Equal(t, actionBlock.BlockID, "test")
assert.Equal(t, actionBlock.ID(), "test")
assert.Equal(t, len(actionBlock.Elements.ElementSet), 1)

}
4 changes: 4 additions & 0 deletions block_call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (

func TestNewCallBlock(t *testing.T) {
callBlock := NewCallBlock("ACallID")

assert.Equal(t, callBlock.BlockType(), MBTCall)
assert.Equal(t, string(callBlock.Type), "call")
assert.Equal(t, callBlock.CallID, "ACallID")
assert.Equal(t, callBlock.BlockID, "")
assert.Equal(t, callBlock.ID(), "")
}
7 changes: 3 additions & 4 deletions block_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import (
)

func TestNewContextBlock(t *testing.T) {

locationPinImage := NewImageBlockElement("https://api.slack.com/img/blocks/bkb_template_images/tripAgentLocationMarker.png", "Location Pin Icon")
textExample := NewTextBlockObject("plain_text", "Location: Central Business District", true, false)

elements := []MixedElement{locationPinImage, textExample}

contextBlock := NewContextBlock("test", elements...)

assert.Equal(t, contextBlock.BlockType(), MBTContext)
assert.Equal(t, string(contextBlock.Type), "context")
assert.Equal(t, contextBlock.BlockID, "test")
assert.Equal(t, contextBlock.ID(), "test")
assert.Equal(t, len(contextBlock.ContextElements.Elements), 2)

}
6 changes: 4 additions & 2 deletions block_divider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
)

func TestNewDividerBlock(t *testing.T) {

dividerBlock := NewDividerBlock()
assert.Equal(t, string(dividerBlock.Type), "divider")

assert.Equal(t, dividerBlock.BlockType(), MBTDivider)
assert.Equal(t, string(dividerBlock.Type), "divider")
assert.Equal(t, dividerBlock.BlockID, "")
assert.Equal(t, dividerBlock.ID(), "")
}
14 changes: 0 additions & 14 deletions block_element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,24 @@ import (
)

func TestNewImageBlockElement(t *testing.T) {

imageElement := NewImageBlockElement("https://api.slack.com/img/blocks/bkb_template_images/tripAgentLocationMarker.png", "Location Pin Icon")

assert.Equal(t, string(imageElement.Type), "image")
assert.Contains(t, imageElement.ImageURL, "tripAgentLocationMarker")
assert.Equal(t, imageElement.AltText, "Location Pin Icon")

}

func TestNewButtonBlockElement(t *testing.T) {

btnTxt := NewTextBlockObject("plain_text", "Next 2 Results", false, false)
btnElement := NewButtonBlockElement("test", "click_me_123", btnTxt)

assert.Equal(t, string(btnElement.Type), "button")
assert.Equal(t, btnElement.ActionID, "test")
assert.Equal(t, btnElement.Value, "click_me_123")
assert.Equal(t, btnElement.Text.Text, "Next 2 Results")

}

func TestWithStyleForButtonElement(t *testing.T) {

// these values are irrelevant in this test
btnTxt := NewTextBlockObject("plain_text", "Next 2 Results", false, false)
btnElement := NewButtonBlockElement("test", "click_me_123", btnTxt)
Expand All @@ -40,33 +35,27 @@ func TestWithStyleForButtonElement(t *testing.T) {
assert.Equal(t, btnElement.Style, Style("primary"))
btnElement.WithStyle(StyleDanger)
assert.Equal(t, btnElement.Style, Style("danger"))

}

func TestWithURLForButtonElement(t *testing.T) {

btnTxt := NewTextBlockObject("plain_text", "Next 2 Results", false, false)
btnElement := NewButtonBlockElement("test", "click_me_123", btnTxt)

btnElement.WithURL("https://foo.bar")
assert.Equal(t, btnElement.URL, "https://foo.bar")

}

func TestNewOptionsSelectBlockElement(t *testing.T) {

testOptionText := NewTextBlockObject("plain_text", "Option One", false, false)
testOption := NewOptionBlockObject("test", testOptionText, nil)

option := NewOptionsSelectBlockElement("static_select", nil, "test", testOption)
assert.Equal(t, option.Type, "static_select")
assert.Equal(t, len(option.Options), 1)
assert.Nil(t, option.OptionGroups)

}

func TestNewOptionsGroupSelectBlockElement(t *testing.T) {

testOptionText := NewTextBlockObject("plain_text", "Option One", false, false)
testOption := NewOptionBlockObject("test", testOptionText, nil)
testLabel := NewTextBlockObject("plain_text", "Test Label", false, false)
Expand All @@ -77,11 +66,9 @@ func TestNewOptionsGroupSelectBlockElement(t *testing.T) {
assert.Equal(t, optGroup.Type, "static_select")
assert.Equal(t, optGroup.ActionID, "test")
assert.Equal(t, len(optGroup.OptionGroups), 1)

}

func TestNewOptionsMultiSelectBlockElement(t *testing.T) {

testOptionText := NewTextBlockObject("plain_text", "Option One", false, false)
testDescriptionText := NewTextBlockObject("plain_text", "Description One", false, false)
testOption := NewOptionBlockObject("test", testOptionText, testDescriptionText)
Expand All @@ -90,7 +77,6 @@ func TestNewOptionsMultiSelectBlockElement(t *testing.T) {
assert.Equal(t, option.Type, "static_select")
assert.Equal(t, len(option.Options), 1)
assert.Nil(t, option.OptionGroups)

}

func TestNewOptionsGroupMultiSelectBlockElement(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions block_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (

func TestNewFileBlock(t *testing.T) {
fileBlock := NewFileBlock("test", "external_id", "source")

assert.Equal(t, fileBlock.BlockType(), MBTFile)
assert.Equal(t, string(fileBlock.Type), "file")
assert.Equal(t, fileBlock.BlockID, "test")
assert.Equal(t, fileBlock.ID(), "test")
assert.Equal(t, fileBlock.ExternalID, "external_id")
assert.Equal(t, fileBlock.Source, "source")
}
5 changes: 3 additions & 2 deletions block_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
)

func TestNewHeaderBlock(t *testing.T) {

textInfo := NewTextBlockObject("plain_text", "This is quite the header", false, false)

headerBlock := NewHeaderBlock(textInfo, HeaderBlockOptionBlockID("test_block"))

assert.Equal(t, headerBlock.BlockType(), MBTHeader)
assert.Equal(t, string(headerBlock.Type), "header")
assert.Equal(t, headerBlock.ID(), "test_block")
assert.Equal(t, headerBlock.BlockID, "test_block")
assert.Equal(t, headerBlock.Text.Type, "plain_text")
assert.Contains(t, headerBlock.Text.Text, "quite the header")
Expand Down
4 changes: 2 additions & 2 deletions block_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
)

func TestNewImageBlock(t *testing.T) {

imageText := NewTextBlockObject("plain_text", "Location", false, false)
imageBlock := NewImageBlock("https://api.slack.com/img/blocks/bkb_template_images/tripAgentLocationMarker.png", "Marker", "test", imageText)

assert.Equal(t, imageBlock.BlockType(), MBTImage)
assert.Equal(t, string(imageBlock.Type), "image")
assert.Equal(t, imageBlock.Title.Type, "plain_text")
assert.Equal(t, imageBlock.ID(), "test")
assert.Equal(t, imageBlock.BlockID, "test")
assert.Contains(t, imageBlock.Title.Text, "Location")
assert.Contains(t, imageBlock.ImageURL, "tripAgentLocationMarker.png")

}
3 changes: 3 additions & 0 deletions block_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ func TestNewInputBlock(t *testing.T) {
element := NewDatePickerBlockElement("action_id")
hint := NewTextBlockObject("plain_text", "hint", false, false)
inputBlock := NewInputBlock("test", label, hint, element)

assert.Equal(t, inputBlock.BlockType(), MBTInput)
assert.Equal(t, string(inputBlock.Type), "input")
assert.Equal(t, inputBlock.ID(), "test")
assert.Equal(t, inputBlock.BlockID, "test")
assert.Equal(t, inputBlock.Label, label)
assert.Equal(t, inputBlock.Element, element)
Expand Down
12 changes: 0 additions & 12 deletions block_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,23 @@ import (
)

func TestNewImageBlockObject(t *testing.T) {

imageObject := NewImageBlockElement("https://api.slack.com/img/blocks/bkb_template_images/beagle.png", "Beagle")

assert.Equal(t, string(imageObject.Type), "image")
assert.Equal(t, imageObject.AltText, "Beagle")
assert.Contains(t, imageObject.ImageURL, "beagle.png")

}

func TestNewTextBlockObject(t *testing.T) {

textObject := NewTextBlockObject("plain_text", "test", true, false)

assert.Equal(t, textObject.Type, "plain_text")
assert.Equal(t, textObject.Text, "test")
assert.True(t, textObject.Emoji, "Emoji property should be true")
assert.False(t, textObject.Verbatim, "Verbatim should be false")

}

func TestNewConfirmationBlockObject(t *testing.T) {

titleObj := NewTextBlockObject("plain_text", "testTitle", false, false)
textObj := NewTextBlockObject("plain_text", "testText", false, false)
confirmObj := NewTextBlockObject("plain_text", "testConfirm", false, false)
Expand All @@ -41,11 +36,9 @@ func TestNewConfirmationBlockObject(t *testing.T) {
assert.Equal(t, confirmation.Text.Text, "testText")
assert.Equal(t, confirmation.Confirm.Text, "testConfirm")
assert.Nil(t, confirmation.Deny, "Deny should be nil")

}

func TestWithStyleForConfirmation(t *testing.T) {

// these values are irrelevant in this test
titleObj := NewTextBlockObject("plain_text", "testTitle", false, false)
textObj := NewTextBlockObject("plain_text", "testText", false, false)
Expand All @@ -58,23 +51,19 @@ func TestWithStyleForConfirmation(t *testing.T) {
assert.Equal(t, confirmation.Style, Style("primary"))
confirmation.WithStyle(StyleDanger)
assert.Equal(t, confirmation.Style, Style("danger"))

}

func TestNewOptionBlockObject(t *testing.T) {

valTextObj := NewTextBlockObject("plain_text", "testText", false, false)
valDescriptionObj := NewTextBlockObject("plain_text", "testDescription", false, false)
optObj := NewOptionBlockObject("testOpt", valTextObj, valDescriptionObj)

assert.Equal(t, optObj.Text.Text, "testText")
assert.Equal(t, optObj.Description.Text, "testDescription")
assert.Equal(t, optObj.Value, "testOpt")

}

func TestNewOptionGroupBlockElement(t *testing.T) {

labelObj := NewTextBlockObject("plain_text", "testLabel", false, false)
valTextObj := NewTextBlockObject("plain_text", "testText", false, false)
optObj := NewOptionBlockObject("testOpt", valTextObj, nil)
Expand All @@ -83,7 +72,6 @@ func TestNewOptionGroupBlockElement(t *testing.T) {

assert.Equal(t, optGroup.Label.Text, "testLabel")
assert.Len(t, optGroup.Options, 1, "Options should contain one element")

}

func TestValidateTextBlockObject(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions block_rich_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/go-test/deep"
"github.com/stretchr/testify/assert"
)

const (
Expand Down Expand Up @@ -83,6 +84,15 @@ const (
}`
)

func TestNewRichTextBlock(t *testing.T) {
richTextBlock := NewRichTextBlock("test_block")

assert.Equal(t, richTextBlock.BlockType(), MBTRichText)
assert.Equal(t, string(richTextBlock.Type), "rich_text")
assert.Equal(t, string(richTextBlock.BlockID), "test_block")
assert.Equal(t, string(richTextBlock.ID()), "test_block")
}

func TestRichTextBlock_UnmarshalJSON(t *testing.T) {
cases := []struct {
raw []byte
Expand Down
6 changes: 3 additions & 3 deletions block_section_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
)

func TestNewSectionBlock(t *testing.T) {

textInfo := NewTextBlockObject("mrkdwn", "*<fakeLink.toHotelPage.com|The Ritz-Carlton New Orleans>*\n★★★★★\n$340 per night\nRated: 9.1 - Excellent", false, false)

sectionBlock := NewSectionBlock(textInfo, nil, nil, SectionBlockOptionBlockID("test_block"))

assert.Equal(t, sectionBlock.BlockType(), MBTSection)
assert.Equal(t, string(sectionBlock.Type), "section")
assert.Equal(t, sectionBlock.BlockID, "test_block")
assert.Equal(t, sectionBlock.ID(), "test_block")
assert.Equal(t, len(sectionBlock.Fields), 0)
assert.Nil(t, sectionBlock.Accessory)
assert.Equal(t, sectionBlock.Text.Type, "mrkdwn")
assert.Contains(t, sectionBlock.Text.Text, "New Orleans")

}

func TestNewBlockSectionContainsAddedTextBlockAndAccessory(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions block_video_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
)

func TestNewVideoBlock(t *testing.T) {

videoTitle := NewTextBlockObject("plain_text", "VideoTitle", false, false)
videoBlock := NewVideoBlock(
"https://example.com/example.mp4",
"https://example.com/thumbnail.png",
"alternative text", "blockID", videoTitle)

assert.Equal(t, videoBlock.Type, MBTVideo)
assert.Equal(t, string(videoBlock.Type), "video")
assert.Equal(t, videoBlock.Title.Type, "plain_text")
assert.Equal(t, videoBlock.BlockID, "blockID")
assert.Equal(t, videoBlock.ID(), "blockID")
assert.Contains(t, videoBlock.Title.Text, "VideoTitle")
assert.Contains(t, videoBlock.VideoURL, "example.mp4")

}

0 comments on commit fdb5665

Please sign in to comment.