-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add copy to clipboard feature to library authoring
- Loading branch information
Showing
4 changed files
with
153 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React from 'react'; | ||
import { AppProvider } from '@edx/frontend-platform/react'; | ||
import { initializeMockApp } from '@edx/frontend-platform'; | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import { render, fireEvent, screen } from '@testing-library/react'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import type { Store } from 'redux'; | ||
|
||
import { ToastProvider } from '../../generic/toast-context'; | ||
import { ContentHit } from '../../search-manager'; | ||
import initializeStore from '../../store'; | ||
import ComponentCard from './ComponentCard'; | ||
|
||
let store: Store; | ||
let axiosMock: MockAdapter; | ||
|
||
const contentHit: ContentHit = { | ||
id: '1', | ||
usageKey: 'lb:org1:demolib:html:a1fa8bdd-dc67-4976-9bf5-0ea75a9bca3d', | ||
type: 'library_block', | ||
blockId: 'a1fa8bdd-dc67-4976-9bf5-0ea75a9bca3d', | ||
contextKey: 'lb:org1:Demo_Course', | ||
org: 'org1', | ||
breadcrumbs: [{ displayName: 'Demo Lib' }], | ||
displayName: 'Text Display Name', | ||
formatted: { | ||
displayName: 'Text Display Formated Name', | ||
content: { | ||
htmlContent: 'This is a text: ID=1', | ||
}, | ||
}, | ||
tags: { | ||
level0: ['1', '2', '3'], | ||
}, | ||
blockType: 'text', | ||
created: 1722434322294, | ||
modified: 1722434322294, | ||
lastPublished: null, | ||
}; | ||
|
||
const RootWrapper = () => ( | ||
<AppProvider store={store}> | ||
<ComponentCard | ||
contentHit={contentHit} | ||
blockTypeDisplayName="text" | ||
/> | ||
</AppProvider> | ||
); | ||
|
||
describe('<ComponentCard />', () => { | ||
beforeEach(() => { | ||
initializeMockApp({ | ||
authenticatedUser: { | ||
userId: 3, | ||
username: 'abc123', | ||
administrator: true, | ||
roles: [], | ||
}, | ||
}); | ||
store = initializeStore(); | ||
|
||
axiosMock = new MockAdapter(getAuthenticatedHttpClient()); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should render the card with title and description', () => { | ||
const { getByText } = render(<RootWrapper />); | ||
|
||
expect(getByText('Text Display Formated Name')).toBeInTheDocument(); | ||
expect(getByText('This is a text: ID=1')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call the updateClipboard function when the copy button is clicked', () => { | ||
axiosMock.onPost('/api/clipboard/').reply(200, {}); | ||
const { getByTestId } = render(<RootWrapper />); | ||
|
||
// Open menu | ||
fireEvent.click(getByTestId('component-card-menu-button')); | ||
fireEvent.click(getByTestId('test-copy')); | ||
|
||
screen.logTestingPlaygroundURL(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters