Files
overleaf-cep/services/web/test/frontend/features/settings-modal/settings/root-document-setting.test.tsx
Davinder Singh f27c99ea4b Tearing down of old Editor (File tree) (#31784)
* merging ide-redesign/components/file-tree into features/file-tree

* moving ide-redesign/contexts/settings-modal-context   to features/settings/contexts

* use-collapsible-file-tree.tsx → features/file-tree/hooks

* use-focus-on-setting.tsx → features/settings/hooks

* use-project-notification-preferences.ts → features/settings/hooks

* use-rail-overflow.tsx→ features/ide-react/hooks

* deleting use-switch-enable-new-editor-state.ts

* use-toolbar-menu-editor-commands.tsx → features/source-editor/hooks

* npm run extract-translations

* modifying the test to target correct buttons and removing a test for old component

* adding a test back and modifying it

* changing the test

GitOrigin-RevId: baa1e9a992c88b84313eea82161354d4958cf1ef
2026-03-06 09:14:01 +00:00

92 lines
2.4 KiB
TypeScript

import { screen, within, render } from '@testing-library/react'
import { expect } from 'chai'
import fetchMock from 'fetch-mock'
import { Folder } from '../../../../../types/folder'
import { SettingsModalProvider } from '@/features/settings/context/settings-modal-context'
import {
EditorProviders,
projectDefaults,
} from '../../../helpers/editor-providers'
import RootDocumentSetting from '@/features/settings/components/compiler-settings/root-document-setting'
import userEvent from '@testing-library/user-event'
const OPTIONS = [
{
label: 'main.tex',
value: '123abc',
},
{
label: 'another.tex',
value: '123abcd',
},
]
describe('<RootDocumentSetting />', function () {
const rootFolder: Folder = {
_id: 'root-folder-id',
name: 'rootFolder',
docs: [
{
_id: '123abc',
name: 'main.tex',
},
{
_id: '123abcd',
name: 'another.tex',
},
],
fileRefs: [],
folders: [],
}
let originalSettings: typeof window.metaAttributesCache
beforeEach(function () {
originalSettings = window.metaAttributesCache.get('ol-ExposedSettings')
window.metaAttributesCache.set('ol-ExposedSettings', {
validRootDocExtensions: ['tex'],
})
})
afterEach(function () {
fetchMock.removeRoutes().clearHistory()
window.metaAttributesCache.set('ol-ExposedSettings', originalSettings)
})
it('each option is shown and can be selected', async function () {
render(
<EditorProviders rootFolder={[rootFolder as any]}>
<SettingsModalProvider>
<RootDocumentSetting />
</SettingsModalProvider>
</EditorProviders>
)
const saveSettingsMock = fetchMock.post(
`express:/project/:projectId/settings`,
{
status: 200,
},
{ delay: 0 }
)
const select = screen.getByLabelText('Main document')
// Reverse order so we test changing to each option
for (const option of OPTIONS.reverse()) {
const optionElement = within(select).getByText(option.label)
expect(optionElement.getAttribute('value')).to.equal(option.value)
await userEvent.selectOptions(select, [optionElement])
expect(
saveSettingsMock.callHistory.called(
`/project/${projectDefaults._id}/settings`,
{
body: { rootDocId: option.value },
}
)
).to.be.true
}
})
})