Skip to content

Commit

Permalink
feat: added ui test
Browse files Browse the repository at this point in the history
  • Loading branch information
ioanmo226 committed Nov 8, 2024
1 parent bf4e49e commit 2d07ab8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
11 changes: 11 additions & 0 deletions appium/api-mocks/apis/google/google-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class GmailMsg {
this.draftId = msg.draftId;
this.labelIds = msg.labelIds;
this.raw = msg.raw;
this.snippet = msg.mimeMsg.text;
this.sizeEstimate = Buffer.byteLength(msg.raw, 'utf-8');

const dateHeader = msg.mimeMsg.headers.get('date')! as Date;
Expand Down Expand Up @@ -488,6 +489,7 @@ export class GoogleData {

public getThreads = (labelIds: string[] = [], query?: string) => {
const subject = (query?.match(/subject: '([^"]+)'/) || [])[1]?.trim().toLowerCase();
const pgpFlag = query?.includes('-----BEGIN PGP MESSAGE-----');
const threads: GmailThread[] = [];

const filteredThreads = this.getMessagesAndDrafts()
Expand All @@ -504,6 +506,15 @@ export class GoogleData {
}
})
.filter(m => (subject ? GoogleData.msgSubject(m).toLowerCase().includes(subject) : true))
.filter(m => {
if (pgpFlag) {
return (
m.snippet?.includes('-----BEGIN PGP MESSAGE-----') ||
m.snippet?.includes('-----BEGIN PGP SIGNED MESSAGE-----')
);
}
return true;
})
.map(m => ({ historyId: m.historyId, id: m.threadId!, snippet: `MOCK SNIPPET: ${GoogleData.msgSubject(m)}` }));

for (const thread of filteredThreads) {
Expand Down
9 changes: 9 additions & 0 deletions appium/tests/screenobjects/menu-bar.screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const SELECTORS = {
TRASH_BTN: '~aid-menu-bar-item-trash',
DRAFTS_BTN: '~aid-menu-bar-item-drafts',
ALL_MAIL_BTN: '~aid-menu-bar-item-all-mail',
SHOW_ONLY_ENCRYPTED_EMAILS_TOGGLE: '~aid-toggle-pgp-only-node',
ADD_ACCOUNT_BUTTON: '~aid-add-account-btn',
};

Expand Down Expand Up @@ -51,6 +52,10 @@ class MenuBarScreen extends BaseScreen {
return $(SELECTORS.ALL_MAIL_BTN);
}

get showOnlyEncryptedEmailsToggle() {
return $(SELECTORS.SHOW_ONLY_ENCRYPTED_EMAILS_TOGGLE);
}

get addAccountButton() {
return $(SELECTORS.ADD_ACCOUNT_BUTTON);
}
Expand Down Expand Up @@ -110,6 +115,10 @@ class MenuBarScreen extends BaseScreen {
await ElementHelper.waitAndClick(await this.allMailButton);
};

clickShowOnlyEncryptedEmailsToggle = async () => {
await ElementHelper.waitAndClick(await this.showOnlyEncryptedEmailsToggle);
};

checkMenuBarItem = async (menuItem: string) => {
const menuBarItem = await $(`~aid-menu-item-${menuItem}`);
await menuBarItem.waitForDisplayed();
Expand Down
35 changes: 35 additions & 0 deletions appium/tests/specs/mock/inbox/CheckShowOnlyEncryptedEmails.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { MockApi } from 'api-mocks/mock';
import { MockApiConfig } from 'api-mocks/mock-config';
import { MailFolderScreen, MenuBarScreen, SetupKeyScreen, SplashScreen } from '../../../screenobjects/all-screens';

describe('INBOX: ', () => {
it('user is able to see only encrypted emails when he clicks show only encrypted emails button', async () => {
const mockApi = new MockApi();

mockApi.fesConfig = MockApiConfig.defaultEnterpriseFesConfiguration;
mockApi.ekmConfig = MockApiConfig.defaultEnterpriseEkmConfiguration;
const plainEmailSubject = 'Honor reply-to address - plain';
const encryptedEmailSubject = 'Encrypted email with public key attached';
mockApi.addGoogleAccount('[email protected]', {
messages: [plainEmailSubject, encryptedEmailSubject],
});

await mockApi.withMockedApis(async () => {
await SplashScreen.mockLogin();
await SetupKeyScreen.setPassPhrase();
await MailFolderScreen.checkInboxScreen();

// Check if both encrypted & plain emails are present
await MailFolderScreen.checkEmailIsDisplayed(plainEmailSubject);
await MailFolderScreen.checkEmailIsDisplayed(encryptedEmailSubject);

await MenuBarScreen.clickMenuBtn();
await MenuBarScreen.clickShowOnlyEncryptedEmailsToggle();
await browser.pause(1000);
await MenuBarScreen.clickInboxButton();

// Now check if plain email is not present
await MailFolderScreen.checkEmailIsNotDisplayed(plainEmailSubject);
});
});
});

0 comments on commit 2d07ab8

Please sign in to comment.