Skip to content

Commit

Permalink
feat: include name in organization not reachable (#1471)
Browse files Browse the repository at this point in the history
Signed-off-by: Svetoslav Borislavov <[email protected]>
Signed-off-by: Yordan Iliev <[email protected]>
Co-authored-by: Yordan Iliev <[email protected]>
  • Loading branch information
SvetBorislavov and yiliev0 authored Jan 22, 2025
1 parent fbf3987 commit 386c1df
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 50 deletions.
34 changes: 5 additions & 29 deletions automation/pages/OrganizationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class OrganizationPage extends BasePage {
this.users = []; // List to store user credentials
this.transactions = []; // List to store transactions
this.organizationRecoveryWords = []; // List to store recovery phrase words for organization
this.badOrganizationList = []; // List to store bad organizations
this.complexAccountId = []; // List to store complex account ids
this.complexFileId = []; // List to store complex file ids
this.registrationPage = new RegistrationPage(window);
Expand All @@ -72,7 +71,6 @@ class OrganizationPage extends BasePage {
dropdownSelectModeSelector = 'dropdown-select-mode';
dropdownSelectedModeSelector = 'dropdown-selected-mode';
editNicknameOrganizationButtonSelector = 'button-edit-nickname';
closeErrorModalButtonSelector = 'button-close-modal';
logoutButtonSelector = 'button-logout';
contactListButton = 'button-contact-list';
deleteNextButtonSelector = 'button-delete-next';
Expand All @@ -88,6 +86,7 @@ class OrganizationPage extends BasePage {
signTransactionButtonSelector = 'button-sign-org-transaction';
nextTransactionButtonSelector = 'button-next-org-transaction';
signAllTransactionsButtonSelector = 'button-sign-all-tx';
cancelAddingOrganizationButtonSelector = 'button-cancel-adding-org';

// Inputs
organizationNicknameInputSelector = 'input-organization-nickname';
Expand All @@ -98,7 +97,6 @@ class OrganizationPage extends BasePage {
editOrganizationNicknameInputSelector = 'input-edit-nickname';

// Texts
organizationErrorMessageSelector = 'p-organization-error-message';
organizationNicknameTextSelector = 'span-organization-nickname';
transactionDetailsIdSelector = 'p-transaction-details-id';
transactionValidStartSelector = 'p-transaction-details-valid-start';
Expand Down Expand Up @@ -177,7 +175,6 @@ class OrganizationPage extends BasePage {
const serverUrl = process.env.ORGANIZATION_URL + Math.floor(Math.random() * 10);
await this.clickOnAddNewOrganizationButton();
await this.fillOrganizationDetailsAndContinue(organizationNickname, serverUrl);
this.badOrganizationList.push(organizationNickname);
}

/**
Expand Down Expand Up @@ -319,31 +316,10 @@ class OrganizationPage extends BasePage {
return checks.every(isTrue => isTrue);
}

async getOrganizationErrorMessage() {
return await this.getText(this.organizationErrorMessageSelector);
}

async clickOnCloseErrorModalButton() {
await this.click(this.closeErrorModalButtonSelector);
}

async clickOnDeleteSecondOrganization() {
await this.click(this.deleteOrganizationButtonSelector, 1);
}

async clickOnDeleteFirstOrganization() {
await this.click(this.deleteOrganizationButtonSelector, 0);
}

async ensureBadOrganizationExists() {
if (this.badOrganizationList.length === 0) {
await this.settingsPage.clickOnSettingsButton();
await this.settingsPage.clickOnOrganisationsTab();
await this.setupWrongOrganization();
await this.clickOnCloseErrorModalButton();
}
}

async clickOnSelectModeDropdown() {
await this.click(this.dropdownSelectModeSelector);
}
Expand Down Expand Up @@ -1466,10 +1442,6 @@ class OrganizationPage extends BasePage {
return await this.getText(this.observerIndexSelector + index);
}

async getNotificationNumberText() {
return await this.getText(this.spanNotificationNumberSelector);
}

async isNotificationNumberVisible() {
return await this.isElementVisible(this.spanNotificationNumberSelector);
}
Expand Down Expand Up @@ -1505,6 +1477,10 @@ class OrganizationPage extends BasePage {
async isNextTransactionButtonVisible() {
return await this.isElementVisible(this.nextTransactionButtonSelector);
}

async clickOnCancelAddingOrganizationButton() {
await this.click(this.cancelAddingOrganizationButtonSelector);
}
}

module.exports = OrganizationPage;
34 changes: 18 additions & 16 deletions automation/tests/organizationSettingsTests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,11 @@ test.describe('Organization Settings tests', () => {
});

test('Verify error message when user adds non-existing organization', async () => {
await organizationPage.setupWrongOrganization();
const errorMessage = (await organizationPage.getOrganizationErrorMessage()).trim();
expect(errorMessage).toBe('Organization server is not reachable');
await organizationPage.clickOnCloseErrorModalButton();
});

test('Verify user can delete an organization', async () => {
await organizationPage.ensureBadOrganizationExists();
await settingsPage.clickOnSettingsButton();
await settingsPage.clickOnOrganisationsTab();
await loginPage.waitForToastToDisappear();
await organizationPage.clickOnDeleteSecondOrganization();

await organizationPage.setupWrongOrganization();
const toastMessage = await registrationPage.getToastMessage();
expect(toastMessage).toBe('Connection deleted successfully');

const isDeletedFromDb = await organizationPage.verifyOrganizationExists('Bad Organization');
expect(isDeletedFromDb).toBe(false);
expect(toastMessage).toBe('Organization does not exist. Please check the server URL');
await organizationPage.clickOnCancelAddingOrganizationButton();
});

test('Verify user is prompted for mnemonic phrase and can recover account when resetting organization', async () => {
Expand Down Expand Up @@ -212,4 +199,19 @@ test.describe('Organization Settings tests', () => {
await transactionPage.clickOnTransactionsMenuButton();
expect(await organizationPage.returnAllTabsVisible()).toBe(true);
});

test('Verify user can delete an organization', async () => {
await organizationPage.selectPersonalMode();
await settingsPage.clickOnSettingsButton();
await settingsPage.clickOnOrganisationsTab();
await loginPage.waitForToastToDisappear();
await organizationPage.clickOnDeleteFirstOrganization();

const toastMessage = await registrationPage.getToastMessage();
expect(toastMessage).toBe('Connection deleted successfully');

const orgName = await organizationPage.getOrganizationNicknameText();
const isDeletedFromDb = await organizationPage.verifyOrganizationExists(orgName);
expect(isDeletedFromDb).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import AppButton from '@renderer/components/ui/AppButton.vue';
import AppModal from '@renderer/components/ui/AppModal.vue';
import AppInput from '@renderer/components/ui/AppInput.vue';
import AppCustomIcon from '@renderer/components/ui/AppCustomIcon.vue';
import { healthCheck } from '@renderer/services/organization';
/* Props */
const props = defineProps<{
Expand Down Expand Up @@ -46,6 +47,12 @@ const handleAdd = async () => {
throw new Error('Invalid Server URL');
}
try {
const active = await healthCheck(serverUrl.value);
if (!active) {
throw new Error('Organization does not exist. Please check the server URL');
}
const organization = await addOrganization({
nickname: nickname.value.trim() || `Organization ${user.organizations.length + 1}`,
serverUrl: serverUrl.value,
Expand Down Expand Up @@ -111,7 +118,11 @@ watch(
<hr class="separator my-5" />

<div class="flex-between-centered gap-4">
<AppButton color="borderless" type="button" @click="$emit('update:show', false)"
<AppButton
data-testid="button-cancel-adding-org"
color="borderless"
type="button"
@click="$emit('update:show', false)"
>Cancel</AppButton
>
<AppButton color="primary" data-testid="button-add-organization-in-modal" type="submit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const user = useUserStore();
/* State */
const inactiveSelectedOrganizationModalShown = ref(false);
const organizationNickname = ref<string | null>(null);
const organizationUrl = ref<string | null>(null);
/* Handlers */
const handleSelectedOrganizationNotActiveSubmit = async () => {
inactiveSelectedOrganizationModalShown.value = false;
};
Expand All @@ -28,7 +29,12 @@ watch(
if (!isOrganizationActive(selectedOrganization)) {
inactiveSelectedOrganizationModalShown.value = true;
throw new Error('Organization server is not reachable');
const nickname = user.organizations.find(
organization => organization.serverUrl === selectedOrganization.serverUrl,
)?.nickname;
organizationNickname.value = nickname || null;
organizationUrl.value = selectedOrganization.serverUrl;
}
},
);
Expand All @@ -47,15 +53,20 @@ watch(
@click="inactiveSelectedOrganizationModalShown = false"
></i>
</div>
<form class="mt-3" @submit.prevent="handleSelectedOrganizationNotActiveSubmit">
<form
class="overflow-hidden mt-3"
@submit.prevent="handleSelectedOrganizationNotActiveSubmit"
>
<h3 class="text-center text-title text-bold">Organization status error</h3>
<p
class="text-center text-small text-secondary mt-4"
data-testid="p-organization-error-message"
>
Organization server is not reachable
{{ organizationNickname }} <span class="text-nobreak">is not reachable</span>
</p>

<hr class="separator my-5" />

<div class="d-grid">
<AppButton color="primary" data-testid="button-close-modal" type="submit"
>Close</AppButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const handleChangeNickname = async (e: Event) => {
if (nickname.length === 0) {
toast.error('Nickname cannot be empty');
} else if (user.organizations.some(org => org.nickname === nickname)) {
toast.error('Nickname already exists');
} else {
await updateOrganization(user.organizations[index].id, { nickname });
user.organizations[index].nickname = nickname;
Expand Down

0 comments on commit 386c1df

Please sign in to comment.