-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(Templates): Adding Tests for Templates Designer / Card / State (#…
…4782) * modified templates state according to tests & fixed params,conns type * commiting rest of the files * set up initial tests * divided tests into templateDesigner and templateCard * removed empty white space
- Loading branch information
1 parent
8eaf2e1
commit 453acae
Showing
11 changed files
with
283 additions
and
33 deletions.
There are no files selected for viewing
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,34 @@ | ||
import React, { PropsWithChildren } from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import type { RenderOptions } from '@testing-library/react'; | ||
import { Provider as ReduxProvider } from 'react-redux'; | ||
import type { AppStore, RootState } from '../core/state/templates/store'; | ||
import { setupStore } from '../core/state/templates/store'; | ||
import { TemplatesWrappedContext } from '../core/templates/TemplatesDesignerContext'; | ||
import { TemplatesDataProvider } from '../core/templates/TemplatesDataProvider'; | ||
|
||
// As a basic setup, import your same slice reducers | ||
|
||
// This type interface extends the default options for render from RTL, as well | ||
// as allows the user to specify other things such as initialState, templateStore. | ||
interface ExtendedRenderOptions extends Omit<RenderOptions, 'queries'> { | ||
preloadedState?: Partial<RootState>; | ||
store?: AppStore; | ||
} | ||
|
||
export function renderWithProviders(ui: React.ReactElement, extendedRenderOptions: ExtendedRenderOptions = {}) { | ||
const { | ||
preloadedState = {}, | ||
// Automatically create a templateStore instance if no templateStore was passed in | ||
store = setupStore(preloadedState), | ||
...renderOptions | ||
} = extendedRenderOptions; | ||
|
||
const Wrapper = ({ children }: PropsWithChildren) => <ReduxProvider store={store}>{children}</ReduxProvider>; | ||
|
||
// Return an object with the templateStore and all of RTL's query functions | ||
return { | ||
store, | ||
...render(ui, { wrapper: Wrapper, ...renderOptions }), | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { combineReducers, configureStore } from '@reduxjs/toolkit'; | ||
import type {} from 'redux-thunk'; | ||
import { templateSlice } from './templateSlice'; | ||
import { manifestSlice } from './manifestSlice'; | ||
import { panelSlice } from './panelSlice'; | ||
|
||
export const templateStore = configureStore({ | ||
reducer: { | ||
template: templateSlice.reducer, | ||
manifest: manifestSlice.reducer, | ||
panel: panelSlice.reducer, | ||
}, | ||
const rootReducer = combineReducers({ | ||
template: templateSlice.reducer, | ||
manifest: manifestSlice.reducer, | ||
panel: panelSlice.reducer, | ||
}); | ||
|
||
export const setupStore = (preloadedState?: Partial<RootState>) => { | ||
return configureStore({ | ||
reducer: rootReducer, | ||
preloadedState, | ||
}); | ||
}; | ||
|
||
export const templateStore = setupStore(); | ||
export const templatesPathFromState = '../../templates/samples'; | ||
export type RootState = ReturnType<typeof templateStore.getState>; | ||
export type AppDispatch = typeof templateStore.dispatch; | ||
export type RootState = ReturnType<typeof rootReducer>; | ||
export type AppStore = ReturnType<typeof setupStore>; | ||
export type AppDispatch = AppStore['dispatch']; |
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
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
110 changes: 110 additions & 0 deletions
110
libs/designer/src/lib/ui/templates/__tests__/templateCard.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,110 @@ | ||
import { describe, beforeAll, expect, it } from 'vitest'; | ||
import type { AppStore } from '../../../core/state/templates/store'; | ||
import { setupStore, type RootState } from '../../../core/state/templates/store'; | ||
import type { Template } from '@microsoft/logic-apps-shared'; | ||
import { renderWithProviders } from '../../../__test__/template-test-utils'; | ||
import { screen } from '@testing-library/react'; | ||
import { TemplateCard } from '../cards/templateCard'; | ||
|
||
describe('ui/templates/templatesDesigner', () => { | ||
let store: AppStore; | ||
let minimalStoreData: Partial<RootState>; | ||
let template1Manifest: Template.Manifest; | ||
let template2Manifest: Template.Manifest; | ||
|
||
beforeAll(() => { | ||
template1Manifest = { | ||
title: 'Template 1', | ||
description: 'Template 1 Description', | ||
skus: ['standard'], | ||
kinds: ['stateful'], | ||
artifacts: [ | ||
{ | ||
type: 'workflow', | ||
file: 'workflow.json', | ||
}, | ||
{ | ||
type: 'description', | ||
file: 'description.md', | ||
}, | ||
], | ||
connections: [ | ||
{ | ||
id: 'connection example 1', | ||
}, | ||
{ | ||
id: 'connection example 2', | ||
}, | ||
], | ||
parameters: [], | ||
}; | ||
template2Manifest = { | ||
title: 'Template 2', | ||
description: 'Template 2 Description', | ||
skus: ['standard', 'consumption'], | ||
kinds: ['stateful', 'stateless'], | ||
artifacts: [ | ||
{ | ||
type: 'workflow', | ||
file: 'workflow.json', | ||
}, | ||
{ | ||
type: 'description', | ||
file: 'description.md', | ||
}, | ||
], | ||
connections: [ | ||
{ | ||
id: 'connection example 1', | ||
}, | ||
], | ||
parameters: [], | ||
}; | ||
}); | ||
|
||
it('Renders TemplateCard and loads template state correctly on buttons click', async () => { | ||
minimalStoreData = { | ||
manifest: { | ||
availableTemplateNames: ['template1', 'template2'], | ||
availableTemplates: { | ||
template1: template1Manifest, | ||
template2: template2Manifest, | ||
}, | ||
}, | ||
}; | ||
store = setupStore(minimalStoreData); | ||
|
||
renderWithProviders(<TemplateCard templateName="template1" />, { store }); | ||
|
||
expect(screen.getByText('Create Workflow')).toBeDefined(); | ||
expect(screen.getByText('Quick View')).toBeDefined(); | ||
screen.getByText('Create Workflow').click(); | ||
expect(store.getState().template.templateName).toBe('template1'); | ||
}); | ||
|
||
it('Renders TemplateCard and Opens the right panel', async () => { | ||
minimalStoreData = { | ||
manifest: { | ||
availableTemplateNames: ['template1', 'template2'], | ||
availableTemplates: { | ||
template1: template1Manifest, | ||
template2: template2Manifest, | ||
}, | ||
}, | ||
}; | ||
store = setupStore(minimalStoreData); | ||
|
||
renderWithProviders(<TemplateCard templateName="template2" />, { store }); | ||
|
||
expect(screen.getByText('Create Workflow')).toBeDefined(); | ||
expect(screen.getByText('Quick View')).toBeDefined(); | ||
screen.getByText('Create Workflow').click(); | ||
expect(store.getState().panel.isOpen).toBe(true); | ||
expect(store.getState().panel.currentPanelView).toBe('createWorkflow'); | ||
store.dispatch({ type: 'panel/closePanel' }); | ||
expect(store.getState().panel.isOpen).toBe(false); | ||
screen.getByText('Quick View').click(); | ||
expect(store.getState().panel.isOpen).toBe(true); | ||
expect(store.getState().panel.currentPanelView).toBe('quickView'); | ||
}); | ||
}); |
84 changes: 84 additions & 0 deletions
84
libs/designer/src/lib/ui/templates/__tests__/templatesDesigner.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,84 @@ | ||
import { describe, beforeAll, expect, it } from 'vitest'; | ||
import type { AppStore } from '../../../core/state/templates/store'; | ||
import { setupStore, type RootState } from '../../../core/state/templates/store'; | ||
import type { Template } from '@microsoft/logic-apps-shared'; | ||
import { renderWithProviders } from '../../../__test__/template-test-utils'; | ||
import { TemplatesDesigner } from '../TemplatesDesigner'; | ||
import { screen } from '@testing-library/react'; | ||
|
||
describe('ui/templates/templatesDesigner', () => { | ||
let store: AppStore; | ||
let minimalStoreData: Partial<RootState>; | ||
let template1Manifest: Template.Manifest; | ||
let template2Manifest: Template.Manifest; | ||
|
||
beforeAll(() => { | ||
template1Manifest = { | ||
title: 'Template 1', | ||
description: 'Template 1 Description', | ||
skus: ['standard'], | ||
kinds: ['stateful'], | ||
artifacts: [ | ||
{ | ||
type: 'workflow', | ||
file: 'workflow.json', | ||
}, | ||
{ | ||
type: 'description', | ||
file: 'description.md', | ||
}, | ||
], | ||
connections: [ | ||
{ | ||
id: 'connection example 1', | ||
}, | ||
{ | ||
id: 'connection example 2', | ||
}, | ||
], | ||
parameters: [], | ||
}; | ||
template2Manifest = { | ||
title: 'Template 2', | ||
description: 'Template 2 Description', | ||
skus: ['standard', 'consumption'], | ||
kinds: ['stateful', 'stateless'], | ||
artifacts: [ | ||
{ | ||
type: 'workflow', | ||
file: 'workflow.json', | ||
}, | ||
{ | ||
type: 'description', | ||
file: 'description.md', | ||
}, | ||
], | ||
connections: [ | ||
{ | ||
id: 'connection example 1', | ||
}, | ||
], | ||
parameters: [], | ||
}; | ||
}); | ||
|
||
it('Fetches templates and display the title and description', async () => { | ||
minimalStoreData = { | ||
manifest: { | ||
availableTemplateNames: ['template1', 'template2'], | ||
availableTemplates: { | ||
template1: template1Manifest, | ||
template2: template2Manifest, | ||
}, | ||
}, | ||
}; | ||
store = setupStore(minimalStoreData); | ||
|
||
renderWithProviders(<TemplatesDesigner />, { store }); | ||
|
||
expect(screen.getByText(/Template 1/i)).toBeDefined(); | ||
expect(screen.getByText(/Template 1 Description/i)).toBeDefined(); | ||
expect(screen.getByText(/Template 2/i)).toBeDefined(); | ||
expect(screen.getByText(/Template 2 Description/i)).toBeDefined(); | ||
}); | ||
}); |
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...ner/src/lib/ui/templates/templateCard.tsx → ...c/lib/ui/templates/cards/templateCard.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
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
@import './templateCard.less'; | ||
@import './cards/templateCard.less'; |
Oops, something went wrong.