-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
70 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/editors/sharedComponents/InsertLinkModal/BlockLink/__snapshots__/index.test.jsx.snap
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,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`BlockLink Component snapshot 1`] = ` | ||
<div> | ||
<div | ||
class="link-container d-flex row p-4 rounded border border-gray-400 mx-4 mt-3" | ||
> | ||
<div | ||
class="col-10" | ||
> | ||
<p | ||
class="text-left" | ||
/> | ||
<p | ||
class="h2 w-20 title" | ||
> | ||
Some Path | ||
</p> | ||
</div> | ||
<div | ||
class="col-2" | ||
> | ||
<button | ||
class="d-flex justify-content-center align-items-center" | ||
data-testid="close-link-button" | ||
variant="tertiary" | ||
> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
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
36 changes: 8 additions & 28 deletions
36
src/editors/sharedComponents/InsertLinkModal/FilteredBlock/__snapshots__/index.test.jsx.snap
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 |
---|---|---|
@@ -1,42 +1,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`FilteredBlock Component snapshot 1`] = ` | ||
<FilteredBlock | ||
block={ | ||
Object { | ||
"blockId": "edx_block-1", | ||
"children": Array [ | ||
"block-children-1", | ||
"block-children-2", | ||
], | ||
"displayName": "Any display name", | ||
"id": "block-key", | ||
"legacyWebUrl": "http://localhost/legacy", | ||
"lmsWebUrl": "http://localhost/weburl", | ||
"path": "Path / To / Block 1", | ||
"studentViewUrl": "http://localhost/studentview", | ||
"type": "sequential", | ||
} | ||
} | ||
onBlockFilterClick={[MockFunction]} | ||
> | ||
<Button | ||
className="d-flex flex-column w-100 align-items-start p-3" | ||
<div> | ||
<button | ||
class="d-flex flex-column w-100 align-items-start p-3 btn btn-tertiary" | ||
data-testid="filter-block-item" | ||
key="filtered_block_block-key" | ||
onClick={[Function]} | ||
variant="tertiary" | ||
type="button" | ||
> | ||
<span | ||
className="h5 text-left" | ||
class="h5 text-left" | ||
> | ||
Path / To | ||
</span> | ||
<span | ||
className="h3" | ||
class="h3" | ||
> | ||
Block 1 | ||
</span> | ||
</Button> | ||
</FilteredBlock> | ||
</button> | ||
</div> | ||
`; |
63 changes: 34 additions & 29 deletions
63
src/editors/sharedComponents/InsertLinkModal/FilteredBlock/index.test.jsx
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 |
---|---|---|
@@ -1,51 +1,56 @@ | ||
import React from 'react'; | ||
import Enzyme, { mount } from 'enzyme'; | ||
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; | ||
import { render, fireEvent, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import FilterBlock from '.'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
const mockBlock = { | ||
id: 'block-key', | ||
blockId: 'edx_block-1', | ||
lmsWebUrl: 'http://localhost/weburl', | ||
legacyWebUrl: 'http://localhost/legacy', | ||
studentViewUrl: 'http://localhost/studentview', | ||
type: 'sequential', | ||
displayName: 'Any display name', | ||
path: 'Path / To / Block 1', | ||
children: ['block-children-1', 'block-children-2'], | ||
}; | ||
jest.unmock('@edx/frontend-platform/i18n'); | ||
jest.unmock('@edx/paragon'); | ||
jest.unmock('@edx/paragon/icons'); | ||
|
||
describe('FilteredBlock Component', () => { | ||
const mockOnBlockFilterClick = jest.fn(); | ||
|
||
const setup = ( | ||
block = mockBlock, | ||
onBlockFilterClick = mockOnBlockFilterClick, | ||
) => mount(<FilterBlock block={block} onBlockFilterClick={onBlockFilterClick} />); | ||
const mockBlock = { | ||
id: 'block-key', | ||
blockId: 'edx_block-1', | ||
lmsWebUrl: 'http://localhost/weburl', | ||
legacyWebUrl: 'http://localhost/legacy', | ||
studentViewUrl: 'http://localhost/studentview', | ||
type: 'sequential', | ||
displayName: 'Any display name', | ||
path: 'Path / To / Block 1', | ||
children: ['block-children-1', 'block-children-2'], | ||
}; | ||
|
||
const renderComponent = (overrideProps = {}) => render( | ||
<FilterBlock | ||
block={mockBlock} | ||
onBlockFilterClick={mockOnBlockFilterClick} | ||
{...overrideProps} | ||
/>, | ||
); | ||
|
||
test('renders without crashing', () => { | ||
const wrapper = setup(); | ||
expect(wrapper.exists()).toBeTruthy(); | ||
const { container } = renderComponent(); | ||
expect(container).toBeTruthy(); | ||
}); | ||
|
||
test('snapshot', () => { | ||
const wrapper = setup(); | ||
expect(wrapper).toMatchSnapshot(); | ||
const { container } = renderComponent(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
test('calls onBlockFilterClick when the button is clicked', () => { | ||
const wrapper = setup(); | ||
const button = wrapper.find('Button[data-testid="filter-block-item"]'); | ||
button.simulate('click'); | ||
const { getByTestId } = renderComponent(); | ||
const button = getByTestId('filter-block-item'); | ||
fireEvent.click(button); | ||
expect(mockOnBlockFilterClick).toHaveBeenCalledWith(mockBlock); | ||
}); | ||
|
||
test('displays the block title and subtitle', () => { | ||
const wrapper = setup(); | ||
expect(wrapper.find('.h5').text()).toContain('Path / To'); | ||
expect(wrapper.find('.h3').text()).toContain('Block 1'); | ||
renderComponent(); | ||
expect(screen.getByText('Path / To')).toBeInTheDocument(); | ||
expect(screen.getByText('Block 1')).toBeInTheDocument(); | ||
}); | ||
}); |