I have a very simple popup dialog that is driven by JavaScript in my Laravel app. Essentially, on click, a class is added to the popup div that uses a CSS transition to change its opacity from 0 to 1.
Here's my test:
public function testCantFindCodePopup()
{
$customer = $this->createCustomer();
$this->fillOutEmailAndDob($customer);
$this->visit('/product-codes/new')
->dontSee("Still can't find your code?");
$this->click('Can\'t find your code?');
sleep(0.5);
$this->see("Call customer service");
}
The transition takes 300ms, so I thought sleeping for 500ms would solve the issue, but no dice.
And actually, the test fails on the dontSee("Still can't find your code?") part, even though that text is inside of the popup, which has display: none set on it on load.
Am I doing something wrong, or is PHPUnit not aware of CSS and JavaScript like capybara is (because it runs in a headless browser).
If I can't use PHPUnit for this type of integration test, is there something similar that I can use? Note that I have ~70 other tests in PHPUnit, so whatever other tool there is, it can't be a wholesale replacement; ideally it'd exist alongside my PHPUnit tests.
Edit
Relevant part of the blade template:
<div class="form-control">
<label for="product-code">Enter Your{{$second}}Code</label>
<input type="text" id="product-code" name="product-code" />
</div>
<button class="btn btn-dark" type="submit">Submit</button>
<span class="label-explanation js__popup-toggle">Can't find your code?
<div class='popup'>
<span class="popup__close">×</span>
<img src="/assets/images/find-code-pop-up.png" alt="[alt text]" />
<p class="popup__cannot-find">Still can't find your code?<br/> Call customer service at xxx-xxx-xxxx.</p>
Relevant CSS:
.popup
width 300px
position absolute
left 35%
bottom 0
transition width 0.3s, height 0.3s, opacity 0.3s, transform 0.45s
opacity 0
background rgba(255,255,255,0.9)
color $brand-primary-dark
text-align center
transform scale(0)
p
font-size 16px
text-transform none
line-height 1.15
&.js__display
height auto
opacity 1
transform scale(1)
z-index 9999
.popup__close
font-size 20px
position absolute
top 0
right 5px
transition font-size 0.3s
&:hover
font-size 24px