diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 02a9c12e7c..193ce1a98c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ jobs: build: runs-on: ubuntu-latest container: - image: cypress/browsers:node16.16.0-chrome105-ff104-edge + image: cypress/browsers:node-16.18.1-chrome-110.0.5481.96-1-ff-109.0-edge-110.0.1587.41-1 # https://github.com/cypress-io/github-action#firefox Cypress FF image needs this user permissions to be able to install dependencies options: --user 1001 diff --git a/packages/react-wrapper/package.json b/packages/react-wrapper/package.json index 21d6a95ae1..362b854305 100644 --- a/packages/react-wrapper/package.json +++ b/packages/react-wrapper/package.json @@ -49,7 +49,7 @@ "@types/jest": "~27.0.3", "@types/react": "~16.9.0", "@types/react-dom": "~16.9.0", - "cypress": "~12.2.0", + "cypress": "~12.8.0", "eslint-plugin-react": "~7.32.1", "jest": "~27.3.1", "react": "~16.9.0", diff --git a/packages/x-archetype-utils/package.json b/packages/x-archetype-utils/package.json index 4e394b5f69..3690f38b0f 100644 --- a/packages/x-archetype-utils/package.json +++ b/packages/x-archetype-utils/package.json @@ -36,6 +36,7 @@ }, "dependencies": { "@empathyco/x-deep-merge": "^1.3.0-alpha.33", + "tslib": "~2.4.1", "vue-i18n": "~8.28.2" }, "devDependencies": { diff --git a/packages/x-bus/src/x-bus.ts b/packages/x-bus/src/x-bus.ts index dfe101b42b..ff6f6c7617 100644 --- a/packages/x-bus/src/x-bus.ts +++ b/packages/x-bus/src/x-bus.ts @@ -230,7 +230,7 @@ export class XPriorityBus> + ? Observable, SomeEventMetadata>> : Observable> { // TODO: This type should work, but inference isn't working as expected. Check when updating ts. // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -239,7 +239,7 @@ export class XPriorityBus, + SubjectPayload, SomeEventMetadata>, EventPayload >(value => value.eventPayload) ); @@ -277,7 +277,7 @@ export class XPriorityBus(event: SomeEvent): void { this.emitters[event] = new ReplaySubject< - SubjectPayload + SubjectPayload, SomeEventMetadata> >(1); } } diff --git a/packages/x-bus/src/x-bus.types.ts b/packages/x-bus/src/x-bus.types.ts index 22206bd27b..5817ebacee 100644 --- a/packages/x-bus/src/x-bus.types.ts +++ b/packages/x-bus/src/x-bus.types.ts @@ -28,13 +28,9 @@ export type EventPayload< * * @public */ -export interface SubjectPayload< - SomeEvents extends Dictionary, - SomeEvent extends keyof SomeEvents, - SomeEventMetadata extends Dictionary -> { +export interface SubjectPayload { /** The payload of the event. */ - eventPayload: EventPayload; + eventPayload: SomePayload; /** Extra data of the event. */ metadata: SomeEventMetadata; } @@ -49,7 +45,7 @@ export type Emitter< SomeEvents extends Dictionary, SomeEvent extends keyof SomeEvents, SomeEventMetadata extends Dictionary -> = Subject>; +> = Subject, SomeEventMetadata>>; /** * Represents a dictionary where the key is an event name and its value is an {@link Emitter}. @@ -165,6 +161,6 @@ export interface XBus> + ? Observable, SomeEventMetadata>> : Observable>; } diff --git a/packages/x-components/cypress.config.ts b/packages/x-components/cypress.config.ts index 3dbb1cf729..8f911a93a1 100644 --- a/packages/x-components/cypress.config.ts +++ b/packages/x-components/cypress.config.ts @@ -27,7 +27,8 @@ export default defineConfig({ ); return config; }, - specPattern: 'tests/e2e/**/*.feature' + specPattern: 'tests/e2e/**/*.feature', + experimentalRunAllSpecs: true }, component: { specPattern: 'tests/unit/**/*.spec.ts', diff --git a/packages/x-components/package.json b/packages/x-components/package.json index dc4255cb09..741cbdecda 100644 --- a/packages/x-components/package.json +++ b/packages/x-components/package.json @@ -53,7 +53,7 @@ "lint": "eslint . --ext .ts,.vue", "test:unit": "jest --silent && pnpm run test:unit-cypress", "test:unit-jest": "jest", - "test:unit-cypress": "cypress run --component", + "test:unit-cypress": "cypress run --component --browser chrome", "test:unit-coverage": "jest --coverage", "test:unit-watch": "jest --watch", "test:e2e": "vue-cli-service test:e2e --e2e --browser chrome", @@ -69,6 +69,7 @@ "dependencies": { "@empathyco/x-adapter": "^8.0.0-alpha.26", "@empathyco/x-adapter-platform": "^1.0.0-alpha.66", + "@empathyco/x-bus": "^0.1.0-alpha.9", "@empathyco/x-deep-merge": "^1.3.0-alpha.33", "@empathyco/x-logger": "^1.2.0-alpha.10", "@empathyco/x-storage-service": "^2.0.0-alpha.10", @@ -89,7 +90,7 @@ "devDependencies": { "@badeball/cypress-cucumber-preprocessor": "~15.0.0", "@bahmutov/cypress-esbuild-preprocessor": "~2.2.0", - "@cypress/vue": "~2.2.4", + "@cypress/vue2": "~2.0.1", "@empathyco/x-tailwindcss": "^1.0.0-alpha.15", "@microsoft/api-documenter": "~7.21.3", "@microsoft/api-extractor": "~7.33.7", @@ -108,8 +109,8 @@ "@vue/vue2-jest": "~27.0.0-alpha.3", "autoprefixer": "~10.4.4", "convert-source-map": "~2.0.0", - "cypress": "~12.2.0", - "esbuild": "0.17.5", + "cypress": "~12.8.0", + "esbuild": "0.17.10", "glob": "~7.1.6", "jest": "~27.3.1", "jest-scss-transform": "~1.0.1", diff --git a/packages/x-components/src/__tests__/bus.dummy.ts b/packages/x-components/src/__tests__/bus.dummy.ts new file mode 100644 index 0000000000..d71863d126 --- /dev/null +++ b/packages/x-components/src/__tests__/bus.dummy.ts @@ -0,0 +1,24 @@ +import { Dictionary } from '@empathyco/x-utils'; +import { EmittedData, EventPayload, XPriorityBus } from '@empathyco/x-bus'; +import { WireMetadata, XEventsTypes } from '../wiring'; + +export class XDummyBus< + SomeEvents extends Dictionary = XEventsTypes, + SomeMetadata extends Dictionary = WireMetadata +> extends XPriorityBus { + emit( + event: SomeEvent, + payload?: EventPayload, + metadata = {} as SomeMetadata + ): Promise> { + const emitter = this.getEmitter(event); + const emittedPayload = { + eventPayload: payload as EventPayload, + metadata + }; + + emitter.next(emittedPayload); + + return Promise.resolve({ event, ...emittedPayload }); + } +} diff --git a/packages/x-components/src/__tests__/utils.ts b/packages/x-components/src/__tests__/utils.ts index 5721b0ec01..951245b804 100644 --- a/packages/x-components/src/__tests__/utils.ts +++ b/packages/x-components/src/__tests__/utils.ts @@ -14,7 +14,6 @@ import { SearchResponse } from '@empathyco/x-types'; import { XPluginOptions } from '../plugins'; -import { BaseXBus } from '../plugins/x-bus'; import { XPlugin } from '../plugins/x-plugin'; import { ActionsDictionary } from '../store/actions.types'; import { MutationsDictionary } from '../store/mutations.types'; @@ -22,6 +21,7 @@ import { RootXStoreState, XStoreModule } from '../store/store.types'; import { cleanGettersProxyCache } from '../store/utils/getters-proxy.utils'; import { ExtractState, XModule, XModuleName } from '../x-modules/x-modules.types'; import { XComponentsAdapterDummy } from './adapter.dummy'; +import { XDummyBus } from './bus.dummy'; import Mock = jest.Mock; export type MockedXComponentsAdapter = { @@ -190,7 +190,7 @@ export function installNewXPlugin( localVue: typeof Vue = createLocalVue() ): [XPlugin, typeof Vue] { XPlugin.resetInstance(); - const xPlugin = new XPlugin(new BaseXBus()); + const xPlugin = new XPlugin(new XDummyBus()); const installOptions: XPluginOptions = { adapter: XComponentsAdapterDummy, ...options diff --git a/packages/x-components/src/components/__tests__/global-x-bus.spec.ts b/packages/x-components/src/components/__tests__/global-x-bus.spec.ts index be6b795494..a31a6131be 100644 --- a/packages/x-components/src/components/__tests__/global-x-bus.spec.ts +++ b/packages/x-components/src/components/__tests__/global-x-bus.spec.ts @@ -28,7 +28,8 @@ describe('testing GlobalXBus component', function () { expect(acceptedAQueryCallback).toHaveBeenCalledTimes(1); expect(acceptedAQueryCallback).toHaveBeenCalledWith('lego', { location: undefined, - moduleName: null + moduleName: null, + replaceable: true }); expect(clickedColumnPickerCallback).not.toHaveBeenCalled(); diff --git a/packages/x-components/src/components/__tests__/snippet-callbacks.spec.ts b/packages/x-components/src/components/__tests__/snippet-callbacks.spec.ts index 9da23ee02a..eb4dc0e6fd 100644 --- a/packages/x-components/src/components/__tests__/snippet-callbacks.spec.ts +++ b/packages/x-components/src/components/__tests__/snippet-callbacks.spec.ts @@ -36,7 +36,8 @@ describe('testing SnippetCallbacks component', () => { expect(acceptedAQueryCallback).toHaveBeenCalledTimes(1); expect(acceptedAQueryCallback).toHaveBeenCalledWith('lego', { location: undefined, - moduleName: null + moduleName: null, + replaceable: true }); expect(clickedColumnPickerCallback).not.toHaveBeenCalled(); @@ -48,7 +49,8 @@ describe('testing SnippetCallbacks component', () => { expect(clickedColumnPickerCallback).toHaveBeenCalledTimes(1); expect(clickedColumnPickerCallback).toHaveBeenCalledWith(1, { location: undefined, - moduleName: null + moduleName: null, + replaceable: true }); }); diff --git a/packages/x-components/src/components/base-keyboard-navigation.vue b/packages/x-components/src/components/base-keyboard-navigation.vue index 675c7dcc70..6ab91e2f17 100644 --- a/packages/x-components/src/components/base-keyboard-navigation.vue +++ b/packages/x-components/src/components/base-keyboard-navigation.vue @@ -83,8 +83,8 @@ /** * Trigger navigation if this component is in control of it. * - * @param eventPayload - The {@link WirePayload.eventPayload}. - * @param metadata - The {@link WirePayload.metadata}. + * @param eventPayload - The {@link @empathyco/x-bus#SubjectPayload.eventPayload}. + * @param metadata - The {@link @empathyco/x-bus#SubjectPayload.metadata}. * @public */ @XOn(component => (component as BaseKeyboardNavigation).navigationHijackerEvents) diff --git a/packages/x-components/src/components/column-picker/__tests__/base-column-picker-dropdown.spec.ts b/packages/x-components/src/components/column-picker/__tests__/base-column-picker-dropdown.spec.ts index f5223559ea..4c08e7863a 100644 --- a/packages/x-components/src/components/column-picker/__tests__/base-column-picker-dropdown.spec.ts +++ b/packages/x-components/src/components/column-picker/__tests__/base-column-picker-dropdown.spec.ts @@ -81,7 +81,9 @@ describe('testing BaseColumnPickerDropdown', () => { expect(listenerColumnPicker).toHaveBeenNthCalledWith(1, { eventPayload: 3, metadata: { - moduleName: null + moduleName: null, + location: undefined, + replaceable: true } }); }); diff --git a/packages/x-components/src/components/column-picker/__tests__/base-column-picker-list.spec.ts b/packages/x-components/src/components/column-picker/__tests__/base-column-picker-list.spec.ts index dd5263691f..77a4913079 100644 --- a/packages/x-components/src/components/column-picker/__tests__/base-column-picker-list.spec.ts +++ b/packages/x-components/src/components/column-picker/__tests__/base-column-picker-list.spec.ts @@ -72,7 +72,9 @@ describe('testing Base Column Picker List', () => { expect(listenerColumnPicker).toHaveBeenNthCalledWith(1, { eventPayload: 3, metadata: { - moduleName: null + moduleName: null, + location: undefined, + replaceable: true } }); }); @@ -94,7 +96,9 @@ describe('testing Base Column Picker List', () => { eventPayload: columns[index], metadata: { moduleName: null, // no module registered for this base component - target: wrapper.findAll(getDataTestSelector('column-picker-button')).at(index).element + target: wrapper.findAll(getDataTestSelector('column-picker-button')).at(index).element, + location: undefined, + replaceable: true } }); /* 1st event is to sync the initial value @@ -105,7 +109,9 @@ describe('testing Base Column Picker List', () => { eventPayload: columns[index], metadata: { moduleName: null, // no module registered for this base component - target: wrapper.findAll(getDataTestSelector('column-picker-button')).at(index).element + target: wrapper.findAll(getDataTestSelector('column-picker-button')).at(index).element, + location: undefined, + replaceable: true } }); }); diff --git a/packages/x-components/src/components/decorators/bus.decorators.ts b/packages/x-components/src/components/decorators/bus.decorators.ts index b732fec811..012380f320 100644 --- a/packages/x-components/src/components/decorators/bus.decorators.ts +++ b/packages/x-components/src/components/decorators/bus.decorators.ts @@ -1,11 +1,12 @@ import { AnyFunction } from '@empathyco/x-utils'; -import { Subscription } from 'rxjs'; +import { Observable, Subscription } from 'rxjs'; import { filter } from 'rxjs/operators'; import Vue, { WatchOptions } from 'vue'; import { createDecorator } from 'vue-class-component'; +import { EventPayload, SubjectPayload } from '@empathyco/x-bus'; import { clone } from '../../utils/clone'; import { DecoratorFor } from '../../utils/types'; -import { XEvent, XEventPayload } from '../../wiring/events.types'; +import { XEvent, XEventPayload, XEventsTypes } from '../../wiring/events.types'; import { WireMetadata } from '../../wiring/wiring.types'; /** @@ -84,8 +85,11 @@ function createSubscription( const subscription = new Subscription(); eventArray.forEach(xEvent => { subscription.add( - this.$x - .on(xEvent, true) + ( + this.$x.on(xEvent, true) as unknown as Observable< + SubjectPayload, WireMetadata> + > + ) .pipe(filter(({ metadata }) => filterMetadataOptions(metadataFilteringOptions, metadata))) .subscribe(({ eventPayload, metadata }) => callback(eventPayload, metadata)) ); diff --git a/packages/x-components/src/components/global-x-bus.vue b/packages/x-components/src/components/global-x-bus.vue index d147cd8f85..f4ed76f116 100644 --- a/packages/x-components/src/components/global-x-bus.vue +++ b/packages/x-components/src/components/global-x-bus.vue @@ -1,8 +1,11 @@