Computing TF-IDF on the whole dataset or only on training data?
Author gives all text data before separating train and test to
  function. Is it a true action or we must separate data first then
  perform tfidf fit_transform on train and transform on test?

I would consider this as already leaking some information about the test set into the training set.
I tend to always follow the rule that before any pre-processing first thing to do is to separate the data, create a hold-out set.
In the chapter seven of this book "TensorFlow Machine Learning Cookbook" the author in pre-processing data uses fit_transform function of scikit-learn to get the tfidf features of text for training. The author gives all text data to the function before separating it into train and test. Is it a true action or we must separate data first and then perform fit_transform on train and transform on test?