Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AAfghahi committed Sep 7, 2022
1 parent 393b706 commit ed55343
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,47 @@ import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import Footer from 'src/views/CRUD/data/dataset/AddDataset/Footer';

const mockedProps = {
url: 'realwebsite.com',
};

const mockPropsWithDataset = {
url: 'realwebsite.com',
datasetObject: {
database: {
id: '1',
database_name: 'examples',
},
owners: [1, 2, 3],
schema: 'public',
dataset_name: 'Untitled',
table_name: 'real_info',
},
};

describe('Footer', () => {
it('renders a blank state Footer', () => {
render(<Footer />);
it('renders a Footer with a cancel button and a disabled create button', () => {
render(<Footer {...mockedProps} />, { useRedux: true });

const saveButton = screen.getByRole('button', {
name: /Cancel/i,
});

const createButton = screen.getByRole('button', {
name: /Create/i,
});

expect(saveButton).toBeVisible();
expect(createButton).toBeDisabled();
});

it('renders a Create Dataset button when a table is selected', () => {
render(<Footer {...mockPropsWithDataset} />, { useRedux: true });

const createButton = screen.getByRole('button', {
name: /Create/i,
});

expect(screen.getByText(/footer/i)).toBeVisible();
expect(createButton).not.toBeDisabled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ import { DatasetObject } from '../types';
interface FooterObject {
url: string;
datasetObject?: Partial<DatasetObject> | null;
onDatasetAdd?: (dataset: DatasetObject) => void;
}

export default function Footer({ url, datasetObject }: FooterObject) {
export default function Footer({
url,
datasetObject,
onDatasetAdd,
}: FooterObject) {
const { createResource } = useSingleViewResource<Partial<DatasetObject>>(
'dataset',
t('dataset'),
Expand All @@ -48,6 +53,9 @@ export default function Footer({ url, datasetObject }: FooterObject) {
if (!response) {
return;
}
if (onDatasetAdd) {
onDatasetAdd({ id: response.id, ...response });
}
});
cancelButtonOnClick();
}
Expand Down

0 comments on commit ed55343

Please sign in to comment.