Add test notification tool (#28334)
* Add test notification tool * Add frontend styles * Remove option from admin view * Refactor create post and add translations * Fix several CI errors * Fix API and frontend snapshots * Refactor trailing and leading icon on buttons * Add different button states * i18n-extract * Fix wrong text * Add tests * Fix wrong string * Fix test * feat: E2E send test notifications (#28371) * Refactor send desktop notification * Address rest of the feedback * Fix tests * Add correct link * Fix test --------- Co-authored-by: Mattermost Build <build@mattermost.com> Co-authored-by: yasserfaraazkhan <attitude3cena.yf@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
30a6ddc995
Коммит
118d0346ee
@@ -0,0 +1,128 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
// ***************************************************************
|
||||
// - [#] indicates a test step (e.g. # Go to a page)
|
||||
// - [*] indicates an assertion (e.g. * Check the title)
|
||||
// - Use element ID when selecting an element. Create one if none.
|
||||
// ***************************************************************
|
||||
|
||||
// Stage: @prod
|
||||
// Group: @channels @notification
|
||||
|
||||
describe('Verify users can receive notification on browser', () => {
|
||||
let offTopic: string;
|
||||
const notificationMessage = 'If you received this test notification, it worked!';
|
||||
before(() => {
|
||||
cy.apiInitSetup({userPrefix: 'other', loginAfter: true}).then(({offTopicUrl}) => {
|
||||
offTopic = offTopicUrl;
|
||||
});
|
||||
});
|
||||
|
||||
it('MM-T5631_1 should be able to receive notification when notifications are enabled on the browser', () => {
|
||||
cy.visit(offTopic);
|
||||
cy.stubNotificationPermission('granted');
|
||||
cy.get('#CustomizeYourExperienceTour > button').click();
|
||||
triggertestNotification();
|
||||
cy.get('@notificationStub').should('be.called');
|
||||
cy.get('@notificationStub').should((stub) => {
|
||||
expect(stub).to.have.been.calledWithMatch(
|
||||
'Direct Message',
|
||||
Cypress.sinon.match({
|
||||
body: '@@system-bot: If you received this test notification, it worked!',
|
||||
tag: '@@system-bot: If you received this test notification, it worked!',
|
||||
requireInteraction: false,
|
||||
silent: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
cy.get('#accountSettingsHeader button.close').click();
|
||||
|
||||
// * Verify user still recieves a message from system bot
|
||||
cy.verifySystemBotMessageRecieved(notificationMessage);
|
||||
});
|
||||
|
||||
it('MM-T5631_2 should not be able to receive notification when notifications are denied on the browser', () => {
|
||||
cy.visit(offTopic);
|
||||
cy.stubNotificationPermission('denied');
|
||||
cy.get('#CustomizeYourExperienceTour > button').click();
|
||||
triggertestNotification();
|
||||
|
||||
// * Assert that the Notification constructor was not called
|
||||
cy.get('@notificationStub').should('not.be.called');
|
||||
cy.get('#accountSettingsHeader button.close').click();
|
||||
|
||||
// * Verify user still recieves a message from system bot
|
||||
cy.verifySystemBotMessageRecieved(notificationMessage);
|
||||
});
|
||||
|
||||
it('MM-T5631_3 should not trigger notification when permission is default (no decision made)', () => {
|
||||
cy.visit(offTopic);
|
||||
cy.stubNotificationPermission('default');
|
||||
cy.get('#CustomizeYourExperienceTour > button').click();
|
||||
triggertestNotification();
|
||||
|
||||
// * Assert that the Notification constructor was not called
|
||||
cy.get('@notificationStub').should('not.be.called');
|
||||
cy.get('#accountSettingsHeader button.close').click();
|
||||
|
||||
// * Verify user still recieves a message from system bot
|
||||
cy.verifySystemBotMessageRecieved(notificationMessage);
|
||||
});
|
||||
|
||||
// Simulating macOS Focus Mode by suppressing the Notification constructor entirely
|
||||
it('MM-T5631_4 should not show notification when Focus Mode is enabled (simulating no notification pop-up)', () => {
|
||||
cy.visit(offTopic);
|
||||
cy.stubNotificationPermission('granted');
|
||||
|
||||
cy.window().then((win) => {
|
||||
win.Notification = function() {
|
||||
// Do nothing to simulate Focus Mode
|
||||
};
|
||||
|
||||
cy.stub(win, 'Notification').as('notificationStub').callsFake(() => {
|
||||
return null; // Prevent the notification from being created
|
||||
});
|
||||
});
|
||||
cy.get('#CustomizeYourExperienceTour > button').click();
|
||||
triggertestNotification();
|
||||
|
||||
// * Assert that the Notification constructor was not called in Focus Mode
|
||||
cy.get('@notificationStub').should('not.be.called');
|
||||
cy.get('#accountSettingsHeader button.close').click();
|
||||
|
||||
// * Verify user still recieves a message from system bot
|
||||
cy.verifySystemBotMessageRecieved(notificationMessage);
|
||||
});
|
||||
|
||||
it('should still recieve a test notification when user has set Global and Channel Notification preference to Nothing', () => {
|
||||
cy.visit(offTopic);
|
||||
cy.stubNotificationPermission('default');
|
||||
|
||||
// # Mute Channel
|
||||
cy.get('#channelHeaderTitle > span').click();
|
||||
cy.get('#channelToggleMuteChannel').should('have.text', 'Mute Channel').click();
|
||||
cy.get('#toggleMute').should('be.visible');
|
||||
|
||||
// # Set Desktop Notification preference to Nothing
|
||||
cy.get('#CustomizeYourExperienceTour > button').click();
|
||||
cy.get('#desktopAndMobileTitle').click();
|
||||
cy.get('#sendDesktopNotificationsSection input[type=radio]').last().check();
|
||||
cy.get('#saveSetting').click();
|
||||
cy.wait(500);
|
||||
triggertestNotification();
|
||||
|
||||
// * Assert that the Notification constructor was not called
|
||||
cy.get('@notificationStub').should('not.be.called');
|
||||
cy.get('#accountSettingsHeader button.close').click();
|
||||
|
||||
// * Verify user still recieves a message from system bot
|
||||
cy.verifySystemBotMessageRecieved(notificationMessage);
|
||||
});
|
||||
});
|
||||
|
||||
function triggertestNotification() {
|
||||
cy.get('.sectionNoticeContent').scrollIntoView().should('be.visible');
|
||||
cy.get('.btn-tertiary').should('be.visible').should('have.text', 'Troubleshooting docs');
|
||||
cy.get('.btn-primary').should('be.visible').should('have.text', 'Send a test notification').click();
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import './fetch_commands';
|
||||
import './keycloak_commands';
|
||||
import './ldap_commands';
|
||||
import './ldap_server_commands';
|
||||
import './notification_commands';
|
||||
import './okta_commands';
|
||||
import './saml_commands';
|
||||
import './shell';
|
||||
|
||||
38
e2e-tests/cypress/tests/support/notification_commands.ts
Обычный файл
38
e2e-tests/cypress/tests/support/notification_commands.ts
Обычный файл
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import * as TIMEOUTS from '../fixtures/timeouts';
|
||||
|
||||
/**
|
||||
* permission can be 'granted', 'denied', or 'default'
|
||||
*/
|
||||
function stubNotificationPermission(permission: string) {
|
||||
cy.window().then((win) => {
|
||||
cy.stub(win.Notification, 'permission').value(permission);
|
||||
cy.stub(win.Notification, 'requestPermission').resolves(permission);
|
||||
cy.stub(win, 'Notification').as('notificationStub').callsFake(() => {
|
||||
return {
|
||||
onclick: cy.stub().as('notificationOnClick'),
|
||||
onerror: cy.stub().as('notificationOnError'),
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the system bot message was received
|
||||
*/
|
||||
function notificationMessage(notificationMessage: string) {
|
||||
// * Assert the unread count is correct
|
||||
cy.get('.SidebarLink:contains(system-bot)').find('#unreadMentions').as('unreadCount').should('be.visible').should('have.text', '1');
|
||||
cy.get('.SidebarLink:contains(system-bot)').find('.Avatar').should('exist').click().wait(TIMEOUTS.HALF_SEC);
|
||||
cy.get('@unreadCount').should('not.exist');
|
||||
|
||||
// * Assert the notification message
|
||||
cy.getLastPostId().then((postId) => {
|
||||
cy.get(`#postMessageText_${postId}`).scrollIntoView().should('be.visible').should('have.text', notificationMessage);
|
||||
});
|
||||
}
|
||||
|
||||
Cypress.Commands.add('stubNotificationPermission', stubNotificationPermission);
|
||||
Cypress.Commands.add('verifySystemBotMessageRecieved', notificationMessage);
|
||||
Ссылка в новой задаче
Block a user