@@ -13,6 +13,100 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
jest.mock('./TemplateCard', () => ({ TemplateCard: jest.fn(() => null) }));
|
||||
|
||||
import React from 'react';
|
||||
import { TemplateGroup } from './TemplateGroup';
|
||||
import { render } from '@testing-library/react';
|
||||
import { TemplateCard } from './TemplateCard';
|
||||
import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
|
||||
|
||||
describe('TemplateGroup', () => {
|
||||
// this is where we are at now
|
||||
it('should return a message when no templates are passed in', async () => {
|
||||
const { getByText } = render(<TemplateGroup title="Test" templates={[]} />);
|
||||
|
||||
expect(
|
||||
getByText(/No templates found that match your filter/),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render a card for each template with the template being passed as a prop', () => {
|
||||
const mockTemplates: TemplateEntityV1beta3[] = [
|
||||
{
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
kind: 'Template',
|
||||
metadata: { name: 'test' },
|
||||
spec: {
|
||||
parameters: [],
|
||||
steps: [],
|
||||
type: 'website',
|
||||
},
|
||||
},
|
||||
{
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
kind: 'Template',
|
||||
metadata: { name: 'test2' },
|
||||
spec: {
|
||||
parameters: [],
|
||||
steps: [],
|
||||
type: 'service',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
render(<TemplateGroup title="Test" templates={mockTemplates} />);
|
||||
|
||||
expect(TemplateCard).toHaveBeenCalledTimes(2);
|
||||
|
||||
for (const template of mockTemplates) {
|
||||
expect(TemplateCard).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ template }),
|
||||
{},
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('should use the passed in TemplateCard prop to render the template card', () => {
|
||||
const mockTemplateCardComponent = jest.fn(() => null);
|
||||
|
||||
const mockTemplates: TemplateEntityV1beta3[] = [
|
||||
{
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
kind: 'Template',
|
||||
metadata: { name: 'test' },
|
||||
spec: {
|
||||
parameters: [],
|
||||
steps: [],
|
||||
type: 'website',
|
||||
},
|
||||
},
|
||||
{
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
kind: 'Template',
|
||||
metadata: { name: 'test2' },
|
||||
spec: {
|
||||
parameters: [],
|
||||
steps: [],
|
||||
type: 'service',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
render(
|
||||
<TemplateGroup
|
||||
title="Test"
|
||||
templates={mockTemplates}
|
||||
components={{ CardComponent: mockTemplateCardComponent }}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(mockTemplateCardComponent).toHaveBeenCalledTimes(2);
|
||||
|
||||
for (const template of mockTemplates) {
|
||||
expect(mockTemplateCardComponent).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ template }),
|
||||
{},
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user