Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('orders accounts by date promoted', async () => {
AccountService.fetchAdminAccounts = jest
.fn()
.mockResolvedValueOnce(MOCK_ADMINS)
const page = renderPage()
await accountsTestUtils.waitForAccountsToLoad(page)
// Order ascending
const table = page.getByTestId(AccountsTable.ACCOUNTS_TABLE_TESTID)
const dateRegisteredHeader = rtl.getByText(table, 'Date promoted')
rtl.fireEvent.click(dateRegisteredHeader)
// Check that first page is correct
_(MOCK_ADMINS)
.orderBy(['DatePromoted'], ['asc'])
.take(AccountsTable.DEFAULT_PAGE_SIZE)
.forEach(({ EmailAddress }) =>
accountsTestUtils.expectEmailIn(EmailAddress, table),
)
})
// need to set extensionUses to zero so that the delete button is enabled
const comp = (
);
const { getAllByRole, getByText, queryByRole } = render(comp);
const deleteButton = getByText(deleteLabel);
expect(deleteButton).not.toHaveAttribute('disabled'); // delete should be enabled
// click the delete button so that the delete confirmation dialog opens
fireEvent.click(deleteButton);
// click the confirmation dialog cancel button and make sure dialog disappears
const dialog = getAllByRole('dialog')[0];
fireEvent.click(getDialogButton(dialog, cancelLabel));
await wait(() => expect(queryByRole('dialog')).toBeNull());
});
});
// need to set extensionUses to zero so that the delete button is enabled
const comp = (
);
const { getAllByRole, getByText, queryByRole } = render(comp);
const deleteButton = getByText(deleteText);
expect(deleteButton).not.toHaveAttribute('disabled'); // delete should be enabled
// click the delete button so that the delete confirmation dialog opens
fireEvent.click(deleteButton);
// click the confirmation dialog cancel button and make sure dialog disappears
const dialog = getAllByRole('dialog')[0];
fireEvent.click(getDialogButton(dialog, cancelText));
await wait(() => expect(queryByRole('dialog')).toBeNull());
});
});
addButtonLabel: ADD_TAG_BUTTON,
searchPlaceholder: SEARCH_PLACEHOLDER,
}}
addable
creatable
/>
);
// ACT
fireEvent.click(getByText(ADD_TAG_BUTTON));
fireEvent.change(getByPlaceholderText(SEARCH_PLACEHOLDER), { target: { value: tagOne.name.slice(0, -1) } });
fireEvent.click(getByText(CREATE_TAG_BUTTON));
// ASSERT
const dropdown = getByTestId(DROPDOWN_TESTID);
const foundTag = globalGetByText(dropdown, tagOne.name);
expect(onCreate).toHaveBeenCalled();
expect(foundTag).toBeTruthy();
});
it('promotes an account', async () => {
const targetAccountEmail = '2@example.com'
const targetAccountUserId = 'userId2'
AccountService.fetchRegisteredAccounts = jest
.fn()
.mockResolvedValueOnce(MOCK_ACCOUNTS)
AccountService.promoteAccountByUserId = jest
.fn()
.mockResolvedValueOnce(undefined)
const page = renderPage()
await accountsTestUtils.waitForAccountsToLoad(page)
const table = page.getByTestId('accountsTable')
const targetAccountEmailCell = rtl.getByText(table, targetAccountEmail)
const promoteButton = page.getByText('Promote to Admin')
expect(promoteButton.disabled === true)
rtl.fireEvent.click(targetAccountEmailCell)
expect(promoteButton.disabled === false)
rtl.fireEvent.click(promoteButton)
const modal = rtl.getByText(document, 'Confirm promotion').closest('.modal')
const confirmPromoteButton = rtl.getByText(modal, 'Promote')
rtl.getByText(modal, targetAccountEmail)
rtl.fireEvent.click(confirmPromoteButton)
await accountsTestUtils.waitForAccountsToLoad(page)
expect(rtl.queryByText(document, 'Confirm promotion')).toBeNull()
expect(AccountService.promoteAccountByUserId.mock.calls).toHaveLength(1)
expect(AccountService.promoteAccountByUserId.mock.calls[0][0]).toEqual(
AccountService.fetchRegisteredAccounts = jest
.fn()
.mockResolvedValueOnce(MOCK_ACCOUNTS)
AccountService.deleteAccountByUserId = jest
.fn()
.mockImplementation(() => Promise.reject(new Error(errorMessage)))
const page = renderPage()
await accountsTestUtils.waitForAccountsToLoad(page)
const table = page.getByTestId('accountsTable')
const targetAccountEmailCell = rtl.getByText(table, targetAccountEmail)
const deleteButton = page.getByText('Delete')
rtl.fireEvent.click(targetAccountEmailCell)
rtl.fireEvent.click(deleteButton)
const modal = rtl.getByText(document, 'Confirm deletion').closest('.modal')
const confirmDeleteButton = rtl.getByText(modal, 'Delete')
rtl.getByText(modal, targetAccountEmail)
rtl.fireEvent.click(confirmDeleteButton)
await accountsTestUtils.waitForAccountsToLoad(page)
await rtl.wait(() =>
expect(page.getByText(/Failed to delete account/)).toBeInTheDocument(),
)
expect(rtl.getByText(table, targetAccountEmail)).toBeInTheDocument()
})
})
const table = page.getByTestId('accountsTable')
const targetAccountEmailCell = rtl.getByText(table, targetAccountEmail)
const deleteButton = page.getByText('Delete')
rtl.fireEvent.click(targetAccountEmailCell)
rtl.fireEvent.click(deleteButton)
const modal = rtl.getByText(document, 'Confirm deletion').closest('.modal')
const confirmDeleteButton = rtl.getByText(modal, 'Delete')
rtl.getByText(modal, targetAccountEmail)
rtl.fireEvent.click(confirmDeleteButton)
await accountsTestUtils.waitForAccountsToLoad(page)
await rtl.wait(() =>
expect(page.getByText(/Failed to delete account/)).toBeInTheDocument(),
)
expect(rtl.getByText(table, targetAccountEmail)).toBeInTheDocument()
})
})
const createModal = await rtl.waitForElement(() =>
rtl.getByText(document, 'Create invite').closest('.modal'),
)
.forEach(({ EmailAddress }) => rtl.getByText(table, EmailAddress))
id: '144',
is_ready_to_show: true,
language: 'fr',
mode: timedTextMode.CLOSED_CAPTIONING,
upload_state: uploadState.READY,
url: 'https://example.com/ttt/144',
video: '43',
},
]);
render(wrapInIntlProvider(wrapInRouter()));
const closedCaptions = await screen.findByText('Closed captions');
getByTextInContainer(closedCaptions.parentElement!, 'French');
const subtitles = screen.getByText('Subtitles');
getByTextInContainer(subtitles.parentElement!, 'English');
screen.getByText('Transcripts');
});