Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clis/twitter/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,11 @@ async function submitTweet(page, text) {

const boxes = Array.from(document.querySelectorAll('[data-testid="tweetTextarea_0"]')).filter(visible);
const composerStillHasText = boxes.some((box) => normalize(box.innerText || box.textContent || '').includes(expectedText));
const hasMedia = !!document.querySelector('[data-testid="attachments"], [data-testid="tweetPhoto"]')
|| document.querySelectorAll('img[src^="blob:"], video[src^="blob:"]').length > 0;
const isComposeRoute = /^\\/compose\\/post\\/?$/.test(window.location.pathname);
const hasMedia = isComposeRoute && (
!!document.querySelector('[data-testid="attachments"], [data-testid="tweetPhoto"]')
|| document.querySelectorAll('img[src^="blob:"], video[src^="blob:"]').length > 0
);
if (!composerStillHasText && !hasMedia) {
return { ok: true, message: 'Tweet posted successfully.', ...statusUrl() };
}
Expand Down
18 changes: 18 additions & 0 deletions clis/twitter/post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,24 @@ describe('twitter post command', () => {
expect(submitScript).toContain('your post was sent');
});

it('does not treat timeline media as composer media after compose navigation completes', async () => {
const command = getCommand();
const page = makePage([
{ ok: true, previewCount: 1 }, // upload polling returns true
{ ok: true }, // focus composer
{ ok: true }, // verify native insertText
{ ok: true }, // click post
{ ok: true, message: 'Tweet posted successfully.' },
]);

await command.func(page, { text: 'with image', images: 'a.png' });

const submitScript = page.evaluate.mock.calls[4][0];
expect(submitScript).toContain('isComposeRoute');
expect(submitScript).toContain('/^\\/compose\\/post');
expect(submitScript).toContain('isComposeRoute &&');
});

it('returns failed when image upload times out', async () => {
const command = getCommand();
const page = makePage([
Expand Down
Loading