Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: merges TaxonomyCardMenu and TaxonomyDetailMenu #13

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 55 additions & 52 deletions src/taxonomy/export-modal/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useState } from 'react';
import { useState } from 'react';
import {
ActionRow,
Button,
Container,
Form,
ModalDialog,
} from '@edx/paragon';
Expand All @@ -24,59 +25,61 @@ const ExportModal = ({
};

return (
<ModalDialog
title={intl.formatMessage(messages.exportModalTitle)}
isOpen={isOpen}
onClose={onClose}
size="lg"
hasCloseButton
isFullscreenOnMobile
>
<ModalDialog.Header>
<ModalDialog.Title>
{intl.formatMessage(messages.exportModalTitle)}
</ModalDialog.Title>
</ModalDialog.Header>
<ModalDialog.Body className="pb-5 mt-2">
<Form.Group>
<Form.Label>
{intl.formatMessage(messages.exportModalBodyDescription)}
</Form.Label>
<Form.RadioSet
name="export-format"
value={outputFormat}
onChange={(e) => setOutputFormat(e.target.value)}
>
<Form.Radio
key={`export-csv-format-${taxonomyId}`}
value="csv"
<Container onClick={(e) => e.stopPropagation() /* This prevents calling onClick handler from the parent */}>
<ModalDialog
title={intl.formatMessage(messages.exportModalTitle)}
isOpen={isOpen}
onClose={onClose}
size="lg"
hasCloseButton
isFullscreenOnMobile
>
<ModalDialog.Header>
<ModalDialog.Title>
{intl.formatMessage(messages.exportModalTitle)}
</ModalDialog.Title>
</ModalDialog.Header>
<ModalDialog.Body className="pb-5 mt-2">
<Form.Group>
<Form.Label>
{intl.formatMessage(messages.exportModalBodyDescription)}
</Form.Label>
<Form.RadioSet
name="export-format"
value={outputFormat}
onChange={(e) => setOutputFormat(e.target.value)}
>
{intl.formatMessage(messages.taxonomyCSVFormat)}
</Form.Radio>
<Form.Radio
key={`export-json-format-${taxonomyId}`}
value="json"
<Form.Radio
key={`export-csv-format-${taxonomyId}`}
value="csv"
>
{intl.formatMessage(messages.taxonomyCSVFormat)}
</Form.Radio>
<Form.Radio
key={`export-json-format-${taxonomyId}`}
value="json"
>
{intl.formatMessage(messages.taxonomyJSONFormat)}
</Form.Radio>
</Form.RadioSet>
</Form.Group>
</ModalDialog.Body>
<ModalDialog.Footer>
<ActionRow>
<ModalDialog.CloseButton variant="tertiary">
{intl.formatMessage(messages.taxonomyModalsCancelLabel)}
</ModalDialog.CloseButton>
<Button
variant="primary"
onClick={onClickExport}
data-testid={`export-button-${taxonomyId}`}
>
{intl.formatMessage(messages.taxonomyJSONFormat)}
</Form.Radio>
</Form.RadioSet>
</Form.Group>
</ModalDialog.Body>
<ModalDialog.Footer>
<ActionRow>
<ModalDialog.CloseButton variant="tertiary">
{intl.formatMessage(messages.taxonomyModalsCancelLabel)}
</ModalDialog.CloseButton>
<Button
variant="primary"
onClick={onClickExport}
data-testid={`export-button-${taxonomyId}`}
>
{intl.formatMessage(messages.exportModalSubmitButtonLabel)}
</Button>
</ActionRow>
</ModalDialog.Footer>
</ModalDialog>
{intl.formatMessage(messages.exportModalSubmitButtonLabel)}
</Button>
</ActionRow>
</ModalDialog.Footer>
</ModalDialog>
</Container>
);
};

Expand Down
78 changes: 1 addition & 77 deletions src/taxonomy/taxonomy-card/TaxonomyCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ import React from 'react';
import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n';
import { initializeMockApp } from '@edx/frontend-platform';
import { AppProvider } from '@edx/frontend-platform/react';
import { render, fireEvent } from '@testing-library/react';
import { render } from '@testing-library/react';
import PropTypes from 'prop-types';

import initializeStore from '../../store';
import { getTaxonomyExportFile } from '../data/api';
import { importTaxonomyTags } from '../import-tags';
import TaxonomyCard from '.';

let store;
const taxonomyId = 1;

jest.mock('../import-tags', () => ({
importTaxonomyTags: jest.fn().mockResolvedValue({}),
}));

const data = {
id: taxonomyId,
name: 'Taxonomy 1',
Expand Down Expand Up @@ -92,74 +86,4 @@ describe('<TaxonomyCard />', async () => {
const { getByText } = render(<TaxonomyCardComponent original={cardData} />);
expect(getByText('Assigned to 6 orgs')).toBeInTheDocument();
});

test('should open and close menu on button click', () => {
const { getByTestId } = render(<TaxonomyCardComponent original={data} />);

// Menu closed/doesn't exist yet
expect(() => getByTestId('taxonomy-card-menu-1')).toThrow();

// Click on the menu button to open
fireEvent.click(getByTestId('taxonomy-card-menu-button-1'));

// Menu opened
expect(getByTestId('taxonomy-card-menu-1')).toBeVisible();

// Click on button again to close the menu
fireEvent.click(getByTestId('taxonomy-card-menu-button-1'));

// Menu closed
// Jest bug: toBeVisible() isn't checking opacity correctly
// expect(getByTestId('taxonomy-card-menu-1')).not.toBeVisible();
expect(getByTestId('taxonomy-card-menu-1').style.opacity).toEqual('0');

// Menu button still visible
expect(getByTestId('taxonomy-card-menu-button-1')).toBeVisible();
});

test('should open export modal on export menu click', () => {
const { getByTestId, getByText } = render(<TaxonomyCardComponent original={data} />);

// Modal closed
expect(() => getByText('Select format to export')).toThrow();

// Click on export menu
fireEvent.click(getByTestId('taxonomy-card-menu-button-1'));
fireEvent.click(getByTestId('taxonomy-card-menu-export-1'));

// Modal opened
expect(getByText('Select format to export')).toBeInTheDocument();

// Click on cancel button
fireEvent.click(getByText('Cancel'));

// Modal closed
expect(() => getByText('Select format to export')).toThrow();
});

test('should call import tags when menu click', () => {
const { getByTestId } = render(<TaxonomyCardComponent original={data} />);

// Click on import menu
fireEvent.click(getByTestId('taxonomy-card-menu-button-1'));
fireEvent.click(getByTestId('taxonomy-card-menu-import-1'));

expect(importTaxonomyTags).toHaveBeenCalled();
});

test('should export a taxonomy', () => {
const { getByTestId, getByText } = render(<TaxonomyCardComponent original={data} />);

// Click on export menu
fireEvent.click(getByTestId('taxonomy-card-menu-button-1'));
fireEvent.click(getByTestId('taxonomy-card-menu-export-1'));

// Select JSON format and click on export
fireEvent.click(getByText('JSON file'));
fireEvent.click(getByTestId('export-button-1'));

// Modal closed
expect(() => getByText('Select format to export')).toThrow();
expect(getTaxonomyExportFile).toHaveBeenCalledWith(taxonomyId, 'json');
});
});
59 changes: 0 additions & 59 deletions src/taxonomy/taxonomy-card/TaxonomyCardMenu.jsx

This file was deleted.

Loading