-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create module tests #1303
Merged
Merged
Create module tests #1303
Changes from 50 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
9017a64
feat(xcontrols): add skeleton (#1278)
mgg709 02f6f2d
feat(xcontrols): add store module (#1285)
AnaOstio 6534e8f
feat(xcontrols): add actions (#1288)
mgg709 b52ff8c
feat(xcontrols): add emitter (#1290)
mgg709 3844630
feat(xcontrols): add experience-controls component (#1297)
AnaOstio 39c73f6
test: test mutations
annacv 62fddd9
feat(experience-controls): tests for the experience-controls componen…
CachedaCodes 7516213
feat: add status mutations to module
annacv 00e5684
test: add fetchMock util + actions test
annacv 13a7269
test: add fetchMock util + actions test
annacv 4ebbaab
feat(xcontrols): add request mapper (#1300)
mgg709 47c23fa
test: PR comments
annacv ce7af6f
feat(xcontrols): create response mapper (#1305)
AnaOstio 67653dd
Merge branch 'feature/EMP-1944-create-config-module-xcontrols' of htt…
annacv 2fd6e72
Merge branch 'feature/EMP-1939-create-endpoint-adapter' of https://gi…
annacv 85fde5d
test: PR comments
annacv 347a135
feat(xcontrols): update the xperience-controls module with adapter (#…
AnaOstio 068146f
Merge remote-tracking branch 'origin/main' into feature/EMP-1939-crea…
CachedaCodes 53c0a4f
install missing deps for `x-types`
diegopf d9ceae5
export `PlatformExperienceControlsRequest`
diegopf 13b9d67
remove unnecessary eslint-disable comment
diegopf 2278faf
refactor `ExperienceControlsRequestMapper` comment
diegopf 5189842
use `ExperienceControlsResponse` type for experienceControlsEndpointA…
diegopf 408c798
change default endpoint for experienceControlsEndpointAdapter
diegopf 9703847
add test for experienceControlsEndpointAdapter
diegopf 173cf6d
extend experienceControlsAdapter to point to test
diegopf ccc2143
update branch
annacv feb8138
chore: update import
annacv 168dd72
skip test
diegopf 566e1f8
enable test again
diegopf 966d21f
chore: change object assign to vue set
CachedaCodes e574c4f
skip test again
CachedaCodes ef75c33
restore test
CachedaCodes 6d4246f
remove tests from svg package scripts
CachedaCodes b070a52
Merge branch 'feature/EMP-1939-create-endpoint-adapter' of https://gi…
annacv 1c0ea5e
feat: WIP update tests using Xcontrols adapter
annacv 52614e4
feat: update store Xcontrols util
annacv c8ee72f
feat: add cancelFetchAndSaveControls in the module actions & types
annacv 3f9e379
test: update tests
annacv c97e3c4
test: create XControls stub
annacv 2bc91f4
test: add & update tests
annacv a74248a
chore: rm comment
annacv 41de164
update branch
annacv 5ad9857
feat: add release tag in actions types
annacv 7fa1f35
feat: add getter test
annacv c4f36d5
Update packages/x-components/src/x-modules/experience-controls/store/…
annacv 33b80f0
Update packages/x-components/src/x-modules/experience-controls/store/…
annacv 0a6ec50
Update packages/x-components/src/x-modules/experience-controls/store/…
annacv 1ccc932
chore: PR changes
annacv 8cc9431
chore: PR changes
annacv eaf1521
Update packages/x-components/src/x-modules/experience-controls/store/…
annacv 766ffee
Update packages/x-components/src/x-modules/experience-controls/store/…
annacv c203485
chore: Rollback pnpm-lock.yaml file changes
annacv c2b8cbe
chore: fix imports
annacv 3cc085d
chore: rm mutations tests
annacv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/x-components/src/__stubs__/experience-controls-stubs.factory.ts
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,24 @@ | ||
import { ExperienceControlsResponse } from '@empathyco/x-types'; | ||
|
||
/** | ||
* Creates a an experience controls response stub. | ||
* | ||
* @returns An experience controls stub. | ||
* | ||
* @internal | ||
*/ | ||
export function getExperienceControlsStub(): ExperienceControlsResponse { | ||
return createExperienceControlsStub(); | ||
} | ||
|
||
/** | ||
* Creates an experience controls response. | ||
* | ||
* @returns An experience controls response. | ||
*/ | ||
export function createExperienceControlsStub(): ExperienceControlsResponse { | ||
return { | ||
controls: { numberOfCarousels: 10, resultsPerCarousels: 21 }, | ||
events: { ColumnsNumberProvided: 6 } | ||
}; | ||
} |
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
61 changes: 61 additions & 0 deletions
61
...onents/src/x-modules/experience-controls/components/__tests__/experience-controls.spec.ts
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,61 @@ | ||
import { mount, Wrapper } from '@vue/test-utils'; | ||
import Vue from 'vue'; | ||
import { XPlugin } from '../../../../plugins/index'; | ||
import { installNewXPlugin } from '../../../../__tests__/utils'; | ||
import { experienceControlsXModule } from '../../x-module'; | ||
import { getXComponentXModuleName, isXComponent } from '../../../../components/index'; | ||
import ExperienceControls from '../experience-controls.vue'; | ||
|
||
function renderExperienceControls(): RenderExperienceControlsApi { | ||
const [, localVue] = installNewXPlugin(); | ||
XPlugin.registerXModule(experienceControlsXModule); | ||
|
||
const wrapper = mount(ExperienceControls, { | ||
localVue | ||
}); | ||
|
||
return { | ||
wrapper | ||
}; | ||
} | ||
|
||
describe('testing experience controls component', () => { | ||
it('is an XComponent which has an XModule', () => { | ||
const { wrapper } = renderExperienceControls(); | ||
expect(isXComponent(wrapper.vm)).toEqual(true); | ||
expect(getXComponentXModuleName(wrapper.vm)).toEqual('experienceControls'); | ||
}); | ||
|
||
// eslint-disable-next-line max-len | ||
it('listens to the event ExperienceControlsEventsChanged and emits the events on the payload', () => { | ||
const { wrapper } = renderExperienceControls(); | ||
|
||
const eventsFromExperienceControls = { | ||
ExtraParamsProvided: { | ||
warehouse: 'Magrathea' | ||
}, | ||
SortChanged: 'price:desc' | ||
}; | ||
|
||
const extraParamsProvidedListener = jest.fn(); | ||
wrapper.vm.$x.on('ExtraParamsProvided').subscribe(extraParamsProvidedListener); | ||
|
||
const sortChangedListener = jest.fn(); | ||
wrapper.vm.$x.on('SortChanged').subscribe(sortChangedListener); | ||
|
||
wrapper.vm.$x.emit('ExperienceControlsEventsChanged', eventsFromExperienceControls); | ||
|
||
expect(extraParamsProvidedListener).toHaveBeenCalledTimes(1); | ||
expect(extraParamsProvidedListener).toHaveBeenCalledWith({ | ||
warehouse: 'Magrathea' | ||
}); | ||
|
||
expect(sortChangedListener).toHaveBeenCalledTimes(1); | ||
expect(sortChangedListener).toHaveBeenCalledWith('price:desc'); | ||
}); | ||
}); | ||
|
||
interface RenderExperienceControlsApi { | ||
/** The wrapper for the experience controls component. */ | ||
wrapper: Wrapper<Vue>; | ||
} |
87 changes: 87 additions & 0 deletions
87
packages/x-components/src/x-modules/experience-controls/store/__tests__/actions.spec.ts
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,87 @@ | ||
import Vuex from 'vuex'; | ||
import { createLocalVue } from '@vue/test-utils'; | ||
import { getMockedAdapter, installNewXPlugin } from '../../../../__tests__/utils'; | ||
import { getExperienceControlsStub } from '../../../../__stubs__/experience-controls-stubs.factory'; | ||
import { createExperienceControlsStore, resetExperienceControlsStateWith } from './utils'; | ||
|
||
describe('testing experience controls module actions', () => { | ||
const mockedResponse = getExperienceControlsStub(); | ||
|
||
const adapter = getMockedAdapter({ | ||
experienceControls: mockedResponse | ||
}); | ||
|
||
const localVue = createLocalVue(); | ||
localVue.config.productionTip = false; // Silent production console messages. | ||
localVue.use(Vuex); | ||
const store = createExperienceControlsStore(); | ||
annacv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
installNewXPlugin({ adapter, store }, localVue); | ||
|
||
beforeEach(() => { | ||
resetExperienceControlsStateWith(store); | ||
}); | ||
|
||
describe('fetchControls', () => { | ||
it('should return experience controls response', async () => { | ||
const experienceControls = await store.dispatch( | ||
'fetchExperienceControlsResponse', | ||
store.getters.experienceControlsRequest | ||
); | ||
expect(experienceControls).toEqual(mockedResponse); | ||
}); | ||
}); | ||
|
||
describe('fetchAndSaveControls', () => { | ||
it('should request and store controls and events in the state', async () => { | ||
const actionPromise = store.dispatch( | ||
'fetchAndSaveExperienceControlsResponse', | ||
store.getters.experienceControlsRequest | ||
); | ||
expect(store.state.status).toEqual('loading'); | ||
await actionPromise; | ||
|
||
expect(store.state.controls).toEqual(mockedResponse.controls); | ||
expect(store.state.events).toEqual(mockedResponse.events); | ||
expect(store.state.status).toEqual('success'); | ||
}); | ||
|
||
it('should cancel the previous request if it is not yet resolved', async () => { | ||
const initialExperienceControls = store.state.controls; | ||
adapter.experienceControls.mockResolvedValueOnce(mockedResponse); | ||
|
||
const firstRequest = store.dispatch( | ||
'fetchAndSaveExperienceControlsResponse', | ||
store.getters.experienceControlsRequest | ||
); | ||
const secondRequest = store.dispatch( | ||
'fetchAndSaveExperienceControlsResponse', | ||
store.getters.experienceControlsRequest | ||
); | ||
|
||
await firstRequest; | ||
expect(store.state.status).toEqual('loading'); | ||
expect(store.state.controls).toBe(initialExperienceControls); | ||
await secondRequest; | ||
expect(store.state.status).toEqual('success'); | ||
expect(store.state.controls).toEqual(mockedResponse.controls); | ||
}); | ||
}); | ||
|
||
describe('cancelFetchAndSaveControls', () => { | ||
it('should cancel the request and do not modify the stored controls', async () => { | ||
resetExperienceControlsStateWith(store, { | ||
controls: { numberOfCarousels: 20, resultsPerCarousels: 6 } | ||
}); | ||
const previousControls = store.state.controls; | ||
await Promise.all([ | ||
store.dispatch( | ||
'fetchAndSaveExperienceControlsResponse', | ||
store.getters.experienceControlsRequest | ||
), | ||
store.dispatch('cancelFetchAndSaveControls') | ||
]); | ||
expect(store.state.controls).toEqual(previousControls); | ||
expect(store.state.status).toEqual('success'); | ||
}); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/x-components/src/x-modules/experience-controls/store/__tests__/getters.spec.ts
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,26 @@ | ||
import { ExperienceControlsRequest } from '@empathyco/x-types'; | ||
import { createExperienceControlsStore, resetExperienceControlsStateWith } from './utils'; | ||
|
||
describe('testing experience controls module getters', () => { | ||
const store = createExperienceControlsStore(); | ||
annacv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
beforeEach(() => { | ||
resetExperienceControlsStateWith(store); | ||
}); | ||
|
||
describe(`request getter`, () => { | ||
it('should return a request object', () => { | ||
resetExperienceControlsStateWith(store, { | ||
params: { | ||
store: 'es' | ||
} | ||
}); | ||
|
||
expect(store.getters.experienceControlsRequest).toEqual<ExperienceControlsRequest>({ | ||
extraParams: { | ||
store: 'es' | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
packages/x-components/src/x-modules/experience-controls/store/__tests__/mutations.spec.ts
annacv marked this conversation as resolved.
Show resolved
Hide resolved
|
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,59 @@ | ||
import { Dictionary } from '@empathyco/x-utils'; | ||
import Vuex from 'vuex'; | ||
import { createLocalVue } from '@vue/test-utils'; | ||
import { XEventsTypes } from '../../../../wiring/index'; | ||
import { createExperienceControlsStore } from './utils'; | ||
|
||
describe('testing experience controls module mutations', () => { | ||
const localVue = createLocalVue(); | ||
localVue.config.productionTip = false; // Silent production console messages. | ||
localVue.use(Vuex); | ||
const store = createExperienceControlsStore(); | ||
|
||
describe('setControls', () => { | ||
it('should update the state with the new controls', () => { | ||
const controls: Dictionary<unknown> = { | ||
numberOfCarousels: 10, | ||
resultsPerCarousels: 21 | ||
}; | ||
store.commit('setControls', controls); | ||
|
||
expect(store.state.controls).toEqual<Dictionary<unknown>>({ | ||
numberOfCarousels: 10, | ||
resultsPerCarousels: 21 | ||
}); | ||
}); | ||
}); | ||
|
||
describe('setEvents', () => { | ||
it('should update the state with the new events', () => { | ||
const events: Partial<XEventsTypes> = { | ||
UserAcceptedAQuery: 'sandal', | ||
ColumnsNumberProvided: 6 | ||
}; | ||
store.commit('setEvents', events); | ||
|
||
expect(store.state.events).toEqual<Partial<XEventsTypes>>({ | ||
UserAcceptedAQuery: 'sandal', | ||
ColumnsNumberProvided: 6 | ||
}); | ||
}); | ||
}); | ||
|
||
describe('setParams', () => { | ||
it('should update the state with the new parameters', () => { | ||
const params: Dictionary<unknown> = { | ||
section: 'kids', | ||
store: 'Gijón', | ||
season: 'autum' | ||
}; | ||
store.commit('setParams', params); | ||
|
||
expect(store.state.params).toEqual<Partial<Dictionary<unknown>>>({ | ||
section: 'kids', | ||
store: 'Gijón', | ||
season: 'autum' | ||
}); | ||
}); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
packages/x-components/src/x-modules/experience-controls/store/__tests__/utils.ts
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,46 @@ | ||
import { DeepPartial } from '@empathyco/x-utils'; | ||
import { Store } from 'vuex'; | ||
import { resetStoreModuleState } from '../../../../__tests__/utils'; | ||
import { experienceControlsXStoreModule } from '../module'; | ||
import { | ||
ExperienceControlsActions, | ||
ExperienceControlsGetters, | ||
ExperienceControlsMutations, | ||
ExperienceControlsState | ||
} from '../types'; | ||
import { SafeStore } from '../../../../store/__tests__/utils'; | ||
|
||
/** | ||
* Resets the experience controls module state, optionally modifying its default values. | ||
* | ||
* @param store - Experience controls store state. | ||
* @param state - Partial experience controls store state to replace the original one. | ||
* | ||
* @internal | ||
*/ | ||
export function resetExperienceControlsStateWith( | ||
store: Store<ExperienceControlsState>, | ||
state?: DeepPartial<ExperienceControlsState> | ||
): void { | ||
resetStoreModuleState(store, experienceControlsXStoreModule.state(), state); | ||
} | ||
|
||
/** | ||
* Creates an experience controls store with the state passed as parameter. | ||
* | ||
* @param state - Partial experience controls store state to replace the original one. | ||
annacv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @returns Store - The new store created. | ||
* | ||
* @internal | ||
*/ | ||
export function createExperienceControlsStore(): Store<ExperienceControlsState> { | ||
const store: SafeStore< | ||
ExperienceControlsState, | ||
ExperienceControlsGetters, | ||
ExperienceControlsMutations, | ||
ExperienceControlsActions | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
> = new Store(experienceControlsXStoreModule as any); | ||
|
||
return store; | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 Signal not included here as it threw an error.