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

[Prod] Quality of life & bug fixes for the TR import #2335

Merged
merged 15 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,24 @@ commands:
esac

env_name="<< parameters.environment_name >>"

set -x
if [ ! -z "${CIRCLE_PULL_REQUEST}" ]; then
PR_NUMBER=${CIRCLE_PULL_REQUEST##*/}

# Debugging output
echo "CIRCLE_PULL_REQUEST: ${CIRCLE_PULL_REQUEST}"
echo "Extracted PR_NUMBER: ${PR_NUMBER}"

PR_TITLE=$(curl -s "${CIRCLE_PULL_REQUEST}" | sed -e :a -e "N; s/\n/ /g; ta" | grep -oP "<bdi class=\"js-issue-title markdown-title\">[^<]+</bdi>" | sed -re "s~<[^>]+>~~g")
# Debugging output
echo "Extracted PR_TITLE: ${PR_TITLE}"

if [ ! -z "${PR_TITLE}" ]; then
JIRA_URLS=$(curl -s "${CIRCLE_PULL_REQUEST}" | sed -e :a -e "N; s/\n/ /g; ta" | grep -oP "Issue[(]s[)]</h2>.*Checklists</h2>" | grep -oP "\"https[^\"]+\"" | sed -e "s~\"~~g" | grep -o "https://jira.acf.gov/browse/[A-Z0-9-]*")

# Debugging output
echo "Extracted JIRA_URLS: ${JIRA_URLS}"

MESSAGE_TEXT=":rocket: Deployment of PR <${CIRCLE_PULL_REQUEST}|${PR_NUMBER}> (${PR_TITLE}) to <${ENV_URL}|${env_name}> was successful!"
if [ ! -z "${JIRA_URLS}" ]; then
MESSAGE_TEXT="${MESSAGE_TEXT}\nJIRA URLs in the PR:\n${JIRA_URLS}"
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/pages/Admin/components/CsvImport.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useRef } from 'react';
import React, { useState, useRef, useContext } from 'react';
import parse from 'csv-parse/lib/browser';
import PropTypes from 'prop-types';
import {
Expand All @@ -12,6 +12,7 @@ import languageEncoding from 'detect-file-encoding-and-language';
import {
importCsv,
} from '../../../fetchers/Admin';
import AppLoadingContext from '../../../AppLoadingContext';

export default function CsvImport(
{
Expand All @@ -22,6 +23,7 @@ export default function CsvImport(
primaryIdColumn,
},
) {
const { setIsAppLoading, setAppLoadingText } = useContext(AppLoadingContext);
const [error, setError] = useState();
const [success, setSuccess] = useState();
const [info, setInfo] = useState();
Expand All @@ -36,6 +38,8 @@ export default function CsvImport(
const fileInputRef = useRef(null);

const importCsvFile = async () => {
setAppLoadingText('Loading...');
setIsAppLoading(true);
try {
// If errors return.
if (error) {
Expand Down Expand Up @@ -77,6 +81,7 @@ export default function CsvImport(
} finally {
// Clear file input.
setInfo('');
setIsAppLoading(false);
}
};

Expand Down
177 changes: 35 additions & 142 deletions frontend/src/pages/Admin/components/__tests__/CsvImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Router } from 'react-router';
import { createMemoryHistory } from 'history';
import userEvent from '@testing-library/user-event';
import CsvImport from '../CsvImport';
import AppLoadingContext from '../../../../AppLoadingContext';

const testCsvUrl = join('/', 'api', 'admin', 'test-csv');

Expand All @@ -34,19 +35,32 @@ describe('CsvImport', () => {
languageEncoding.mockImplementation(() => Promise.resolve({ encoding: 'utf-8' }));
});

it('displays the component', async () => {
const renderTestComponent = (
validCsvHeaders = [],
requiredCsvHeaders = [],
) => {
const history = createMemoryHistory();
render(
<Router history={history}>
<CsvImport
validCsvHeaders={[]}
requiredCsvHeaders={[]}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
<AppLoadingContext.Provider value={{
setIsAppLoading: jest.fn(),
setAppLoadingText: jest.fn(),
}}
>
<CsvImport
validCsvHeaders={validCsvHeaders}
requiredCsvHeaders={requiredCsvHeaders}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</AppLoadingContext.Provider>
</Router>,
);
};

it('displays the component', async () => {
renderTestComponent();

// Assert Displays text 'test csv import'
const csvHeader = await screen.findByRole('heading', { name: /test csv import/i });
Expand All @@ -66,18 +80,7 @@ describe('CsvImport', () => {
});

it('displays csv required error', async () => {
const history = createMemoryHistory();
render(
<Router history={history}>
<CsvImport
validCsvHeaders={[]}
requiredCsvHeaders={[]}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</Router>,
);
renderTestComponent();

// Assert by data-testid 'file-input-input'.
const fileInput = await screen.findByTestId('file-input-input');
Expand All @@ -97,18 +100,7 @@ describe('CsvImport', () => {
});

it('displays duplicate event id error', async () => {
const history = createMemoryHistory();
render(
<Router history={history}>
<CsvImport
validCsvHeaders={[]}
requiredCsvHeaders={[]}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</Router>,
);
renderTestComponent();

// Assert by data-testid 'file-input-input'.
const fileInput = await screen.findByTestId('file-input-input');
Expand All @@ -132,17 +124,9 @@ describe('CsvImport', () => {
});

it('displays missing columns error', async () => {
const history = createMemoryHistory();
render(
<Router history={history}>
<CsvImport
validCsvHeaders={[]}
requiredCsvHeaders={['Primary ID', 'Edit Title', 'Creator']}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</Router>,
renderTestComponent(
[],
['Primary ID', 'Edit Title', 'Creator'],
);

// Assert by data-testid 'file-input-input'.
Expand All @@ -168,8 +152,6 @@ describe('CsvImport', () => {
});

it('displays invalid columns', async () => {
const history = createMemoryHistory();

const validColumns = [
'Primary ID',
'Edit Title',
Expand All @@ -183,17 +165,7 @@ describe('CsvImport', () => {
'Audience',
'Overall Vision/Goal for the PD Event',
];
render(
<Router history={history}>
<CsvImport
validCsvHeaders={validColumns}
requiredCsvHeaders={['Primary ID', 'Edit Title', 'Creator']}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</Router>,
);
renderTestComponent(validColumns);

// Assert by data-testid 'file-input-input'.
const fileInput = await screen.findByTestId('file-input-input');
Expand All @@ -218,18 +190,7 @@ describe('CsvImport', () => {
});

it('ignores invalid columns', async () => {
const history = createMemoryHistory();
render(
<Router history={history}>
<CsvImport
validCsvHeaders={[]}
requiredCsvHeaders={['Primary ID', 'Edit Title', 'Creator']}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</Router>,
);
renderTestComponent([], ['Primary ID', 'Edit Title', 'Creator']);

// Assert by data-testid 'file-input-input'.
const fileInput = await screen.findByTestId('file-input-input');
Expand All @@ -248,18 +209,7 @@ describe('CsvImport', () => {
});

it('displays good import csv', async () => {
const history = createMemoryHistory();
render(
<Router history={history}>
<CsvImport
validCsvHeaders={[]}
requiredCsvHeaders={['Primary ID', 'Edit Title', 'Creator']}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</Router>,
);
renderTestComponent([], ['Primary ID', 'Edit Title', 'Creator']);

// Assert by data-testid 'file-input-input'.
const fileInput = await screen.findByTestId('file-input-input');
Expand Down Expand Up @@ -325,19 +275,7 @@ describe('CsvImport', () => {
});

it('displays optional summary results', async () => {
const history = createMemoryHistory();
render(
<Router history={history}>
<CsvImport
validCsvHeaders={[]}
requiredCsvHeaders={['Primary ID', 'Edit Title', 'Creator']}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</Router>,
);

renderTestComponent([], ['Primary ID', 'Edit Title', 'Creator']);
// Assert by data-testid 'file-input-input'.
const fileInput = await screen.findByTestId('file-input-input');
expect(fileInput).toBeVisible();
Expand Down Expand Up @@ -431,18 +369,7 @@ describe('CsvImport', () => {
});

it('displays bad import csv', async () => {
const history = createMemoryHistory();
render(
<Router history={history}>
<CsvImport
validCsvHeaders={[]}
requiredCsvHeaders={['Primary ID', 'Edit Title', 'Creator']}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</Router>,
);
renderTestComponent([], ['Primary ID', 'Edit Title', 'Creator']);

// Assert by data-testid 'file-input-input'.
const fileInput = await screen.findByTestId('file-input-input');
Expand Down Expand Up @@ -476,19 +403,7 @@ describe('CsvImport', () => {
});

it('displays error if no import file is selected', async () => {
// Render.
const history = createMemoryHistory();
render(
<Router history={history}>
<CsvImport
validCsvHeaders={[]}
requiredCsvHeaders={['Primary ID', 'Edit Title', 'Creator']}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</Router>,
);
renderTestComponent([], ['Primary ID', 'Edit Title', 'Creator']);

// Assert by data-testid 'file-input-input'.
const fileInput = await screen.findByTestId('file-input-input');
Expand Down Expand Up @@ -524,18 +439,7 @@ describe('CsvImport', () => {
fetchMock.post(testCsvUrl, { status: 200, body: { success: false, count: 0 } });

languageEncoding.mockImplementationOnce(() => Promise.resolve({ encoding: 'ansi' }));
const history = createMemoryHistory();
render(
<Router history={history}>
<CsvImport
validCsvHeaders={[]}
requiredCsvHeaders={[]}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</Router>,
);
renderTestComponent();

// Assert by data-testid 'file-input-input'.
const fileInput = await screen.findByTestId('file-input-input');
Expand Down Expand Up @@ -584,18 +488,7 @@ describe('CsvImport', () => {
languageEncoding.mockImplementationOnce(() => {
throw new Error('Exception thrown');
});
const history = createMemoryHistory();
render(
<Router history={history}>
<CsvImport
validCsvHeaders={[]}
requiredCsvHeaders={[]}
typeName="Test CSV"
apiPathName="test-csv"
primaryIdColumn="Primary ID"
/>
</Router>,
);
renderTestComponent();

// Assert by data-testid 'file-input-input'.
const fileInput = await screen.findByTestId('file-input-input');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ const EventSummary = ({ additionalData, datePickerKey }) => {
id="category-regionalOffice"
name="eventIntendedAudience"
label="Regional office/TTA"
value="regiona-office-tta"
value="regional-office-tta"
className="smart-hub--report-checkbox"
inputRef={register({ required: 'Select one' })}
/>
Expand Down
Loading