MCPcopy
hub / github.com/ory/kratos / TestRemoveMatchingNodes

Function TestRemoveMatchingNodes

ui/node/node_test.go:223–260  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

221}
222
223func TestRemoveMatchingNodes(t *testing.T) {
224 nodes := node.Nodes{
225 &node.Node{Type: node.Input, Group: node.PasswordGroup, Attributes: &node.InputAttributes{Name: "foo"}},
226 &node.Node{Type: node.Input, Group: node.PasswordGroup, Attributes: &node.InputAttributes{Name: "bar"}},
227 &node.Node{Type: node.Input, Group: node.PasswordGroup, Attributes: &node.InputAttributes{Name: "baz"}},
228 }
229
230 // Test when node to remove is present
231 nodeToRemove := &node.Node{Type: node.Input, Group: node.PasswordGroup, Attributes: &node.InputAttributes{Name: "bar"}}
232 nodes.RemoveMatching(nodeToRemove)
233 assert.Len(t, nodes, 2)
234 for _, n := range nodes {
235 assert.NotEqual(t, nodeToRemove.ID(), n.ID())
236 }
237
238 // Test when node to remove is not present
239 nodeToRemove = &node.Node{Type: node.Input, Group: node.PasswordGroup, Attributes: &node.InputAttributes{Name: "qux"}}
240 nodes.RemoveMatching(nodeToRemove)
241 assert.Len(t, nodes, 2) // length should remain the same
242
243 // Test when node to remove is present
244 nodeToRemove = &node.Node{Type: node.Input, Group: node.PasswordGroup, Attributes: &node.InputAttributes{Name: "baz"}}
245 ui := &container.Container{
246 Nodes: nodes,
247 }
248
249 ui.GetNodes().RemoveMatching(nodeToRemove)
250 assert.Len(t, *ui.GetNodes(), 1)
251 for _, n := range *ui.GetNodes() {
252 assert.NotEqual(t, "bar", n.ID())
253 assert.NotEqual(t, "baz", n.ID())
254 }
255
256 ui.Nodes.Append(node.NewInputField("method", "foo", "bar", node.InputAttributeTypeSubmit).WithMetaLabel(text.NewInfoNodeLabelContinue()))
257 assert.NotNil(t, ui.Nodes.Find("method"))
258 ui.GetNodes().RemoveMatching(node.NewInputField("method", "foo", "bar", node.InputAttributeTypeSubmit))
259 assert.Nil(t, ui.Nodes.Find("method"))
260}
261
262func TestNodeMarshalJSON(t *testing.T) {
263 tests := []struct {

Callers

nothing calls this directly

Calls 10

RemoveMatchingMethod · 0.95
IDMethod · 0.95
GetNodesMethod · 0.95
NewInputFieldFunction · 0.92
NewInfoNodeLabelContinueFunction · 0.92
AppendMethod · 0.80
WithMetaLabelMethod · 0.80
LenMethod · 0.65
IDMethod · 0.65
FindMethod · 0.45

Tested by

no test coverage detected