Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions e2e-tests/playwright/lib/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export {initSetup, getAdminClient} from './init';
export {createRandomPost} from './post';
export {createNewTeam, createRandomTeam} from './team';
export {createNewUserProfile, createRandomUser, getDefaultAdminUser, isOutsideRemoteUserHour} from './user';
export {installAndEnablePlugin, isPluginActive, getPluginStatus} from './plugin';
//getPluginStatus
56 changes: 56 additions & 0 deletions e2e-tests/playwright/lib/src/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Client4} from '@mattermost/client';
import {PluginManifest} from '@mattermost/types/plugins';

export async function isPluginActive(client: Client4, pluginId: string): Promise<boolean> {
const plugins = await client.getPlugins();
return plugins.active.some((plugin: PluginManifest) => plugin.id === pluginId);
}

export async function getPluginStatus(
client: Client4,
pluginId: string,
): Promise<{isInstalled: boolean; isActive: boolean}> {
const plugins = await client.getPlugins();

const isActive = plugins.active.some((plugin: PluginManifest) => plugin.id === pluginId);
const isInactive = plugins.inactive.some((plugin: PluginManifest) => plugin.id === pluginId);

return {
isInstalled: isActive || isInactive,
isActive,
};
}

/**
* Installs and enables a plugin with smart status checking
* - If already active: does nothing
* - If already installed: just enables it
* - Otherwise: installs from URL, then enables
*/
export async function installAndEnablePlugin(
client: Client4,
pluginUrl: string,
pluginId: string,
force = true,
): Promise<void> {
// Check current status
const status = await getPluginStatus(client, pluginId);

// If already active, nothing to do
if (status.isActive) {
return;
}

// If already installed but not active, just enable it
if (status.isInstalled) {
await client.enablePlugin(pluginId);
return;
}

// Not installed - install from URL then enable
await client.installPluginFromUrl(pluginUrl, force);
await client.enablePlugin(pluginId);
}
6 changes: 6 additions & 0 deletions e2e-tests/playwright/lib/src/test_fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
isOutsideRemoteUserHour,
makeClient,
mergeWithOnPremServerConfig,
installAndEnablePlugin,
isPluginActive,
} from './server';
import {
toBeFocusedWithFocusVisible,
Expand Down Expand Up @@ -89,6 +91,8 @@ export class PlaywrightExtended {
readonly getAdminClient;
readonly mergeWithOnPremServerConfig;
readonly initSetup;
readonly installAndEnablePlugin;
readonly isPluginActive;

// ./test_action
readonly toBeFocusedWithFocusVisible;
Expand Down Expand Up @@ -149,6 +153,8 @@ export class PlaywrightExtended {
this.getAdminClient = getAdminClient;
this.mergeWithOnPremServerConfig = mergeWithOnPremServerConfig;
this.isOutsideRemoteUserHour = isOutsideRemoteUserHour;
this.installAndEnablePlugin = installAndEnablePlugin;
this.isPluginActive = isPluginActive;

// ./test_action
this.toBeFocusedWithFocusVisible = toBeFocusedWithFocusVisible;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {test, expect} from '@mattermost/playwright-lib';

test('should install and enable demo plugin from URL', async ({pw}) => {
// Create and navigate to channels page
const {adminClient, user} = await pw.initSetup();
const {channelsPage} = await pw.testBrowser.login(user);

await channelsPage.goto();
await channelsPage.toBeVisible();

// Enable public links before installing plugin
await adminClient.patchConfig({
FileSettings: {EnablePublicLink: true},
ServiceSettings: {
EnableOnboardingFlow: false,
EnableTutorial: false,
},
});

// Install and enable
await pw.installAndEnablePlugin(
adminClient,
'https://github.com/mattermost/mattermost-plugin-demo/releases/download/v0.10.3/mattermost-plugin-demo-v0.10.3.tar.gz',
'com.mattermost.demo-plugin',
);

// Verify it's active (API validation, no UI)
await expect
.poll(async () => {
return await pw.isPluginActive(adminClient, 'com.mattermost.demo-plugin');
})
.toBe(true);

// Optional: Get plugin details
const plugins = await adminClient.getPlugins();
const demoPlugin = plugins.active.find((p) => p.id === 'com.mattermost.demo-plugin');
expect(demoPlugin).toBeDefined();

// Dismiss overlay again if it reappeared after plugin activation
await channelsPage.page.keyboard.press('Escape');
await channelsPage.page.waitForTimeout(500);

// UI Validation: Execute slash command and verify response
await channelsPage.postMessage('/demo_plugin true');

const post = await channelsPage.getLastPost();
await post.toBeVisible();
await post.toContainText('enabled');
});
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ function PolicyDetails({
groupID={''}
alreadySelected={Object.values(channelChanges.added).map((channel) => channel.id)}
excludeTypes={['O', 'D', 'G']}
excludeGroupConstrained={true}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ describe('components/ChannelSelectorModal', () => {
const channel1: ChannelWithTeamData = Object.assign(TestHelper.getChannelWithTeamDataMock({id: 'channel-1', team_id: 'teamid1'}));
const channel2: ChannelWithTeamData = Object.assign(TestHelper.getChannelWithTeamDataMock({id: 'channel-2', team_id: 'teamid2'}));
const channel3: ChannelWithTeamData = Object.assign(TestHelper.getChannelWithTeamDataMock({id: 'channel-3', team_id: 'teamid1'}));
const groupSyncedChannel: ChannelWithTeamData = Object.assign(TestHelper.getChannelWithTeamDataMock({
id: 'channel-4',
team_id: 'teamid3',
group_constrained: true,
}));

const defaultProps = {
excludeNames: [],
Expand Down Expand Up @@ -60,4 +65,20 @@ describe('components/ChannelSelectorModal', () => {

expect(wrapper).toMatchSnapshot();
});

test('excludes group constrained channels when requested', () => {
const wrapper = shallowWithIntl(
<ChannelSelectorModal
{...defaultProps}
excludeGroupConstrained={true}
/>,
);
wrapper.setState({channels: [
channel1,
groupSyncedChannel,
]});

const options = (wrapper.find('MultiSelect').props() as any).options;
expect(options.find((channel: ChannelWithTeamData) => channel.id === groupSyncedChannel.id)).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Props = {
alreadySelected?: string[];
excludePolicyConstrained?: boolean;
excludeAccessControlPolicyEnforced?: boolean;
excludeGroupConstrained?: boolean;
excludeTeamIds?: string[];
excludeTypes?: string[];
}
Expand Down Expand Up @@ -220,6 +221,9 @@ export class ChannelSelectorModal extends React.PureComponent<Props, State> {
if (this.props.excludePolicyConstrained) {
options = options.filter((channel) => channel.policy_id === null);
}
if (this.props.excludeGroupConstrained) {
options = options.filter((channel) => !channel.group_constrained);
}
if (this.props.excludeTeamIds) {
options = options.filter((channel) => this.props.excludeTeamIds?.indexOf(channel.team_id) === -1);
}
Expand Down
Loading