Skip to content

Commit 7ea8b33

Browse files
author
Greg Trihus
committed
TT-6957 Enhance OrgHead component to sanitize organization names in display
This update introduces a new function to clean organization names by removing unwanted characters, specifically ensuring names do not start with `>` or end with `<`. The changes include: - Added `cleanOrgName` function to process organization names before display. - Updated the OrgHead component to utilize the new function for rendering organization names. - Expanded Cypress tests to verify that organization names are displayed correctly without unwanted characters. These improvements enhance the user experience by ensuring that organization names are presented in a clean and consistent format.
1 parent 331b1a9 commit 7ea8b33

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

src/renderer/src/components/App/OrgHead.cy.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,4 +549,51 @@ describe('OrgHead', () => {
549549
// Should NOT display the organization name
550550
cy.contains(orgName).should('not.exist');
551551
});
552+
553+
it('should not display organization name that starts with > or ends with <', () => {
554+
const orgId = 'test-org-id';
555+
// Test with name that starts with >
556+
const orgNameWithPrefix = '>Test Organization';
557+
const orgDataWithPrefix = createMockOrganization(orgId, orgNameWithPrefix);
558+
559+
mountOrgHead(createInitialState(), ['/team'], orgId, orgDataWithPrefix);
560+
561+
// The displayed name should not start with >
562+
cy.get('h6, [variant="h6"]')
563+
.should('be.visible')
564+
.then(($el) => {
565+
const displayedText = $el.text();
566+
expect(displayedText.startsWith('>')).to.be.false;
567+
expect(displayedText).to.equal('Test Organization');
568+
});
569+
570+
// Test with name that ends with <
571+
const orgNameWithSuffix = 'Test Organization<';
572+
const orgDataWithSuffix = createMockOrganization(orgId, orgNameWithSuffix);
573+
574+
mountOrgHead(createInitialState(), ['/team'], orgId, orgDataWithSuffix);
575+
576+
// The displayed name should not end with <
577+
cy.get('h6, [variant="h6"]')
578+
.should('be.visible')
579+
.then(($el) => {
580+
const displayedText = $el.text();
581+
expect(displayedText.endsWith('<')).to.be.false;
582+
expect(displayedText).to.equal('Test Organization');
583+
});
584+
const orgNameWithBoth = '>Test Organization<';
585+
const orgDataWithBoth = createMockOrganization(orgId, orgNameWithBoth);
586+
587+
mountOrgHead(createInitialState(), ['/team'], orgId, orgDataWithBoth);
588+
589+
// The displayed name should not start with > or end with <
590+
cy.get('h6, [variant="h6"]')
591+
.should('be.visible')
592+
.then(($el) => {
593+
const displayedText = $el.text();
594+
expect(displayedText.startsWith('>')).to.be.false;
595+
expect(displayedText.endsWith('<')).to.be.false;
596+
expect(displayedText).to.equal('Test Organization');
597+
});
598+
});
552599
});

src/renderer/src/components/App/OrgHead.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ export const OrgHead = () => {
8585
setOpenMember(true);
8686
};
8787

88+
const cleanOrgName = (orgRec: OrganizationD | undefined) => {
89+
let name = orgRec?.attributes.name;
90+
if (!name) return '';
91+
if (name.startsWith('>')) {
92+
name = name.slice(1);
93+
}
94+
if (name.endsWith('<')) {
95+
name = name.slice(0, -1);
96+
}
97+
return name;
98+
};
99+
88100
return (
89101
<Stack direction="row">
90102
<Typography
@@ -100,7 +112,7 @@ export const OrgHead = () => {
100112
>
101113
{isSwitchTeamsScreen
102114
? API_CONFIG.productName
103-
: orgRec?.attributes.name || API_CONFIG.productName}
115+
: cleanOrgName(orgRec) || API_CONFIG.productName}
104116
</Typography>
105117
{isTeamScreen && (
106118
<>

0 commit comments

Comments
 (0)