-
-
Notifications
You must be signed in to change notification settings - Fork 777
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show a validation error in add-muc modal when no default MUC domain i…
…s found
- Loading branch information
Showing
7 changed files
with
54 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ export default class AddMUCModal extends BaseModal { | |
return s | ||
.trim() | ||
.replace(/\s+/g, '-') | ||
.replace(/\u0142/g, "l") | ||
.replace(/\u0142/g, 'l') | ||
.replace(/[^\x00-\x7F]/g, (c) => c.normalize('NFD').replace(/[\u0300-\u036f]/g, '')) | ||
.replace(/[^a-zA-Z0-9-]/g, '-') | ||
.replace(/-+/g, '-') | ||
|
@@ -75,7 +75,7 @@ export default class AddMUCModal extends BaseModal { | |
ev.preventDefault(); | ||
|
||
const autocomplete_el = /** @type {AutoCompleteComponent} */ (this.querySelector('converse-autocomplete')); | ||
if (autocomplete_el.onChange().error_message) return; | ||
if ((await autocomplete_el.onChange()).error_message) return; | ||
|
||
const { escapeNode, getNodeFromJid, getDomainFromJid } = Strophe; | ||
const form = /** @type {HTMLFormElement} */ (ev.target); | ||
|
@@ -109,9 +109,9 @@ export default class AddMUCModal extends BaseModal { | |
|
||
/** | ||
* @param {string} jid | ||
* @return {string} | ||
* @return {Promise<string>} | ||
*/ | ||
validateMUCJID(jid) { | ||
async validateMUCJID(jid) { | ||
if (jid.length === 0) { | ||
return __('Invalid groupchat address, it cannot be empty.'); | ||
} | ||
|
@@ -130,6 +130,16 @@ export default class AddMUCModal extends BaseModal { | |
return __('Invalid groupchat address, it cannot start or end with an @ sign.'); | ||
} | ||
|
||
if (!jid.includes('@')) { | ||
const muc_service = await u.muc.getDefaultMUCService(); | ||
if (!muc_service) { | ||
return __( | ||
"No default groupchat service found. "+ | ||
"You'll need to specify the full address, for example [email protected]" | ||
); | ||
} | ||
} | ||
|
||
const policy = api.settings.get('muc_roomid_policy'); | ||
if (policy && api.settings.get('muc_domain')) { | ||
if (api.settings.get('locked_muc_domain') || !u.isValidJID(jid)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,14 +28,10 @@ const nickname_input = () => { | |
*/ | ||
export default (el) => { | ||
const i18n_join = __('Join'); | ||
const muc_domain = api.settings.get('muc_domain'); | ||
|
||
let placeholder = ''; | ||
let label_name; | ||
if (api.settings.get('locked_muc_domain')) { | ||
label_name = __('Groupchat name'); | ||
} else { | ||
placeholder = muc_domain ? `name@${muc_domain}` : __('[email protected]'); | ||
label_name = __('Groupchat name or address'); | ||
} | ||
|
||
|
@@ -58,7 +54,6 @@ export default (el) => { | |
class="add-muc-autocomplete" | ||
min_chars="3" | ||
name="chatroom" | ||
placeholder="${placeholder}" | ||
position="below" | ||
required | ||
></converse-autocomplete>` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
/*global mock, converse */ | ||
const { Promise, sizzle, u } = converse.env; | ||
|
||
|
||
describe('The "Groupchats" Add modal', function () { | ||
|
||
beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza })); | ||
|
@@ -12,9 +11,6 @@ describe('The "Groupchats" Add modal', function () { | |
|
||
let label_name = modal.querySelector('label[for="chatroom"]'); | ||
expect(label_name.textContent.trim()).toBe('Groupchat name or address:'); | ||
const name_input = modal.querySelector('input[name="chatroom"]'); | ||
expect(name_input.placeholder).toBe('[email protected]'); | ||
|
||
const label_nick = modal.querySelector('label[for="nickname"]'); | ||
expect(label_nick.textContent.trim()).toBe('Nickname:'); | ||
const nick_input = modal.querySelector('input[name="nickname"]'); | ||
|
@@ -39,7 +35,6 @@ describe('The "Groupchats" Add modal', function () { | |
const label_name = modal.querySelector('label[for="chatroom"]'); | ||
expect(label_name.textContent.trim()).toBe('Groupchat name or address:'); | ||
let name_input = modal.querySelector('input[name="chatroom"]'); | ||
expect(name_input.placeholder).toBe('[email protected]'); | ||
name_input.value = 'lounge'; | ||
let nick_input = modal.querySelector('input[name="nickname"]'); | ||
nick_input.value = 'max'; | ||
|
@@ -66,7 +61,7 @@ describe('The "Groupchats" Add modal', function () { | |
}) | ||
); | ||
|
||
it('only uses the muc_domain if locked_muc_domain is true', mock.initConverse( | ||
it('uses the muc_domain if locked_muc_domain is true', mock.initConverse( | ||
['chatBoxesFetched'], { muc_domain: 'muc.example.org', locked_muc_domain: true }, | ||
async function (_converse) { | ||
const modal = await mock.openAddMUCModal(_converse); | ||
|
@@ -104,7 +99,7 @@ describe('The "Groupchats" Add modal', function () { | |
}) | ||
); | ||
|
||
fit("lets you create a MUC with only the name", | ||
it("lets you create a MUC with only the name", | ||
mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) { | ||
const { domain } = _converse; | ||
await mock.waitUntilDiscoConfirmed( | ||
|
@@ -210,6 +205,37 @@ describe('The "Groupchats" Add modal', function () { | |
}) | ||
); | ||
|
||
it("shows a validation error when only the name was specified and there's no default MUC service", | ||
mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) { | ||
const { domain } = _converse; | ||
await mock.waitUntilDiscoConfirmed( | ||
_converse, | ||
domain, | ||
[{ category: 'server', type: 'IM' }], | ||
[], | ||
); | ||
|
||
const nick = 'max'; | ||
const modal = await mock.openAddMUCModal(_converse); | ||
spyOn(_converse.ChatRoom.prototype, 'getDiscoInfo').and.callFake(() => Promise.resolve()); | ||
|
||
const name_input = modal.querySelector('input[name="chatroom"]'); | ||
name_input.value = 'The Lounge'; | ||
|
||
const nick_input = modal.querySelector('input[name="nickname"]'); | ||
nick_input.value = nick; | ||
|
||
modal.querySelector('form input[type="submit"]').click(); | ||
|
||
await u.waitUntil(() => name_input.classList.contains('error')); | ||
expect(name_input.classList.contains('is-invalid')).toBe(true); | ||
expect(modal.querySelector('.invalid-feedback')?.textContent).toBe( | ||
"No default groupchat service found. "+ | ||
"You'll need to specify the full address, for example [email protected]" | ||
); | ||
}) | ||
); | ||
|
||
it("normalizes the MUC name when creating the corresponding JID", | ||
mock.initConverse(['chatBoxesFetched'], {muc_domain: 'montague.lit'}, async function (_converse) { | ||
const modal = await mock.openAddMUCModal(_converse); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters