Check the unique values in both tensors for the current batch via print(torch.unique(names)) and print(torch.unique(test_predicted)). If the current batch does not contain all classes, the confusion matrix will be created by only using the found class indices.
You could force the output of the non-existent classes via the labels argument:
x = torch.randint(0, 2, (10,))
y = torch.randint(0, 2, (10,))

confusion_matrix(x, y, labels=[0, 1, 2])
> array([[4, 2, 0],
         [1, 3, 0],
         [0, 0, 0]], dtype=int64)