Skip to content

Commit

Permalink
CrOS Settings: Small refactor of accounts menu item tests
Browse files Browse the repository at this point in the history
Extracts a helper function to query the Accounts menu item, in effort
to reduce code duplication.

Bug: b:295060340
Test: browser_tests --gtest_filter="OSSettingsOsSettingsMenu*"
Change-Id: I236214b315eda37a66a6feb85636b68746007a05
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4950297
Auto-Submit: Wes Okuhara <wesokuhara@google.com>
Commit-Queue: Connie Xu <conniekxu@chromium.org>
Reviewed-by: Connie Xu <conniekxu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1211294}
  • Loading branch information
Wes Okuhara authored and Chromium LUCI CQ committed Oct 18, 2023
1 parent baa32b2 commit 8483192
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ suite('<os-settings-menu>', () => {
},
];

function getAccountsMenuItem(): OsSettingsMenuItemElement {
const accountsMenuItem =
queryMenuItemByPath(`/${routesMojom.PEOPLE_SECTION_PATH}`);
assertTrue(!!accountsMenuItem);
return accountsMenuItem;
}

suite('When there is only one account', () => {
setup(() => {
browserProxy.setAccountsForTesting(fakeAccounts.slice(0, 1));
Expand All @@ -195,18 +202,14 @@ suite('<os-settings-menu>', () => {
test('Description should show account email', async () => {
await createMenu();

const accountsMenuItem =
queryMenuItemByPath(`/${routesMojom.PEOPLE_SECTION_PATH}`);
assertTrue(!!accountsMenuItem);
const accountsMenuItem = getAccountsMenuItem();
assertEquals(fakeAccounts[0]!.email, accountsMenuItem.sublabel);
});

test('Description should update when an account is added', async () => {
await createMenu();

const accountsMenuItem =
queryMenuItemByPath(`/${routesMojom.PEOPLE_SECTION_PATH}`);
assertTrue(!!accountsMenuItem);
const accountsMenuItem = getAccountsMenuItem();
assertEquals(fakeAccounts[0]!.email, accountsMenuItem.sublabel);

// Update accounts to have 2 accounts
Expand All @@ -226,18 +229,14 @@ suite('<os-settings-menu>', () => {
test('Description should show number of accounts', async () => {
await createMenu();

const accountsMenuItem =
queryMenuItemByPath(`/${routesMojom.PEOPLE_SECTION_PATH}`);
assertTrue(!!accountsMenuItem);
const accountsMenuItem = getAccountsMenuItem();
assertEquals('2 accounts', accountsMenuItem.sublabel);
});

test('Description should update when an account is removed', async () => {
await createMenu();

const accountsMenuItem =
queryMenuItemByPath(`/${routesMojom.PEOPLE_SECTION_PATH}`);
assertTrue(!!accountsMenuItem);
const accountsMenuItem = getAccountsMenuItem();
assertEquals('2 accounts', accountsMenuItem.sublabel);

// Remove an account to leave only 1 account
Expand Down

0 comments on commit 8483192

Please sign in to comment.