Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented tilfinltd/aws-extend-switch-roles#290 #295

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ <h1>Settings</h1>
<li><label for="showOnlyMatchingRolesCheckBox"><input type="checkbox" id="showOnlyMatchingRolesCheckBox">Show only matching roles</label></li>
<li><label for="signinEndpointInHereCheckBox"><input type="checkbox" id="signinEndpointInHereCheckBox">Sign-in endpoint in current region</label> (Experimental, Supporters only) </li>
<li><s><label for="autoAssumeLastRoleCheckBox"><input type="checkbox" id="autoAssumeLastRoleCheckBox">Automatically assume last assumed role</label> (Experimental) </s> (temporarily disabled) </li>
<li><label for="enableImageBorderColorCheckBox"><input type="checkbox" id="enableImageBorderColorCheckBox">Enable image border color</label></li>
<li>
Configuration storage:
<label for="configStorageSyncRadioButton"><input type="radio" name="configStorage" id="configStorageSyncRadioButton" value="sync">Sync</label>
Expand Down
14 changes: 8 additions & 6 deletions src/lib/create_role_list_item.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
export function createRoleListItem(document, item, url, region, { hidesAccountId }, selectHandler) {
export function createRoleListItem(document, item, url, region, { hidesAccountId, enableImageBorderColor }, selectHandler) {
const li = document.createElement('li');
const headSquare = document.createElement('span');
headSquare.textContent = ' ';
headSquare.className = 'headSquare';
if (item.color) {
if (item.image) {
headSquare.style.backgroundImage = `url('${item.image.replace(/"/g, '')}')`;
if (item.color && enableImageBorderColor) {
headSquare.style.border = `3px solid #${item.color}`;
}
} else if (item.color) {
headSquare.style.backgroundColor = `#${item.color}`;
} else if (!item.image) {
} else {
// set gray if both color and image are undefined
headSquare.style.backgroundColor = '#aaaaaa';
}
if (item.image) {
headSquare.style.backgroundImage = `url('${item.image.replace(/"/g, '')}')`;
}

const anchor = document.createElement('a');
anchor.href = "#";
Expand Down
2 changes: 1 addition & 1 deletion src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ window.onload = function() {
}
}

const booleanSettings = ['hidesAccountId', 'showOnlyMatchingRoles', 'autoAssumeLastRole'];
const booleanSettings = ['hidesAccountId', 'showOnlyMatchingRoles', 'autoAssumeLastRole', 'enableImageBorderColor'];
for (let key of booleanSettings) {
elById(`${key}CheckBox`).onchange = function() {
syncStorageRepo.set({ [key]: this.checked });
Expand Down
5 changes: 3 additions & 2 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,21 @@ function main() {

function loadFormList(curURL, userInfo, tabId) {
const storageRepo = new SyncStorageRepository(chrome || browser)
storageRepo.get(['hidesAccountId', 'showOnlyMatchingRoles', 'configStorageArea', 'signinEndpointInHere'])
storageRepo.get(['hidesAccountId', 'showOnlyMatchingRoles', 'configStorageArea', 'signinEndpointInHere', 'enableImageBorderColor'])
.then(data => {
const hidesAccountId = data.hidesAccountId || false;
const showOnlyMatchingRoles = data.showOnlyMatchingRoles || false;
const configStorageArea = data.configStorageArea || 'sync';
const signinEndpointInHere = data.signinEndpointInHere || false;
const enableImageBorderColor = data.enableImageBorderColor || false;

new StorageRepository(chrome || browser, configStorageArea).get(['profiles', 'profiles_1', 'profiles_2', 'profiles_3', 'profiles_4'])
.then(data => {
if (data.profiles) {
const dps = new DataProfilesSplitter();
const profiles = dps.profilesFromDataSet(data);
const profileSet = createProfileSet(profiles, userInfo, { showOnlyMatchingRoles });
renderRoleList(profileSet.destProfiles, tabId, curURL, { hidesAccountId, signinEndpointInHere });
renderRoleList(profileSet.destProfiles, tabId, curURL, { hidesAccountId, signinEndpointInHere, enableImageBorderColor });
setupRoleFilter();
}
})
Expand Down
28 changes: 23 additions & 5 deletions test/lib/create_role_list_item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ background-image: url(https://www.exapmle.com/icon.png);"> </span>prf<span class
});

describe('profile has color and image', () => {
it('returns li element', () => {
it('returns li element with image border color when enableImageBorderColor is true', () => {
const item = {
profile: 'prf',
aws_account_id: '333344441111',
Expand All @@ -106,13 +106,31 @@ background-image: url(https://www.exapmle.com/icon.png);"> </span>prf<span class
image: '"https://www.exapmle.com/icon.png"',
}
const url = 'https://console.aws.amazonaws.com/?region=us-east-1';
const li = createRoleListItem(window.document, item, url, 'us-east-1', {}, () => {});

const li = createRoleListItem(window.document, item, url, 'us-east-1', { enableImageBorderColor: true }, () => {});
const a = li.querySelector('a')
expect(a.innerHTML).to.eq(`<span class="headSquare" style="background-color: rgb(255, 170, 34); \
background-image: url(https://www.exapmle.com/icon.png);"> </span>prf<span class="suffixAccountId">333344441111</span>`);
expect(a.innerHTML).to.eq(`<span class="headSquare" style="background-image: url(https://www.exapmle.com/icon.png); border: 3px solid #ffaa22;"> </span>prf<span class="suffixAccountId">333344441111</span>`);
});
});

describe('profile has color and image', () => {
it('returns li element without color style when enableImageBorderColor is false', () => {
const item = {
profile: 'prf',
aws_account_id: '333344441111',
role_name: 'img-role',
color: 'ffaa22',
image: '"https://www.exapmle.com/icon.png"',
}
const url = 'https://console.aws.amazonaws.com/?region=us-east-1';
const li = createRoleListItem(window.document, item, url, 'us-east-1', { enableImageBorderColor: false }, () => {});

const a = li.querySelector('a')
expect(a.innerHTML).to.eq(`<span class="headSquare" style="background-image: url(https://www.exapmle.com/icon.png);"> </span>prf<span class="suffixAccountId">333344441111</span>`);
});
});



describe('profile has region', () => {
it('returns li element', () => {
Expand Down