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

Hide bots and apps UI when managed by Apps Framework #7850

Merged
merged 9 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
larkox committed Apr 12, 2021
commit 2363f6e7aca8a3407198dd7089eb41cb927bb506
46 changes: 46 additions & 0 deletions components/integrations/bots/bot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,52 @@ describe('components/integrations/bots/Bot', () => {
)).toEqual(false);
});

it('app bot', () => {
const bot = UtilsTestHelper.getBotMock({user_id: '1'});
const user = UtilsTestHelper.getUserMock({id: bot.user_id});
const wrapper = shallow(
<Bot
bot={bot}
user={user}
owner={undefined}
accessTokens={{}}
team={team}
actions={actions}
fromApp={true}
/>,
);

expect(wrapper.contains(bot.display_name + ' (@' + bot.username + ')')).toEqual(true);
expect(wrapper.contains(<Markdown message={bot.description}/>)).toEqual(true);
expect(wrapper.contains('Apps Framework')).toEqual(true);

// if bot managed by plugin, remove ability to edit from UI
expect(wrapper.contains(
<FormattedMessage
id='bot.manage.create_token'
defaultMessage='Create New Token'
/>,
)).toEqual(false);
expect(wrapper.contains(
<FormattedMessage
id='bots.manage.edit'
defaultMessage='Edit'
/>,
)).toEqual(false);
expect(wrapper.contains(
<FormattedMessage
id='bot.manage.disable'
defaultMessage='Disable'
/>,
)).toEqual(false);
expect(wrapper.contains(
<FormattedMessage
id='bot.manage.enable'
defaultMessage='Enable'
/>,
)).toEqual(false);
});

it('disabled bot', () => {
const bot = UtilsTestHelper.getBotMock({user_id: '1'});
bot.delete_at = 100; // disabled
Expand Down
70 changes: 69 additions & 1 deletion components/integrations/bots/bots.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('components/integrations/bots/Bots', () => {
getUser: jest.fn(),
disableBot: jest.fn(),
enableBot: jest.fn(),
getAppsBotIDs: jest.fn(),
fetchAppsBotIDs: jest.fn(),
};

it('bots', () => {
Expand Down Expand Up @@ -92,6 +92,74 @@ describe('components/integrations/bots/Bots', () => {
)).toEqual(true);
});

it('bots with bots from apps', () => {
const bot1 = TestHelper.getBotMock({user_id: '1'});
const bot2 = TestHelper.getBotMock({user_id: '2'});
const bot3 = TestHelper.getBotMock({user_id: '3'});
const bots = {
[bot1.user_id]: bot1,
[bot2.user_id]: bot2,
[bot3.user_id]: bot3,
};
const users = {
[bot1.user_id]: TestHelper.getUserMock({id: bot1.user_id}),
[bot2.user_id]: TestHelper.getUserMock({id: bot2.user_id}),
[bot3.user_id]: TestHelper.getUserMock({id: bot3.user_id}),
};

const wrapperFull = shallow(
<Bots
bots={bots}
team={team}
accessTokens={{}}
owners={{}}
users={users}
actions={actions}
appsEnabled={true}
appsBotIDs={[bot3.user_id]}
/>,
);
wrapperFull.instance().setState({loading: false});
const wrapper = shallow(<div>{(wrapperFull.instance() as Bots).bots()[0]}</div>);

expect(wrapper.find('EnabledSection').shallow().contains(
<Bot
key={bot1.user_id}
bot={bot1}
owner={undefined}
user={users[bot1.user_id]}
accessTokens={{}}
team={team}
actions={actions}
fromApp={false}
/>,
)).toEqual(true);
expect(wrapper.find('EnabledSection').shallow().contains(
<Bot
key={bot2.user_id}
bot={bot2}
owner={undefined}
user={users[bot2.user_id]}
accessTokens={{}}
team={team}
actions={actions}
fromApp={false}
/>,
)).toEqual(true);
expect(wrapper.find('EnabledSection').shallow().contains(
<Bot
key={bot3.user_id}
bot={bot3}
owner={undefined}
user={users[bot3.user_id]}
accessTokens={{}}
team={team}
actions={actions}
fromApp={true}
/>,
)).toEqual(true);
});

it('bot owner tokens', () => {
const bot1 = TestHelper.getBotMock({user_id: '1', owner_id: '1'});
const bots = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,55 @@ exports[`components/integrations/InstalledOAuthApp should match snapshot 1`] = `
</div>
`;

exports[`components/integrations/InstalledOAuthApp should match snapshot from app 1`] = `
<div
className="backstage-list__item"
>
<div
className="integration__icon integration-list__icon"
>
<img
alt="get app screenshot"
src="https://test.com/icon"
/>
</div>
<div
className="item-details"
>
<div
className="item-details__row d-flex flex-column flex-md-row justify-content-between"
>
<strong
className="item-details__name"
>
testApp
</strong>
</div>
<div
className="item-details__row"
>
<span
className="item-details__description"
>
testing
</span>
</div>
<div
className="item-details__row"
>
<span
className="item-details__creation"
>
<FormattedMessage
defaultMessage="Managed by Apps Framework"
id="installed_integrations.fromApp"
/>
</span>
</div>
</div>
</div>
`;

exports[`components/integrations/InstalledOAuthApp should match snapshot, on error 1`] = `
<div
className="backstage-list__item"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ describe('components/integrations/InstalledOAuthApp', () => {
expect(wrapper).toMatchSnapshot();
});

test('should match snapshot from app', () => {
const props = {...baseProps, team, fromApp: true};
const wrapper = shallow(
<InstalledOAuthApp {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});

test('should match snapshot, when oauthApp is without name and not trusted', () => {
const props = {...baseProps, team};
props.oauthApp.name = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,38 @@ exports[`components/integrations/InstalledOAuthApps should match snapshot 2`] =
`;

exports[`components/integrations/InstalledOAuthApps should match snapshot 3`] = `<div />`;

exports[`components/integrations/InstalledOAuthApps should match snapshot for Apps 1`] = `
<div>
<Connect(InstalledOAuthApp)
creatorName=""
fromApp={true}
key="fzcxd9wpzpbpfp8pad78xj75pr"
oauthApp={
Object {
"callback_urls": Array [
"https://test2.com/callback",
"https://test2.com/callback2",
],
"client_secret": "decxd9wpzpbpfp8pad78xj75pr",
"create_at": 1501365459984,
"creator_id": "88oybd2dwfdoxpkpw1h5kpbyco",
"description": "testing2",
"homepage": "https://test2.com",
"icon_url": "https://test2.com/icon",
"id": "fzcxd9wpzpbpfp8pad78xj75pr",
"is_trusted": true,
"name": "secondApp",
"update_at": 1501365479988,
}
}
onDelete={[Function]}
onRegenerateSecret={[MockFunction]}
team={
Object {
"name": "test",
}
}
/>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ describe('components/integrations/InstalledOAuthApps', () => {
expect(wrapper.find(BackstageList).props().addText).toBeFalsy();
});

test('should match snapshot for Apps', () => {
const newGetOAuthApps = jest.fn().mockImplementation(
() => {
return new Promise((resolve) => {
process.nextTick(() => resolve({}));
});
},
);

const props = {
...baseProps,
appsOAuthAppIDs: ['fzcxd9wpzpbpfp8pad78xj75pr'],
};

props.actions.loadOAuthAppsAndProfiles = newGetOAuthApps;
const wrapper = shallow<InstalledOAuthApps>(<InstalledOAuthApps {...props}/>);
expect(shallow(<div>{wrapper.instance().oauthApps('second')}</div>)).toMatchSnapshot(); // successful filter
});

test('should props.deleteOAuthApp on deleteOAuthApp', () => {
const newDeleteOAuthApp = jest.fn();
const props = {...baseProps};
Expand Down