fix: active transcript preference not loading (#682)

This commit is contained in:
Kristin Aoki
2023-11-14 10:43:01 -05:00
committed by GitHub
parent 3378c8e170
commit 7c7ea1fbc2
3 changed files with 68 additions and 12 deletions

View File

@@ -37,7 +37,7 @@ const OrderTranscriptForm = ({
}, [data]);
const handleDiscard = () => {
setTranscriptType(activeTranscriptPreferences);
setTranscriptType(activeTranscriptPreferences?.provider);
closeTranscriptSettings();
};
@@ -147,7 +147,14 @@ const OrderTranscriptForm = ({
OrderTranscriptForm.propTypes = {
setTranscriptType: PropTypes.func.isRequired,
activeTranscriptPreferences: PropTypes.shape({}),
activeTranscriptPreferences: PropTypes.shape({
provider: PropTypes.string.isRequired,
cielo24Turnaround: PropTypes.string,
cielo24Fidelity: PropTypes.string,
preferredLanguages: PropTypes.arrayOf(PropTypes.string),
turnaround: PropTypes.string,
videoSourceLanguage: PropTypes.string,
}),
transcriptType: PropTypes.string.isRequired,
transcriptCredentials: PropTypes.shape({
cielo24: PropTypes.bool.isRequired,

View File

@@ -33,7 +33,7 @@ const TranscriptSettings = ({
videoTranscriptSettings,
} = pageSettings;
const { transcriptionPlans } = videoTranscriptSettings || {};
const [transcriptType, setTranscriptType] = useState(activeTranscriptPreferences);
const [transcriptType, setTranscriptType] = useState(activeTranscriptPreferences?.provider);
const handleOrderTranscripts = (data, provider) => {
const noCredentials = isEmpty(transcriptCredentials) || data.apiKey;

View File

@@ -3,6 +3,7 @@ import {
act,
screen,
waitFor,
within,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {
@@ -110,6 +111,45 @@ describe('TranscriptSettings', () => {
});
});
describe('loading saved preference', () => {
beforeEach(async () => {
initializeMockApp({
authenticatedUser: {
userId: 3,
username: 'abc123',
administrator: false,
roles: [],
},
});
store = initializeStore({
...initialState,
videos: {
...initialState.videos,
pageSettings: {
...initialState.videos.pageSettings,
activeTranscriptPreferences: {
provider: 'Cielo24',
cielo24Fidelity: '',
cielo24Turnaround: '',
preferredLanguages: [],
threePlayTurnaround: '',
videoSourceLanguage: '',
},
},
},
});
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
renderComponent(defaultProps);
});
it('should load page with Cielo24 selected', async () => {
const cielo24Button = screen.getByText(messages.cieloLabel.defaultMessage);
expect(within(cielo24Button).getByLabelText('Cielo24 radio')).toHaveProperty('checked', true);
});
});
describe('delete transcript preferences', () => {
beforeEach(async () => {
initializeMockApp({
@@ -120,19 +160,28 @@ describe('TranscriptSettings', () => {
roles: [],
},
});
store = initializeStore(initialState);
store = initializeStore({
...initialState,
videos: {
...initialState.videos,
pageSettings: {
...initialState.videos.pageSettings,
activeTranscriptPreferences: {
provider: 'Cielo24',
cielo24Fidelity: '',
cielo24Turnaround: '',
preferredLanguages: [],
threePlayTurnaround: '',
videoSourceLanguage: '',
},
},
},
});
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
renderComponent(defaultProps);
const orderButton = screen.getByText(messages.orderTranscriptsTitle.defaultMessage);
await act(async () => {
userEvent.click(orderButton);
});
const cielo24Button = screen.getAllByLabelText('Cielo24 radio')[0];
await act(async () => {
userEvent.click(cielo24Button);
});
const noneButton = screen.getAllByLabelText('none radio')[0];
await act(async () => {
userEvent.click(noneButton);
});