Basically, the component's operation is to change the screen and click on the menu button, which has the same event mentioned in the test: somaTabsChange
However, when I run the test, it fails to change the DOM with the new elements.
Basically, this is log i get:
TestingLibraryElementError: Unable to find a label with the text of: Criar menu
Test
it('should render the menu when save a modal', async () => {
getPageManagerInfo();
nock(env.SERVICE_URL)
.persist()
.post('/modules/cards/menu', {
name: 'menus',
icon: 'menus',
})
.reply(200, {
moduleMenu: {
pages: [],
_id: '61d33fd3b922dd0011ddc024',
icon: 'menus',
name: 'menus',
__v: 0,
},
});
const history = createMemoryHistory();
history.push('/manager/module/cards');
const renderResult = render(
<Router history={history}>
<Route path="/manager/module/:id" exact>
<PageManager />
</Route>
</Router>,
);
await changeTabs(renderResult, 'menus', 'menus');
await callModalForm({
render: renderResult,
buttonLabel: 'Criar menu',
buttonConfirmLabel: 'Salvar',
events: async () => {
await changeInput(renderResult, 'Nome', 'menus');
await changeInput(renderResult, 'Ícone', 'menus');
},
});
await callButton(renderResult, 'Fechar modal');
});
Component
import React, { useEffect, useState } from 'react';
import { useParams, useHistory } from 'react-router-dom';
import { SomaTab } from '@soma/react';
import { getModule } from 'services/ModuleService';
import Module from 'models/ModuleV2';
import LoaderFull from 'components/LoaderFull';
import ListPages from './container/ListPages';
import ListMenus from './container/ListMenus';
import { StyledTabs } from './styles';
const PageManager: React.FC = () => {
const history = useHistory();
const { id } = useParams<{ id: string }>();
const [loading, setLoading] = useState(true);
const [module, setModule] = useState<Module>();
const [tab, setTab] = React.useState<string>('pages');
const getData = async (): Promise<void> => {
const result = await getModule(id);
if (result.data) {
setModule(result.data);
} else {
history.push('/404');
}
setLoading(false);
};
useEffect(() => {
getData();
}, []);
if (loading) {
return <LoaderFull />;
}
return (
<>
<StyledTabs value={tab} onSomaTabsChange={e => setTab(e.detail)}>
<SomaTab value="pages">Páginas</SomaTab>
<SomaTab aria-label="menus" value="menus">
menus
</SomaTab>
</StyledTabs>
{tab === 'pages' ? (
<ListPages module={module!} onUpdate={getData} />
) : (
<ListMenus module={module!} onUpdate={getData} />
)}
</>
);
};
export default PageManager;