@@ -111,3 +111,119 @@ function waitForChannelIssueCondition(mixed $page, string $testId, string $condi
111111 'https://docs.trypost.it/knowledge-base/media#x-twitter ' ,
112112 )->assertNoJavaScriptErrors ();
113113});
114+
115+ /**
116+ * @param array<string, string> $platformMeta
117+ * @param array<string, int> $imageMeta
118+ * @return array{Post, PostPlatform}
119+ */
120+ function seedInstagramFeedImagePost (array $ platformMeta = ['aspect_ratio ' => 'original ' ], array $ imageMeta = ['width ' => 1080 , 'height ' => 1440 ], int $ size = 1024 ): array
121+ {
122+ $ user = User::factory ()->create ();
123+ $ workspace = Workspace::factory ()->create (['user_id ' => $ user ->id ]);
124+ $ workspace ->members ()->attach ($ user ->id , ['role ' => Role::Member->value ]);
125+ $ user ->update (['current_workspace_id ' => $ workspace ->id ]);
126+
127+ $ account = SocialAccount::factory ()->instagram ()->create (['workspace_id ' => $ workspace ->id ]);
128+ $ post = Post::factory ()->create ([
129+ 'workspace_id ' => $ workspace ->id ,
130+ 'user_id ' => $ user ->id ,
131+ 'content ' => 'A five-image carousel ' ,
132+ 'media ' => array_map (fn (int $ index ): array => [
133+ 'id ' => "image- {$ index }" ,
134+ 'type ' => 'image ' ,
135+ 'mime_type ' => 'image/jpeg ' ,
136+ 'path ' => "uploads/image- {$ index }.jpg " ,
137+ 'url ' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg== ' ,
138+ 'size ' => $ size ,
139+ 'meta ' => $ imageMeta ,
140+ ], range (1 , 5 )),
141+ ]);
142+ $ postPlatform = PostPlatform::factory ()->create ([
143+ 'post_id ' => $ post ->id ,
144+ 'social_account_id ' => $ account ->id ,
145+ 'platform ' => Platform::Instagram,
146+ 'content_type ' => ContentType::InstagramFeed,
147+ 'meta ' => $ platformMeta ,
148+ ]);
149+
150+ test ()->actingAs ($ user );
151+
152+ return [$ post , $ postPlatform ];
153+ }
154+
155+ test ('Instagram feed aspect choices do not reject the source image in the editor ' , function () {
156+ [$ post , $ postPlatform ] = seedInstagramFeedImagePost ();
157+
158+ $ page = visit (route ('app.posts.edit ' , $ post ));
159+ waitForChannelIssueTestId ($ page , "channel- {$ postPlatform ->id }" );
160+
161+ $ page ->click ('@instagram-settings-toggle ' );
162+
163+ foreach (['1-1 ' => 1.0 , '4-5 ' => 5 / 4 , '16-9 ' => 9 / 16 , 'original ' => 4 / 3 ] as $ option => $ expectedHeightToWidth ) {
164+ $ page ->click ("@instagram-aspect- {$ option }" )
165+ ->assertMissing ('@media-rules-warning ' )
166+ ->assertMissing ("@channel-issue- {$ postPlatform ->id }" )
167+ ->assertEnabled ('@post-submit ' )
168+ ->click ('@editor-tab-preview ' );
169+
170+ waitForChannelIssueTestId ($ page , 'instagram-feed-media ' );
171+
172+ $ heightToWidth = $ page ->script ('(() => { const frame = document.querySelector("[data-testid=instagram-feed-media]"); const rect = frame.getBoundingClientRect(); return rect.height / rect.width; })() ' );
173+
174+ expect (abs ($ heightToWidth - $ expectedHeightToWidth ))->toBeLessThan (0.01 );
175+
176+ $ page ->click ('@editor-tab-channels ' );
177+ }
178+
179+ $ page ->assertNoJavaScriptErrors ();
180+ });
181+
182+ test ('Instagram feed without a saved aspect ratio uses the original image ' , function () {
183+ [$ post , $ postPlatform ] = seedInstagramFeedImagePost ([]);
184+
185+ $ page = visit (route ('app.posts.edit ' , $ post ));
186+ waitForChannelIssueTestId ($ page , "channel- {$ postPlatform ->id }" );
187+
188+ $ page ->click ('@instagram-settings-toggle ' );
189+
190+ $ originalSelected = $ page ->script ('document.querySelector("[data-testid=instagram-aspect-original]").classList.contains("bg-violet-100") ' );
191+
192+ expect ($ originalSelected )->toBeTrue ();
193+
194+ $ page ->assertMissing ('@media-rules-warning ' )
195+ ->assertMissing ("@channel-issue- {$ postPlatform ->id }" )
196+ ->assertEnabled ('@post-submit ' )
197+ ->click ('@editor-tab-preview ' )
198+ ->assertNoJavaScriptErrors ();
199+
200+ waitForChannelIssueTestId ($ page , 'instagram-feed-media ' );
201+
202+ $ heightToWidth = $ page ->script ('(() => { const frame = document.querySelector("[data-testid=instagram-feed-media]"); const rect = frame.getBoundingClientRect(); return rect.height / rect.width; })() ' );
203+
204+ expect (abs ($ heightToWidth - 4 / 3 ))->toBeLessThan (0.01 );
205+ });
206+
207+ test ('Instagram original preview falls back to square when image dimensions are unavailable ' , function () {
208+ [$ post ] = seedInstagramFeedImagePost (imageMeta: []);
209+
210+ $ page = visit (route ('app.posts.edit ' , $ post ));
211+ $ page ->click ('@editor-tab-preview ' );
212+ waitForChannelIssueTestId ($ page , 'instagram-feed-media ' );
213+
214+ $ heightToWidth = $ page ->script ('(() => { const frame = document.querySelector("[data-testid=instagram-feed-media]"); const rect = frame.getBoundingClientRect(); return rect.height / rect.width; })() ' );
215+
216+ expect (abs ($ heightToWidth - 1.0 ))->toBeLessThan (0.01 );
217+ });
218+
219+ test ('Instagram aspect selection still enforces image size limits ' , function () {
220+ [$ post ] = seedInstagramFeedImagePost (size: 9 * 1024 * 1024 );
221+
222+ $ page = visit (route ('app.posts.edit ' , $ post ));
223+ $ page ->click ('@instagram-settings-toggle ' );
224+ waitForChannelIssueTestId ($ page , 'media-rules-warning ' );
225+
226+ $ page ->assertPresent ('@media-rules-warning ' )
227+ ->assertDisabled ('@post-submit ' )
228+ ->assertNoJavaScriptErrors ();
229+ });
0 commit comments