Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

MM-27802 Cypress test for MM-T40 (1.0) Plugin remains enabled when upgraded #6294

Merged
merged 7 commits into from
Aug 28, 2020
115 changes: 115 additions & 0 deletions e2e/cypress/integration/plugins/upgrade_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// 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.
// ***************************************************************

// Group: @system_console @plugin

/**
* Note : This test requires two demo plugin tar files under fixtures folder.
* Download version 0.1.0 from :
* https://github.com/mattermost/mattermost-plugin-demo/releases/download/v0.1.0/com.mattermost.demo-plugin-0.1.0.tar.gz
* Copy to : ./e2e/cypress/fixtures/com.mattermost.demo-plugin-0.1.0.tar.gz
*
* Download version 0.2.0 from :
* https://github.com/mattermost/mattermost-plugin-demo/releases/download/v0.2.0/com.mattermost.demo-plugin-0.2.0.tar.gz
* Copy to : ./e2e/cypress/fixtures/com.mattermost.demo-plugin-0.2.0.tar.gz
*/

import * as TIMEOUTS from '../../fixtures/timeouts';

describe('Plugin remains enabled when upgraded', () => {
const pluginIdDemo = 'com.mattermost.demo-plugin';

before(() => {
// # Initialize setup and visit town-square
cy.apiInitSetup().then(({team}) => {
cy.visit(`/${team.name}/channels/town-square`);

// #If Demo plugin is already enabled , uninstall it
cy.apiRemovePluginById(pluginIdDemo);
saturninoabril marked this conversation as resolved.
Show resolved Hide resolved
cy.visit('/admin_console/plugins/plugin_management');
cy.get('.admin-console__header', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible').and('have.text', 'Plugin Management');
});
});

after(() => {
cy.apiRemovePluginById(pluginIdDemo);
});

it('MT40 Plugin remains enabled when upgraded', () => {
// * Upload Demo plugin from the browser
const fileName1 = 'com.mattermost.demo-plugin-0.1.0.tar.gz';
const fileName2 = 'com.mattermost.demo-plugin-0.2.0.tar.gz';
const mimeType = 'application/gzip';
cy.fixture(fileName1, 'binary').
then(Cypress.Blob.binaryStringToBlob).
then((fileContent) => {
cy.get('input[type=file]').attachFile({fileContent, fileName: fileName1, mimeType});
});

cy.get('#uploadPlugin').scrollIntoView().should('be.visible').click().wait(TIMEOUTS.HALF_SEC);

// * Verify that the button shows correct text while uploading
cy.findByText('Uploading...', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible');

// * Verify that the button shows correct text and is disabled after upload
cy.findByText('Upload', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible');
cy.get('#uploadPlugin').and('be.disabled');

// # Enable demo plugin
doTaskOnPlugin(pluginIdDemo, () => {
// * Verify Demo Plugin title is shown
cy.waitUntil(() => cy.get('strong').scrollIntoView().should('be.visible').then((title) => {
return title[0].innerText === 'Demo Plugin';
}));

// # Click on Enable link
cy.findByText('Enable').click();
});

// * Verify V0.1.0 of plugin
cy.findByText(/0.1.0/).scrollIntoView().should('be.visible');

cy.get('#uploadPlugin').scrollIntoView().should('be.visible');

// # Upgrade plugin
cy.fixture(fileName2, 'binary').
then(Cypress.Blob.binaryStringToBlob).
then((fileContent) => {
cy.get('input[type=file]').attachFile({fileContent, fileName: fileName2, mimeType});
});

// * Verify that the button shows correct text while uploading
cy.get('#uploadPlugin').should('be.visible').click().wait(TIMEOUTS.HALF_SEC);

// # Confirm overwrite of plugin with same name
cy.get('#confirmModalButton').should('be.visible').click();

doTaskOnPlugin(pluginIdDemo, () => {
// * Verify plugin is running
waitForAlert('This plugin is running.');
});

// * Verify v0.2.0 of plugin
cy.findByText(/0.2.0/).scrollIntoView().should('be.visible');
});
});

function waitForAlert(message) {
cy.waitUntil(() => cy.get('.alert').scrollIntoView().should('be.visible').then((alert) => {
return alert[0].innerText === message;
}));
}

function doTaskOnPlugin(pluginId, taskCallback) {
cy.findByText(/Installed Plugins/).scrollIntoView().should('be.visible');
cy.findByTestId(pluginId).scrollIntoView().should('be.visible').within(() => {
// # Perform task
taskCallback();
});
}