Skip to content

Commit b2051f9

Browse files
committed
test(photoalbums): resolve created folder IDs dynamically and avoid brittle selectors; use dynamic folder ids for navigation and robust wait/click
1 parent 2d8e57b commit b2051f9

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

tests/Browser/User/PhotoalbumsPluginTest.php

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
*/
1616
class PhotoalbumsPluginTest extends DuskTestCase
1717
{
18+
/** @var int|null 写真用アルバムのフォルダID */
19+
private $photoFolderId = null;
20+
/** @var int|null 動画用アルバムのフォルダID */
21+
private $movieFolderId = null;
1822
/**
1923
* フォトアルバムテスト
2024
*
@@ -67,15 +71,17 @@ private function index()
6771
->assertPathBeginsWith('/')
6872
->screenshot('user/photoalbums/index/images/index1');
6973

70-
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/2#frame-' . $this->test_frame->id)
71-
->waitFor('#photo_1')
74+
$targetFolder = $this->photoFolderId ?? 2;
75+
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/' . $targetFolder . '#frame-' . $this->test_frame->id)
76+
->waitFor('[id^="photo_"]')
7277
->screenshot('user/photoalbums/index/images/index2');
7378

74-
$browser->click('#photo_1')
79+
$browser->click('[id^="photo_"]')
7580
->pause(500)
7681
->screenshot('user/photoalbums/index/images/index3');
7782

78-
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/3#frame-' . $this->test_frame->id)
83+
$targetMovieFolder = $this->movieFolderId ?? 3;
84+
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/' . $targetMovieFolder . '#frame-' . $this->test_frame->id)
7985
->waitFor('#a_embed_code_check10')
8086
->click('#a_embed_code_check10')
8187
->pause(1000)
@@ -125,6 +131,24 @@ private function makeFolder()
125131
->screenshot('user/photoalbums/makeFolder/images/makeFolder2');
126132
});
127133

134+
// 作成したフォルダのIDを取得
135+
$bucket = Buckets::where('plugin_name', 'photoalbums')->orderBy('id', 'desc')->first();
136+
if ($bucket) {
137+
$album = Photoalbum::where('bucket_id', $bucket->id)->first();
138+
if ($album) {
139+
$photoFolder = PhotoalbumContent::where('photoalbum_id', $album->id)
140+
->where('is_folder', PhotoalbumContent::is_folder_on)
141+
->where('name', '写真用アルバム')
142+
->orderBy('id', 'desc')->first();
143+
$movieFolder = PhotoalbumContent::where('photoalbum_id', $album->id)
144+
->where('is_folder', PhotoalbumContent::is_folder_on)
145+
->where('name', '動画用アルバム')
146+
->orderBy('id', 'desc')->first();
147+
$this->photoFolderId = optional($photoFolder)->id;
148+
$this->movieFolderId = optional($movieFolder)->id;
149+
}
150+
}
151+
128152
// マニュアル用データ出力
129153
$this->putManualData('[
130154
{"path": "user/photoalbums/makeFolder/images/makeFolder1",
@@ -143,7 +167,8 @@ private function makeFolder()
143167
private function uploadOne(&$browser, ...$filenames)
144168
{
145169
foreach ($filenames as $filename) {
146-
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/2#frame-' . $this->test_frame->id)
170+
$targetFolder = $this->photoFolderId ?? 2;
171+
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/' . $targetFolder . '#frame-' . $this->test_frame->id)
147172
->press('画像ファイル追加')
148173
->pause(500)
149174
->attach('upload_file[' . $this->test_frame->id . ']', __DIR__.'/photoalbum/'.$filename)
@@ -157,7 +182,8 @@ private function uploadOne(&$browser, ...$filenames)
157182
private function uploadMovieOne(&$browser, ...$base_filenames)
158183
{
159184
foreach ($base_filenames as $base_filename) {
160-
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/3#frame-' . $this->test_frame->id)
185+
$targetMovieFolder = $this->movieFolderId ?? 3;
186+
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/' . $targetMovieFolder . '#frame-' . $this->test_frame->id)
161187
->press('動画ファイル追加')
162188
->pause(500)
163189
->attach('upload_video[' . $this->test_frame->id . ']', __DIR__.'/photoalbum/' . $base_filename . '.mp4')
@@ -175,7 +201,8 @@ private function upload()
175201
{
176202
// 実行
177203
$this->browse(function (Browser $browser) {
178-
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/2#frame-' . $this->test_frame->id)
204+
$targetFolder = $this->photoFolderId ?? 2;
205+
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/' . $targetFolder . '#frame-' . $this->test_frame->id)
179206
->press('画像ファイル追加')
180207
->pause(500)
181208
->attach('upload_file[' . $this->test_frame->id . ']', __DIR__.'/photoalbum/Ariake_Arena.jpg')
@@ -187,7 +214,8 @@ private function upload()
187214

188215
$this->uploadOne($browser, "Bonito_and_Myoga.jpg", "Bonito_and_Olive.jpg", "Bonito_and_Onion.jpg", "じと目あんず.jpg");
189216

190-
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/3#frame-' . $this->test_frame->id)
217+
$targetMovieFolder = $this->movieFolderId ?? 3;
218+
$browser->visit('/plugin/photoalbums/changeDirectory/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/' . $targetMovieFolder . '#frame-' . $this->test_frame->id)
191219
->press('動画ファイル追加')
192220
->pause(500)
193221
->attach('upload_video[' . $this->test_frame->id . ']', __DIR__.'/photoalbum/あんず伏せ.mp4')

0 commit comments

Comments
 (0)