Skip to content
Merged
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
93 changes: 93 additions & 0 deletions .maestro/scripts/data-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,96 @@ const postWithRetry = (url, options) => retryRequest(() => http.post(url, option

const getWithRetry = (url, options) => retryRequest(() => http.get(url, options));

const getServerVersion = () => {
const result = getWithRetry(`${data.server}/api/info`, {
headers: {
'Content-Type': 'application/json'
}
});

return json(result.body)?.version;
};

const parseVersion = version => {
const [core, ...prerelease] = String(version || '').split('-');
return {
numbers: core.split('.').map(part => parseInt(part, 10) || 0),
isPrerelease: prerelease.length > 0
};
};

const isServerAtLeast = required => {
const current = parseVersion(getServerVersion());
const wanted = parseVersion(required);
const length = Math.max(current.numbers.length, wanted.numbers.length);

for (let i = 0; i < length; i++) {
const c = current.numbers[i] || 0;
const r = wanted.numbers[i] || 0;
if (c > r) {
return true;
}
if (c < r) {
return false;
}
}

// Same core version: a prerelease (8.4.0-rc.1) precedes the stable release (8.4.0)
return !current.isPrerelease || wanted.isPrerelease;
};

const isImageMessage = message =>
Boolean(
message &&
((Array.isArray(message.files) && message.files.some(file => String(file?.type || '').startsWith('image/'))) ||
(Array.isArray(message.attachments) && message.attachments.some(attachment => attachment?.image_url)))
);

const getRoomHistory = roomId => {
const result = getWithRetry(`${data.server}/api/v1/channels.history?roomId=${roomId}&count=20`, {
headers: {
'Content-Type': 'application/json',
...headers
}
});

return json(result.body)?.messages || [];
};

const waitFor = (predicate, { timeoutMs = 60000, intervalMs = 2000, label = 'condition' } = {}) => {
const deadline = Date.now() + timeoutMs;

while (Date.now() < deadline) {
const result = predicate();
Comment thread
Rohit3523 marked this conversation as resolved.
Resolved
if (result) {
return result;
}
sleep(intervalMs);
}

console.log(JSON.stringify({ waitForTimeout: true, label }));
return null;
};

const waitForImageMessage = (roomId, username, password, timeoutMs = 60000) => {
login(username, password);

return waitFor(
() => {
try {
return getRoomHistory(roomId).find(message => message?.u?.username === username && isImageMessage(message)) || null;
} catch (err) {
if (String(err?.message).startsWith('Non-retryable error')) {
throw err;
}
console.log(`channels.history failed, polling again: ${err?.message}`);
return null;
}
},
{ timeoutMs, label: `image message in ${roomId}` }
);
};

output.utils = {
createUser,
createUserWithPasswordChange,
Expand All @@ -289,6 +379,9 @@ output.utils = {
createRandomRoom,
sendMessage,
getProfileInfo,
getServerVersion,
isServerAtLeast,
waitForImageMessage,
post,
reactAsNewUsers,
login,
Expand Down
55 changes: 55 additions & 0 deletions .maestro/tests/room/attachment-send.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
appId: ${APP_ID}
name: Attachment Send
onFlowStart:
- runFlow: '../../helpers/setup.yaml'
onFlowComplete:
- evalScript: ${output.utils.deleteCreatedUsers()}
tags:
- test-9

---
- assertTrue: ${output.utils.isServerAtLeast('8.4.0')}
- evalScript: ${output.user = output.utils.createUser()}
- evalScript: ${output.room = output.utils.createRandomRoom(output.user.username, output.user.password)}
- evalScript: ${output.loggedInUser = output.utils.login(output.user.username, output.user.password)}

- runFlow:
file: '../../helpers/login-with-deeplink.yaml'
env:
USERNAME: ${output.user.username}
PASSWORD: ${output.user.password}
- runFlow:
file: '../../helpers/navigate-to-room.yaml'
env:
ROOM: ${output.room.name}

- extendedWaitUntil:
visible:
id: 'message-composer-actions'
timeout: 60000
- tapOn:
id: 'message-composer-actions'
- extendedWaitUntil:
visible:
id: 'action-sheet'
timeout: 60000
- extendedWaitUntil:
visible:
text: 'Choose from library'
timeout: 60000
- tapOn:
text: 'Choose from library'
- extendedWaitUntil:
visible:
id: 'message-composer-attachment-0'
timeout: 60000

- extendedWaitUntil:
visible:
id: 'message-composer-send'
timeout: 60000
- tapOn:
id: 'message-composer-send'

- evalScript: ${output.imageMessage = output.utils.waitForImageMessage(output.room._id, output.user.username, output.user.password)}
- assertTrue: ${output.imageMessage !== null}
10 changes: 10 additions & 0 deletions .sniffler/test-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@
"app/sagas/room.js"
]
},
{
"test": ".maestro/tests/room/attachment-send.yaml",
"dependsOn": [
"app/views/RoomView/**",
"app/containers/MessageComposer/**",
"app/lib/methods/helpers/ImagePicker/**",
"app/lib/methods/sendFileMessage/**",
"app/lib/hooks/useAltTextSupported.ts"
]
},
{
"test": ".maestro/tests/room/reaction-picker-small-screen.yaml",
"dependsOn": ["app/containers/EmojiPicker/**", "app/containers/ReactionsList/**"]
Expand Down
Loading