-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from XAlinaGS/test(ProductLifecycle)test-produ…
…ct-lifecycle test(CarbonFootprintVisualizations): write test for ProductLifecycle
- Loading branch information
Showing
2 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
.../_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { expect } from '@jest/globals'; | ||
import { ProductLifecycleStage } from 'lib/enums/ProductLifecycleStage.enum'; | ||
import { | ||
ProductLifecycle | ||
} from 'app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle'; | ||
import { CustomRenderReactIntl } from 'test-utils/CustomRenderReactIntl'; | ||
|
||
window.ResizeObserver = | ||
window.ResizeObserver || | ||
jest.fn().mockImplementation(() => ({ | ||
disconnect: jest.fn(), | ||
observe: jest.fn(), | ||
unobserve: jest.fn(), | ||
})); | ||
|
||
|
||
const completedStages = | ||
[ProductLifecycleStage.A1RawMaterialSupply, | ||
ProductLifecycleStage.A2CradleToGate, | ||
ProductLifecycleStage.A3Production, | ||
ProductLifecycleStage.A4TransportToFinalDestination | ||
] ; | ||
|
||
describe('ProductLifecycle', () => { | ||
it('should render the ProductLifecycle with all steps', async () => { | ||
CustomRenderReactIntl(<ProductLifecycle completedStages={completedStages} />); | ||
const stepper = screen.getByTestId('product-lifecycle-stepper'); | ||
expect(stepper).toBeDefined(); | ||
expect(stepper).toBeInTheDocument(); | ||
|
||
const completedSteps = screen.getAllByTestId('product-lifecycle-completed-step'); | ||
expect(completedSteps).toBeDefined(); | ||
expect(completedSteps.length).toBe(4); | ||
|
||
completedSteps.forEach((el) => { | ||
expect(el).toBeInTheDocument(); | ||
}); | ||
|
||
const nextSteps = screen.getAllByTestId('product-lifecycle-next-step'); | ||
expect(nextSteps).toBeDefined(); | ||
expect(nextSteps.length).toBe(1); | ||
}); | ||
|
||
it('should render no completed steps if none are completed', async () => { | ||
CustomRenderReactIntl(<ProductLifecycle completedStages={[]} />); | ||
const stepper = screen.getByTestId('product-lifecycle-stepper'); | ||
expect(stepper).toBeDefined(); | ||
expect(stepper).toBeInTheDocument(); | ||
|
||
const completedSteps= screen.queryByTestId('product-lifecycle-completed-step') | ||
expect(completedSteps).toBeNull(); | ||
|
||
const addressList = screen.getAllByTestId('product-lifecycle-next-step'); | ||
expect(addressList).toBeDefined(); | ||
expect(addressList.length).toBe(1); | ||
}); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters