Skip to content

Commit e4cf90e

Browse files
author
Mint de Wit
committed
chore: fix tests
1 parent 50d869e commit e4cf90e

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

packages/webui/src/client/ui/RundownView/SelectedElementsContext.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,21 @@ const selectionReducer = (
116116
const defaultSelectionContext: SelectionContextType = {
117117
isSelected: () => false,
118118
listSelectedElements: () => [],
119-
clearAndSetSelection: () => {},
120-
toggleSelection: () => {},
121-
addSelection: () => {},
122-
removeSelection: () => {},
123-
clearSelections: () => {},
119+
clearAndSetSelection: () => {
120+
throw new Error('Method "clearAndSetSelection" not implemented on default SelectedElementsContext')
121+
},
122+
toggleSelection: () => {
123+
throw new Error('Method "toggleSelection" not implemented on default SelectedElementsContext')
124+
},
125+
addSelection: () => {
126+
throw new Error('Method "addSelection" not implemented on default SelectedElementsContext')
127+
},
128+
removeSelection: () => {
129+
throw new Error('Method "removeSelection" not implemented on default SelectedElementsContext')
130+
},
131+
clearSelections: () => {
132+
throw new Error('Method "clearSelections" not implemented on default SelectedElementsContext')
133+
},
124134
getSelectedCount: () => 0,
125135
}
126136

@@ -208,9 +218,9 @@ export function useSelectedElements(
208218
useEffect(() => {
209219
clearPendingChange() // element id changed so any pending change is for an old element
210220

211-
const pieceComputation = Tracker.nonreactive(() =>
221+
const computation = Tracker.nonreactive(() =>
212222
Tracker.autorun(() => {
213-
const piece = Pieces.findOne(selectedElement.elementId)
223+
const piece = Pieces.findOne(selectedElement?.elementId)
214224
const part = UIParts.findOne({ _id: piece ? piece.startPartId : selectedElement?.elementId })
215225
const segment = Segments.findOne({ _id: part ? part.segmentId : selectedElement?.elementId })
216226

@@ -220,7 +230,7 @@ export function useSelectedElements(
220230
})
221231
)
222232

223-
return () => pieceComputation.stop()
233+
return () => computation.stop()
224234
}, [selectedElement?.elementId])
225235

226236
return {

packages/webui/src/client/ui/UserEditOperations/PropertiesPanel.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ export function PropertiesPanel(): JSX.Element {
190190
<div className="propertiespanel-pop-up__footer">
191191
<button
192192
className="propertiespanel-pop-up__button start"
193-
title={selectedElement.type === 'segment' ? t('Restore Segment from NRCS') : t('Restore Part from NRCS')}
193+
title={selectedElement?.type === 'segment' ? t('Restore Segment from NRCS') : t('Restore Part from NRCS')}
194+
disabled={!selectedElement}
194195
onClick={handleRevertChanges}
195196
>
196197
<span className="svg">
@@ -202,7 +203,7 @@ export function PropertiesPanel(): JSX.Element {
202203
</svg>
203204
</span>
204205
<span className="propertiespanel-pop-up__label">
205-
{selectedElement.type === 'segment' ? t('Restore Segment from NRCS') : t('Restore Part from NRCS')}
206+
{selectedElement?.type === 'segment' ? t('Restore Segment from NRCS') : t('Restore Part from NRCS')}
206207
</span>
207208
</button>
208209

@@ -339,7 +340,7 @@ function GlobalPropertiesEditor({
339340
)
340341

341342
return (
342-
<div className="properties-grid" style={{ color: 'white' }}>
343+
<div className="properties-panel-pop-up__form styled-schema-form" style={{ color: 'white' }}>
343344
{parsedSchema ? (
344345
<SchemaFormWithState
345346
key={(schema as any as string) ?? 'key'}

packages/webui/src/client/ui/UserEditOperations/__tests__/PropertiesPanel.test.tsx

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ jest.mock('react-i18next', () => ({
3131
return {
3232
t: (str: string) => str,
3333
i18n: {
34-
changeLanguage: () => new Promise(() => {}),
34+
changeLanguage: () =>
35+
new Promise(() => {
36+
// satisfy linter - by making it uglier? ¯\_(ツ)_/¯
37+
}),
3538
},
3639
}
3740
},
3841
initReactI18next: {
3942
type: '3rdParty',
40-
init: () => {},
43+
init: () => {
44+
// satisfy linter - by making it uglier? ¯\_(ツ)_/¯
45+
},
4146
},
4247
}))
4348

@@ -164,6 +169,9 @@ jest.mock('../../../lib/meteorApi', () => ({
164169
jest.mock('../../../lib/forms/SchemaFormInPlace', () => ({
165170
SchemaFormInPlace: () => <div data-testid="schema-form">Schema Form</div>,
166171
}))
172+
jest.mock('../../../lib/forms/SchemaFormWithState', () => ({
173+
SchemaFormWithState: () => <div data-testid="schema-form">Schema Form</div>,
174+
}))
167175

168176
describe('PropertiesPanel', () => {
169177
const wrapper = ({ children }: { children: React.ReactNode }) => (
@@ -206,6 +214,18 @@ describe('PropertiesPanel', () => {
206214
svgIcon: '<svg></svg>',
207215
},
208216
],
217+
userEditProperties: {
218+
operations: [
219+
{
220+
id: 'operation1',
221+
label: { key: 'TEST_LABEL', namespaces: ['blueprint_main-showstyle'] },
222+
type: UserEditingType.ACTION,
223+
isActive: false,
224+
svgIcon: '<svg></svg>',
225+
},
226+
],
227+
translationNamespaces: ['blueprint_main-showstyle'],
228+
},
209229
isHidden: false,
210230
})
211231

@@ -230,7 +250,7 @@ describe('PropertiesPanel', () => {
230250
test('renders empty when no element selected', () => {
231251
const { container } = render(<PropertiesPanel />, { wrapper })
232252
expect(container.querySelector('.properties-panel')).toBeTruthy()
233-
expect(container.querySelector('.propertiespanel-pop-up__contents')).toBeFalsy()
253+
expect(container.querySelector('.properties-panel-pop-up__form')).toBeFalsy()
234254
})
235255

236256
test('renders segment properties when segment is selected', async () => {
@@ -308,8 +328,8 @@ describe('PropertiesPanel', () => {
308328
})
309329

310330
// Wait for the switch button to be available
311-
const { container } = renderWithContext(<PropertiesPanel />, { ctxValue: result.current })
312-
const switchButton = await waitFor(() => container.querySelector('.propertiespanel-pop-up__switchbutton'))
331+
renderWithContext(<PropertiesPanel />, { ctxValue: result.current })
332+
const switchButton = await waitFor(() => screen.getByText('TEST_LABEL'))
313333
expect(switchButton).toBeTruthy()
314334

315335
if (!switchButton) return // above would have thrown - this is a type guard
@@ -318,7 +338,7 @@ describe('PropertiesPanel', () => {
318338
await userEvent.click(switchButton)
319339

320340
// Check if commit button is enabled
321-
const commitButton = screen.getByText('COMMIT CHANGES')
341+
const commitButton = screen.getByText('Save')
322342
expect(commitButton).toBeEnabled()
323343

324344
// Commit changes
@@ -366,7 +386,7 @@ describe('PropertiesPanel', () => {
366386
})
367387

368388
// Click revert button
369-
const revertButton = screen.getByText('REVERT CHANGES')
389+
const revertButton = screen.getByText('Restore Segment from NRCS')
370390
await act(async () => {
371391
await userEvent.click(revertButton)
372392
})
@@ -381,7 +401,7 @@ describe('PropertiesPanel', () => {
381401
pieceExternalId: undefined,
382402
},
383403
{
384-
id: 'revert-segment',
404+
id: '__sofie-revert-segment',
385405
}
386406
)
387407
})
@@ -407,6 +427,7 @@ describe('PropertiesPanel', () => {
407427
await userEvent.click(closeButton!)
408428
})
409429

410-
expect(container.querySelector('.propertiespanel-pop-up__contents')).toBeFalsy()
430+
// expect(container.querySelector('.propertiespanel-pop-up__contents')).toBeFalsy()
431+
expect(container.querySelector('.properties-panel-pop-up__form')).toBeFalsy()
411432
})
412433
})

0 commit comments

Comments
 (0)