Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 92ee02f

Browse files
author
Kerry
authored
unit test Notifications.tsx (#7468)
Signed-off-by: Kerry Archibald <kerrya@element.io>
1 parent 4ab3470 commit 92ee02f

File tree

5 files changed

+428
-10
lines changed

5 files changed

+428
-10
lines changed

src/components/views/settings/Notifications.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
148148

149149
private async refreshRules(): Promise<Partial<IState>> {
150150
const ruleSets = await MatrixClientPeg.get().getPushRules();
151-
152151
const categories = {
153152
[RuleId.Master]: RuleClass.Master,
154153

@@ -182,6 +181,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
182181
for (const k in ruleSets.global) {
183182
// noinspection JSUnfilteredForInLoop
184183
const kind = k as PushRuleKind;
184+
185185
for (const r of ruleSets.global[kind]) {
186186
const rule: IAnnotatedPushRule = Object.assign(r, { kind });
187187
const category = categories[rule.rule_id] ?? RuleClass.Other;
@@ -471,6 +471,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
471471

472472
private renderTopSection() {
473473
const masterSwitch = <LabelledToggleSwitch
474+
data-test-id='notif-master-switch'
474475
value={!this.isInhibited}
475476
label={_t("Enable for this account")}
476477
onChange={this.onMasterRuleChanged}
@@ -484,6 +485,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
484485

485486
const emailSwitches = (this.state.threepids || []).filter(t => t.medium === ThreepidMedium.Email)
486487
.map(e => <LabelledToggleSwitch
488+
data-test-id='notif-email-switch'
487489
key={e.address}
488490
value={this.state.pushers.some(p => p.kind === "email" && p.pushkey === e.address)}
489491
label={_t("Enable email notifications for %(email)s", { email: e.address })}
@@ -495,20 +497,23 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
495497
{ masterSwitch }
496498

497499
<LabelledToggleSwitch
500+
data-test-id='notif-setting-notificationsEnabled'
498501
value={SettingsStore.getValue("notificationsEnabled")}
499502
onChange={this.onDesktopNotificationsChanged}
500503
label={_t('Enable desktop notifications for this session')}
501504
disabled={this.state.phase === Phase.Persisting}
502505
/>
503506

504507
<LabelledToggleSwitch
508+
data-test-id='notif-setting-notificationBodyEnabled'
505509
value={SettingsStore.getValue("notificationBodyEnabled")}
506510
onChange={this.onDesktopShowBodyChanged}
507511
label={_t('Show message in desktop notification')}
508512
disabled={this.state.phase === Phase.Persisting}
509513
/>
510514

511515
<LabelledToggleSwitch
516+
data-test-id='notif-setting-audioNotificationsEnabled'
512517
value={SettingsStore.getValue("audioNotificationsEnabled")}
513518
onChange={this.onAudioNotificationsChanged}
514519
label={_t('Enable audible notifications for this session')}
@@ -559,17 +564,27 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
559564
/>;
560565
}
561566

567+
const VectorStateToLabel = {
568+
[VectorState.On]: _t('On'),
569+
[VectorState.Off]: _t('Off'),
570+
[VectorState.Loud]: _t('Noisy'),
571+
};
572+
562573
const makeRadio = (r: IVectorPushRule, s: VectorState) => (
563574
<StyledRadioButton
564575
key={r.ruleId}
565576
name={r.ruleId}
566577
checked={r.vectorState === s}
567578
onChange={this.onRadioChecked.bind(this, r, s)}
568579
disabled={this.state.phase === Phase.Persisting}
580+
aria-label={VectorStateToLabel[s]}
569581
/>
570582
);
571583

572-
const rows = this.state.vectorPushRules[category].map(r => <tr key={category + r.ruleId}>
584+
const rows = this.state.vectorPushRules[category].map(r => <tr
585+
data-test-id={category + r.ruleId}
586+
key={category + r.ruleId}
587+
>
573588
<td>{ r.description }</td>
574589
<td>{ makeRadio(r, VectorState.Off) }</td>
575590
<td>{ makeRadio(r, VectorState.On) }</td>
@@ -592,13 +607,13 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
592607
}
593608

594609
return <>
595-
<table className='mx_UserNotifSettings_pushRulesTable'>
610+
<table data-test-id={`notif-section-${category}`} className='mx_UserNotifSettings_pushRulesTable'>
596611
<thead>
597612
<tr>
598613
<th>{ sectionName }</th>
599-
<th>{ _t("Off") }</th>
600-
<th>{ _t("On") }</th>
601-
<th>{ _t("Noisy") }</th>
614+
<th>{ VectorStateToLabel[VectorState.Off] }</th>
615+
<th>{ VectorStateToLabel[VectorState.On] }</th>
616+
<th>{ VectorStateToLabel[VectorState.Loud] }</th>
602617
</tr>
603618
</thead>
604619
<tbody>
@@ -635,7 +650,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
635650
// Ends up default centered
636651
return <Spinner />;
637652
} else if (this.state.phase === Phase.Error) {
638-
return <p>{ _t("There was an error loading your notification settings.") }</p>;
653+
return <p data-test-id='error-message'>{ _t("There was an error loading your notification settings.") }</p>;
639654
}
640655

641656
return <div className='mx_UserNotifSettings'>

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,11 +1276,11 @@
12761276
"Clear notifications": "Clear notifications",
12771277
"Keyword": "Keyword",
12781278
"New keyword": "New keyword",
1279-
"Global": "Global",
1280-
"Mentions & keywords": "Mentions & keywords",
1281-
"Off": "Off",
12821279
"On": "On",
1280+
"Off": "Off",
12831281
"Noisy": "Noisy",
1282+
"Global": "Global",
1283+
"Mentions & keywords": "Mentions & keywords",
12841284
"Notification targets": "Notification targets",
12851285
"There was an error loading your notification settings.": "There was an error loading your notification settings.",
12861286
"Failed to save your profile": "Failed to save your profile",

0 commit comments

Comments
 (0)