table
unknown
javascript
a month ago
9.1 kB
1
Indexable
Never
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals'; import { fireEvent, screen, waitFor } from '@testing-library/react'; import { setupServer } from 'msw/node'; import React from 'react'; import i18n from 'config/translations/i18n'; import { handlers } from 'api/microservices/admin/reason-for-non-availability/mocks'; import { renderWithProviders } from 'utils/test-utils'; import { StoreDataBuilder } from 'utils/test-utils/StoreDataBuilder'; import ReasonForNonAvailability from '.'; const preloadedState = new StoreDataBuilder().getStoreData(); const server = setupServer(handlers.getByFilter()); beforeAll(() => server.listen()); beforeEach(() => server.resetHandlers()); afterAll(() => server.close()); describe(`src/modules/NewAdministrator/catalogs/ReasonForNonAvailability`, () => { describe('WHEN render component', () => { it('THEN render title with number of registry in spanish', async () => { // Arrange i18n.changeLanguage('es'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); // Assert await waitFor(() => { expect(screen.getByText('Motivo de no disponibilidad (2)')).toBeInTheDocument(); }); }); it('THEN render title with number of registry in english', async () => { // Arrange i18n.changeLanguage('en'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); // Assert await waitFor(() => { expect(screen.getByText('Reason for Non-Availability (2)')).toBeInTheDocument(); }); }); it('THEN render title with number of registry in portuguese', async () => { // Arrange i18n.changeLanguage('pt'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); // Assert await waitFor(() => { expect(screen.getByText('Motivo de Indisponibilidade (2)')).toBeInTheDocument(); }); }); describe('WHEN render add button', () => { it('THEN render text button in spanish', () => { // Arrange i18n.changeLanguage('es'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); // Assert expect(screen.getByText('Agregar Registro')).toBeInTheDocument(); }); it('THEN render text button in english', () => { // Arrange i18n.changeLanguage('en'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); // Assert expect(screen.getByText('ADD RECORD')).toBeInTheDocument(); }); it('THEN render text button in portuguese', () => { // Arrange i18n.changeLanguage('pt'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); // Assert expect(screen.getByText('ADICIONAR REGISTRO')).toBeInTheDocument(); }); describe('WHEN click add button', () => { it('THEN show modal', async () => { // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); fireEvent.click(screen.getByTestId('add-btn-admin-catalog')); // Assert await waitFor(() => { expect(screen.getByTestId('modal-reason-for-non-availability')).toBeInTheDocument(); }); }); describe('WHEN click close button', () => { it('THEN close modal', async () => { // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); fireEvent.click(screen.getByTestId('add-btn-admin-catalog')); await waitFor(() => { expect(screen.getByTestId('cancel-btn')).toBeInTheDocument(); }); fireEvent.click(screen.getByTestId('cancel-btn')); // Assert expect(screen.queryByTestId('modal-reason-for-non-availability')).toBeNull(); }); }); }); }); describe('WHEN mouse over on refresh button', () => { it('THEN show tooltip in spanish', async () => { // Arrange i18n.changeLanguage('es'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); fireEvent.mouseOver(screen.getByTestId('refresh-btn-admin-catalog')); await waitFor(() => { expect(screen.getByText('Actualizar')).toBeInTheDocument(); }); }); it('THEN show tooltip in english', async () => { // Arrange i18n.changeLanguage('en'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); fireEvent.mouseOver(screen.getByTestId('refresh-btn-admin-catalog')); await waitFor(() => { expect(screen.getByText('Refresh')).toBeInTheDocument(); }); }); it('THEN show tooltip in portuguese', async () => { // Arrange i18n.changeLanguage('pt'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); fireEvent.mouseOver(screen.getByTestId('refresh-btn-admin-catalog')); await waitFor(() => { expect(screen.getByText('Atualizar')).toBeInTheDocument(); }); }); }); describe('WHEN render table', () => { describe('WHEN render head table', () => { it('THEN render head labels in spanish', () => { // Arrange i18n.changeLanguage('es'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); // Assert expect(screen.getByText('Motivo de no disponibilidad')).toBeInTheDocument(); expect(screen.getByText('Estatus')).toBeInTheDocument(); expect(screen.getByText('Opciones')).toBeInTheDocument(); }); it('THEN render head labels in english', () => { // Arrange i18n.changeLanguage('en'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); // Assert expect(screen.getByText('Reason for Non-Availability')).toBeInTheDocument(); expect(screen.getByText('Status')).toBeInTheDocument(); expect(screen.getByText('Options')).toBeInTheDocument(); }); it('THEN render head labels in portuguese', () => { // Arrange i18n.changeLanguage('pt'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); // Assert expect(screen.getByText('Motivo de Indisponibilidade')).toBeInTheDocument(); expect(screen.getByText('Status')).toBeInTheDocument(); expect(screen.getByText('Opções')).toBeInTheDocument(); }); }); describe('WHEN render body table', () => { describe('WHEN render data in table', () => { it('THEN render records', async () => { // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); // Assert await waitFor(() => { expect(screen.getByText('Motivo 1')).toBeInTheDocument(); expect(screen.getByText('Motivo 2')).toBeInTheDocument(); }); }); describe('WHEN moouse over on edit icon', () => { it('THEN show tooltip in spanish', async () => { // Arrange i18n.changeLanguage('es'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); fireEvent.mouseOver(screen.getByTestId('admin-catalog-edit-icon-1')); // Assert await waitFor(() => { expect(screen.getByText('Editar registro')).toBeInTheDocument(); }); }); it('THEN show tooltip in english', async () => { // Arrange i18n.changeLanguage('en'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); fireEvent.mouseOver(screen.getByTestId('admin-catalog-edit-icon-1')); // Assert await waitFor(() => { expect(screen.getByText('Edit Record')).toBeInTheDocument(); }); }); it('THEN show tooltip in portuguese', async () => { // Arrange i18n.changeLanguage('pt'); // Act renderWithProviders(<ReasonForNonAvailability />, { preloadedState }); fireEvent.mouseOver(screen.getByTestId('admin-catalog-edit-icon-1')); // Assert await waitFor(() => { expect(screen.getByText('Editar Registro')).toBeInTheDocument(); }); }); }); }); }); }); }); });
Leave a Comment