Skip to content

Commit

Permalink
test: Add tests for organization transaction group (#1430)
Browse files Browse the repository at this point in the history
Signed-off-by: Yordan Iliev <[email protected]>
Signed-off-by: Svetoslav Borislavov <[email protected]>
Co-authored-by: Svetoslav Borislavov <[email protected]>
  • Loading branch information
yiliev0 and SvetBorislavov authored Jan 14, 2025
1 parent ce7aa9d commit eaedeb0
Show file tree
Hide file tree
Showing 16 changed files with 405 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,4 @@ automation/blob-report/
automation/playwright/.cache/
automation/.env
automation/data/*.bin
automation/data/*.csv
6 changes: 6 additions & 0 deletions automation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,9 @@ npx playwright test tests/SystemFileTests
```bash
npx playwright test tests/GroupTransactionTests
```

### 13. Group organization tests

```bash
npx playwright test tests/OrganizationGroupTests
```
143 changes: 142 additions & 1 deletion automation/pages/GroupPage.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const path = require('path');
const BasePage = require('./BasePage');
const TransactionPage = require('./TransactionPage');
const OrganizationPage = require('./OrganizationPage');
const { getTransactionGroupsForTransactionId } = require('../utils/databaseQueries');
const { generateCSVFile } = require('../utils/csvGenerator');

class GroupPage extends BasePage {
constructor(window) {
super(window);
this.window = window;
this.transactionPage = new TransactionPage(window);
this.organizationPage = new OrganizationPage(window);
}

/* Selectors */
Expand All @@ -24,10 +28,13 @@ class GroupPage extends BasePage {
deleteAllButtonSelector = 'button-delete-all';
confirmDeleteAllButtonSelector = 'button-confirm-delete-all';
confirmGroupTransactionButtonSelector = 'button-confirm-group-transaction';
detailsGroupButtonSelector = 'button-group-details';
importCsvButtonSelector = 'button-import-csv';

// Messages
// Text
toastMessageSelector = '.v-toast__text';
emptyTransactionTextSelector = 'p-empty-transaction-text';
transactionGroupDetailsIdSelector = 'td-group-transaction-id';

// Inputs
descriptionInputSelector = 'input-transaction-group-description';
Expand All @@ -38,6 +45,7 @@ class GroupPage extends BasePage {
transactionDeleteButtonIndexSelector = 'button-transaction-delete-';
transactionDuplicateButtonIndexSelector = 'button-transaction-duplicate-';
transactionEditButtonIndexSelector = 'button-transaction-edit-';
orgTransactionDetailsButtonIndexSelector = 'button-group-transaction-';

async closeModalIfVisible(selector) {
const modalButton = this.window.getByTestId(selector);
Expand Down Expand Up @@ -121,6 +129,31 @@ class GroupPage extends BasePage {
return await this.getText(this.transactionTimestampIndexSelector + index);
}

async getTransactionGroupDetailsId(index) {
return await this.getText(this.transactionGroupDetailsIdSelector, index);
}

async getAllTransactionTimestamps(numberOfTransactions) {
const timestamps = [];
for (let i = 0; i < numberOfTransactions; i++) {
timestamps.push(await this.getTransactionGroupDetailsId(i));
}
return timestamps;
}

async verifyAllTransactionsAreSuccessful(timestampsForVerification) {
for (let i = 0; i < timestampsForVerification.length; i++) {
const transactionDetails = await this.transactionPage.mirrorGetTransactionResponse(
timestampsForVerification[i],
);
const result = transactionDetails.transactions[0]?.result;
if (result !== 'SUCCESS') {
return false;
}
}
return true;
}

async clickTransactionDeleteButton(index) {
await this.click(this.transactionDeleteButtonIndexSelector + index);
}
Expand Down Expand Up @@ -153,6 +186,39 @@ class GroupPage extends BasePage {
}
}

async generateAndImportCsvFile(fromAccountId, numberOfTransactions = 10) {
const fileName = 'groupTransactions.csv';
const receiverAccount = '0.0.1031';
await generateCSVFile({
senderAccount: fromAccountId,
accountId: receiverAccount,
startingAmount: 1,
numberOfTransactions: numberOfTransactions,
fileName: fileName,
});
await this.uploadFile(
this.importCsvButtonSelector,
path.resolve(__dirname, '..', 'data', fileName),
);
}

async addOrgAllowanceTransactionToGroup(numberOfTransactions = 1, allowanceOwner, amount) {
await this.fillDescription('test');
for (let i = 0; i < numberOfTransactions; i++) {
await this.clickOnAddTransactionButton();
await this.transactionPage.clickOnApproveAllowanceTransaction();

await this.transactionPage.fillInAllowanceOwner(allowanceOwner);
await this.transactionPage.fillInAllowanceAmount(amount);
await this.transactionPage.fillInSpenderAccountId(
await this.getTextFromInputField(this.transactionPage.payerDropdownSelector),
this.addToGroupButtonSelector,
);

await this.clickAddToGroupButton();
}
}

async isEmptyTransactionTextVisible() {
return this.isElementVisible(this.emptyTransactionTextSelector);
}
Expand All @@ -178,6 +244,81 @@ class GroupPage extends BasePage {
async doTransactionGroupsExist(transactionId) {
return !!(await getTransactionGroupsForTransactionId(transactionId));
}

async clickOnDetailsGroupButton() {
await this.click(this.detailsGroupButtonSelector);
}

async clickOnTransactionDetailsButton(index) {
await this.click(this.orgTransactionDetailsButtonIndexSelector + index);
}

async logInAndSignGroupTransactionsByAllUsers(encryptionPassword) {
for (let i = 1; i < this.organizationPage.users.length; i++) {
console.log(`Signing transaction for user ${i}`);
const user = this.organizationPage.users[i];
await this.organizationPage.signInOrganization(user.email, user.password, encryptionPassword);
await this.transactionPage.clickOnTransactionsMenuButton();
await this.organizationPage.clickOnReadyToSignTab();
await this.clickOnDetailsGroupButton();
await this.clickOnTransactionDetailsButton(0);

// Initially sign the first transaction
await this.organizationPage.clickOnSignTransactionButton();

// After signing, we check if there's a "Next" button to continue to the next transaction
let hasNext = await this.isElementVisible(
this.organizationPage.nextTransactionButtonSelector,
);

while (hasNext) {
// Click on the "Next" button to move to the next transaction
await this.click(this.organizationPage.nextTransactionButtonSelector);

// Now the button transforms into "Sign" for the next transaction
// Sign this transaction as well
await this.organizationPage.clickOnSignTransactionButton();

// Check again if there's another transaction after this one
hasNext = await this.isElementVisible(this.organizationPage.nextTransactionButtonSelector);
}

await this.organizationPage.logoutFromOrganization();
}
}

async clickOnSignAllButton(retries = 3, retryDelay = 1000) {
const selector = this.organizationPage.signAllTransactionsButtonSelector;

for (let attempt = 1; attempt <= retries; attempt++) {
console.log(`Attempt ${attempt}/${retries} to click "Sign All" button.`);

try {
// Attempt to click the button
await this.click(selector);

// Wait for it to disappear (tweak timeouts as needed)
await this.waitForElementToDisappear(selector, 10000, 30000);

// If no error was thrown, we succeeded — break out
console.log(
`Successfully clicked "Sign All" button and it disappeared on attempt #${attempt}.`,
);
return; // or break;
} catch (error) {
console.error(`Attempt #${attempt} to click "Sign All" button failed: ${error.message}`);

if (attempt < retries) {
console.log(`Retrying in ${retryDelay}ms...`);
await new Promise(resolve => setTimeout(resolve, retryDelay));
} else {
throw new Error(
`Failed to click "Sign All" button and wait for it to disappear after ${retries} attempts.`,
);
}
}
}
}
}

module.exports = GroupPage;
10 changes: 3 additions & 7 deletions automation/pages/TransactionPage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path');
const BasePage = require('./BasePage');
const { getAccountDetails, getTransactionDetails } = require('../utils/mirrorNodeAPI');
const {
Expand All @@ -6,7 +7,6 @@ const {
verifyFileExists,
} = require('../utils/databaseQueries');
const { decodeAndFlattenKeys } = require('../utils/keyUtil');
const path = require('path');

class TransactionPage extends BasePage {
constructor(window) {
Expand Down Expand Up @@ -774,12 +774,8 @@ class TransactionPage extends BasePage {
);
}

async fillInSpenderAccountId(accountId) {
await this.fillInAccountId(
accountId,
this.allowanceSpenderAccountSelector,
this.signAndSubmitButtonSelector,
);
async fillInSpenderAccountId(accountId, buttonSelector = this.signAndSubmitButtonSelector) {
await this.fillInAccountId(accountId, this.allowanceSpenderAccountSelector, buttonSelector);
}

async fillInSpenderAccountIdNormally(accountId) {
Expand Down
4 changes: 1 addition & 3 deletions automation/tests/groupTransactionTests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { test } = require('@playwright/test');
const { expect } = require('playwright/test');
const RegistrationPage = require('../pages/RegistrationPage.js');
const LoginPage = require('../pages/LoginPage');
const SettingsPage = require('../pages/SettingsPage');
const TransactionPage = require('../pages/TransactionPage');
const GroupPage = require('../pages/GroupPage');
const { resetDbState } = require('../utils/databaseUtil');
Expand All @@ -16,15 +15,14 @@ const {

let app, window;
let globalCredentials = { email: '', password: '' };
let registrationPage, loginPage, settingsPage, transactionPage, groupPage;
let registrationPage, loginPage, transactionPage, groupPage;

test.describe('Group transaction tests', () => {
test.beforeAll(async () => {
await resetDbState();
({ app, window } = await setupApp());
loginPage = new LoginPage(window);
registrationPage = new RegistrationPage(window);
settingsPage = new SettingsPage(window);
transactionPage = new TransactionPage(window);
groupPage = new GroupPage(window);

Expand Down
1 change: 0 additions & 1 deletion automation/tests/organizationContactListTests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const OrganizationPage = require('../pages/OrganizationPage');
const SettingsPage = require('../pages/SettingsPage');
const ContactListPage = require('../pages/ContactListPage');
const { resetDbState, resetPostgresDbState } = require('../utils/databaseUtil');
const { getAssociatedAccounts } = require('../utils/mirrorNodeAPI');

let app, window;
let globalCredentials = { email: '', password: '' };
Expand Down
Loading

0 comments on commit eaedeb0

Please sign in to comment.