123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- import moment from 'moment';
- import {Member} from 'sentry-fixture/member';
- import {MissingMembers} from 'sentry-fixture/missingMembers';
- import {Organization} from 'sentry-fixture/organization';
- import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {DEFAULT_SNOOZE_PROMPT_DAYS} from 'sentry/utils/promptIsDismissed';
- import {InviteBanner} from 'sentry/views/settings/organizationMembers/inviteBanner';
- const missingMembers = {
- integration: 'github',
- users: MissingMembers(),
- };
- const noMissingMembers = {
- integration: 'github',
- users: [],
- };
- describe('inviteBanner', function () {
- beforeEach(function () {
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/missing-members/',
- method: 'GET',
- body: [missingMembers],
- });
- MockApiClient.addMockResponse({
- url: '/prompts-activity/',
- method: 'GET',
- body: {
- dismissed_ts: undefined,
- snoozed_ts: undefined,
- },
- });
- });
- it('render banners with feature flag', async function () {
- const org = Organization({
- features: ['integrations-gh-invite'],
- githubNudgeInvite: true,
- });
- render(
- <InviteBanner
- onSendInvite={() => {}}
- organization={org}
- allowedRoles={[]}
- onModalClose={() => {}}
- />
- );
- expect(
- await screen.findByRole('heading', {
- name: 'Bring your full GitHub team on board in Sentry',
- })
- ).toBeInTheDocument();
- expect(screen.queryAllByTestId('invite-missing-member')).toHaveLength(5);
- expect(screen.getByText('See all 5 missing members')).toBeInTheDocument();
- });
- it('does not render banner if no feature flag', function () {
- const org = Organization({
- features: [],
- });
- render(
- <InviteBanner
- onSendInvite={() => {}}
- organization={org}
- allowedRoles={[]}
- onModalClose={() => {}}
- />
- );
- expect(
- screen.queryByRole('heading', {
- name: 'Bring your full GitHub team on board in Sentry',
- })
- ).not.toBeInTheDocument();
- });
- it('does not render banner if no option', function () {
- const org = Organization({
- features: ['integrations-gh-invite'],
- });
- render(
- <InviteBanner
- onSendInvite={() => {}}
- organization={org}
- allowedRoles={[]}
- onModalClose={() => {}}
- />
- );
- expect(
- screen.queryByRole('heading', {
- name: 'Bring your full GitHub team on board in Sentry',
- })
- ).not.toBeInTheDocument();
- });
- it('does not render banner if no missing members', async function () {
- const org = Organization({
- features: ['integrations-gh-invite'],
- githubNudgeInvite: true,
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/missing-members/',
- method: 'GET',
- body: [noMissingMembers],
- });
- await act(async () => {
- await render(
- <InviteBanner
- onSendInvite={() => {}}
- organization={org}
- allowedRoles={[]}
- onModalClose={() => {}}
- />
- );
- });
- expect(
- screen.queryByRole('heading', {
- name: 'Bring your full GitHub team on board in Sentry',
- })
- ).not.toBeInTheDocument();
- });
- it('does not render banner if no integration', async function () {
- const org = Organization({
- features: ['integrations-gh-invite'],
- githubNudgeInvite: true,
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/missing-members/',
- method: 'GET',
- body: [],
- });
- await act(async () => {
- await render(
- <InviteBanner
- onSendInvite={() => {}}
- organization={org}
- allowedRoles={[]}
- onModalClose={() => {}}
- />
- );
- });
- expect(
- screen.queryByRole('heading', {
- name: 'Bring your full GitHub team on board in Sentry',
- })
- ).not.toBeInTheDocument();
- });
- it('does not render banner if lacking org:write', async function () {
- const org = Organization({
- features: ['integrations-gh-invite'],
- access: [],
- githubNudgeInvite: true,
- });
- await act(async () => {
- await render(
- <InviteBanner
- onSendInvite={() => {}}
- organization={org}
- allowedRoles={[]}
- onModalClose={() => {}}
- />
- );
- });
- expect(
- screen.queryByRole('heading', {
- name: 'Bring your full GitHub team on board in Sentry',
- })
- ).not.toBeInTheDocument();
- });
- it('renders banner if snoozed_ts days is longer than threshold', async function () {
- const org = Organization({
- features: ['integrations-gh-invite'],
- githubNudgeInvite: true,
- });
- const promptResponse = {
- dismissed_ts: undefined,
- snoozed_ts: moment
- .utc()
- .subtract(DEFAULT_SNOOZE_PROMPT_DAYS + 1, 'days')
- .unix(),
- };
- MockApiClient.addMockResponse({
- url: '/prompts-activity/',
- method: 'GET',
- body: {data: promptResponse},
- });
- render(
- <InviteBanner
- onSendInvite={() => {}}
- organization={org}
- allowedRoles={[]}
- onModalClose={() => {}}
- />
- );
- expect(
- await screen.findByRole('heading', {
- name: 'Bring your full GitHub team on board in Sentry',
- })
- ).toBeInTheDocument();
- });
- it('does not render banner if snoozed_ts days is shorter than threshold', async function () {
- const org = Organization({
- features: ['integrations-gh-invite'],
- githubNudgeInvite: true,
- });
- const promptResponse = {
- dismissed_ts: undefined,
- snoozed_ts: moment
- .utc()
- .subtract(DEFAULT_SNOOZE_PROMPT_DAYS - 1, 'days')
- .unix(),
- };
- const mockPrompt = MockApiClient.addMockResponse({
- url: '/prompts-activity/',
- method: 'GET',
- body: {data: promptResponse},
- });
- await act(async () => {
- await render(
- <InviteBanner
- onSendInvite={() => {}}
- organization={org}
- allowedRoles={[]}
- onModalClose={() => {}}
- />
- );
- });
- expect(mockPrompt).toHaveBeenCalled();
- expect(
- screen.queryByRole('heading', {
- name: 'Bring your full GitHub team on board in Sentry',
- })
- ).not.toBeInTheDocument();
- });
- it('invites member from banner', async function () {
- const newMember = Member({
- id: '6',
- email: 'hello@sentry.io',
- teams: [],
- teamRoles: [],
- flags: {
- 'idp:provisioned': false,
- 'idp:role-restricted': false,
- 'member-limit:restricted': false,
- 'partnership:restricted': false,
- 'sso:invalid': false,
- 'sso:linked': true,
- },
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/missing-members/',
- method: 'GET',
- body: [
- {
- integration: 'github',
- users: MissingMembers().slice(0, 5),
- },
- ],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/members/?referrer=github_nudge_invite',
- method: 'POST',
- body: newMember,
- });
- const org = Organization({
- features: ['integrations-gh-invite'],
- githubNudgeInvite: true,
- });
- render(
- <InviteBanner
- onSendInvite={() => {}}
- organization={org}
- allowedRoles={[]}
- onModalClose={() => {}}
- />
- );
- expect(
- await screen.findByRole('heading', {
- name: 'Bring your full GitHub team on board in Sentry',
- })
- ).toBeInTheDocument();
- expect(screen.queryAllByTestId('invite-missing-member')).toHaveLength(5);
- expect(screen.getByText('See all 5 missing members')).toBeInTheDocument();
- const inviteButton = screen.queryAllByTestId('invite-missing-member')[0];
- await userEvent.click(inviteButton);
- expect(screen.queryAllByTestId('invite-missing-member')).toHaveLength(4);
- expect(screen.getByText('See all 4 missing members')).toBeInTheDocument();
- });
- });
|