Find common directory path
Naming

Good names can greatly improve the readability of a program.
Many of the names in the posted code can be improved:


getPrefix: the function returns the common prefix. It would be good to include that important clarifying detail in the name.


If you intend to return the common parent directory, I would call the function getCommonParent.

text: the parameter is not just any text, it's an array of paths, so paths would be a better name that conveys the intention.
i: is fine in simple counting loops, but when you iterate over values that have a meaningful name, it's better to use that, for example in this example path.
test is also an overly generic name, instead of the more descriptive paths


Algorithm

The implementation will call commonPrefix method text.count + 1 times.
This is probably fine,
but you could reduce the number of calls to commonPrefix
by using a divide and conquer strategy.

For example, consider you have paths p1, p2, ..., pn.
You could call commonPrefix for each pair, to get n / 2 results.
Then you could call commonPrefix for each of those pairs.
And so on, until there is only one pair left:

p1 p2 p3 p4 p5 p6 p7 p8
|__|  |__|  |__|  |__|
 |_____|     |_____|
    |___________|
          |
          = the common prefix


Admittedly, this might be overkill for your use case.