Skip to content

Commit 9abf098

Browse files
authored
feat: Added e2e tests for vite-react-simple sample (#2728)
1 parent 594c87e commit 9abf098

File tree

12 files changed

+261
-17
lines changed

12 files changed

+261
-17
lines changed

cypress/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ It will generate two `describes` and two `its` for each test, and our test run w
461461
### Separate common checks and uncommon
462462
463463
As a suggestion, if you have two or more applications with similar functionality, you can create a separate file for shared checks, named `commonChecks.ts`, and add your created object with common checks there.
464+
NOTE: You can use `commonChecks.ts`, not only fot different apps but for similar checks in one app (for example similar checks of different buttons in one app)
464465
465466
So, your `e2e` directory will look like the following:
466467

cypress/common/base.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,27 @@ export class BaseMethods {
5959
wait = 0,
6060
isShadowRoot = false,
6161
index = 0,
62-
parentSelector
62+
parentSelector,
63+
isTargetChanged = false
6364
}: {
6465
selector: string,
6566
text: string,
6667
isForce?: boolean,
6768
wait?: number,
6869
isShadowRoot?: boolean,
6970
index?: number,
70-
parentSelector?: string
71+
parentSelector?: string,
72+
isTargetChanged?: boolean
7173
}): void {
74+
if(isTargetChanged) {
75+
cy.get(selector).contains(text)
76+
.should(($button: JQuery<HTMLElement>) => {
77+
$button.attr('target', '_self');
78+
}).click()
79+
80+
return;
81+
}
82+
7283
if(parentSelector) {
7384
cy.get(parentSelector)
7485
.find(selector)
@@ -124,7 +135,15 @@ export class BaseMethods {
124135
})
125136
}
126137

127-
public checkUrlText(url: string, isInclude: boolean = false): void {
138+
public checkUrlText(url: string, isInclude: boolean = false, isDifferentOrigin: boolean = false): void {
139+
if(isDifferentOrigin) {
140+
cy.origin(url, { args: { isInclude, url } }, ({ isInclude, url }) => {
141+
cy.url().should(isInclude ? 'include' : 'not.include', url);
142+
});
143+
144+
return;
145+
}
146+
128147
cy.url().should(isInclude ? 'include' : 'not.include', url);
129148
}
130149

@@ -340,7 +359,8 @@ export class BaseMethods {
340359
isShadowElement = false,
341360
text,
342361
isParent = false,
343-
checkType = 'contains'
362+
checkType = 'contains',
363+
isWithInvoke = true
344364
}: {
345365
selector: string,
346366
attr?: string,
@@ -352,7 +372,8 @@ export class BaseMethods {
352372
isShadowElement?: boolean,
353373
text?: string,
354374
isParent?: boolean,
355-
checkType?: string
375+
checkType?: string,
376+
isWithInvoke?: boolean
356377
}
357378
): Cypress.Chainable<JQuery<HTMLElement>> {
358379
if(text) {
@@ -426,6 +447,10 @@ export class BaseMethods {
426447
});
427448
}
428449

450+
if(!isWithInvoke) {
451+
return cy.get(selector).should(prop, value)
452+
}
453+
429454
return cy.get(selector)
430455
.invoke(attr, prop)
431456
.should('include', value)

cypress/common/selectors.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export const updatedSelectors = {
189189
vue3DemoFederationWithViteApp: {
190190
buttons: {
191191
vite: selectors.vue3DemoFederationWithViteApp.vueAppButton.replace('{appType}', Constants.selectorParts.vue3DemoFederationWithViteApp.vite),
192-
webpack: selectors.vue3DemoFederationWithViteApp.vueAppButton.replace('{appType}', Constants.selectorParts.vue3DemoFederationWithViteApp.webpack),
192+
webpack: selectors.vue3DemoFederationWithViteApp.vueAppButton.replace('{appType}', Constants.commonConstantsData.webpack),
193193
common: `${baseSelectors.tags.coreElements.div}[class*= "content"]`,
194194
}
195195
},
@@ -210,5 +210,8 @@ export const updatedSelectors = {
210210
componentBorder: `${selectors.craReactRewiredApp.componentInfo}${baseSelectors.css.style
211211
.replace('{style}', Constants.color.nonRgbValues.borderRed)}`
212212
},
213+
viteReactSimpleApp: {
214+
headerBlock: `${baseSelectors.tags.headers.header} ${baseSelectors.tags.coreElements.div}`,
215+
}
213216
}
214217

cypress/fixtures/constants.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export class Constants {
1111
public static readonly selectorParts = {
1212
vue3DemoFederationWithViteApp : {
1313
vite: 'vite',
14-
webpack: 'webpack'
1514
},
1615
sharedRoutingAppReplaceSelectorPart: 'RECENT_',
1716
formFieldNames: {
@@ -35,7 +34,10 @@ export class Constants {
3534
app3: 'App 3'
3635
},
3736
button: 'Button',
37+
header: 'Header',
3838
widget: 'Widget',
39+
webpack: 'webpack',
40+
counter: 'Counter',
3941
home: 'Home',
4042
commonIndexes: {
4143
minusOne: -1,
@@ -137,6 +139,7 @@ export class Constants {
137139
},
138140
helloWorldMessage: 'Hello World',
139141
commonVueAppComponentState: 'Remote Component in Action..',
142+
commonReactLink: 'https://reactjs.org'
140143
}
141144

142145
public static readonly updatedConstantsData = {
@@ -607,7 +610,6 @@ export class Constants {
607610
routeButton: 'Route',
608611
subheader1: 'Exposed from Child',
609612
subheader2: 'Listening in Parent',
610-
counter: 'Counter',
611613
},
612614
appButtonDiv: 'App Button',
613615
appButtonClickMeButton: 'Click me',
@@ -691,8 +693,15 @@ export class Constants {
691693
'Stop 🛑'
692694
],
693695
},
694-
rollupFederationDemoApp: {
695-
headerText: 'Header'
696+
viteReactSimpleApp: {
697+
buttons: {
698+
webpack: 'Webpack Remote Button',
699+
counter: 'count is: 0'
700+
},
701+
links: [
702+
'Learn React',
703+
'Vite Docs'
704+
]
696705
}
697706
}
698707

@@ -830,6 +839,12 @@ export class Constants {
830839
rollupHost: 'Rollup Host'
831840
},
832841
buttonText: 'Webpack Remote Button'
842+
},
843+
viteReactSimpleApp: {
844+
messages: {
845+
intro: 'Hello Vite + federation! +1+2+3+4',
846+
edit: 'Edit App.tsx and save to test HMR updates.'
847+
}
833848
}
834849
}
835850

@@ -869,7 +884,8 @@ export class Constants {
869884
white: 'rgb(255, 255, 255)',
870885
lightGrey: 'rgb(239, 239, 239)',
871886
darkGrey: 'rgb(40, 44, 52)',
872-
darkSaturatedBlue: 'rgb(0, 0, 255)'
887+
darkSaturatedBlue: 'rgb(0, 0, 255)',
888+
mint: 'rgb(97, 218, 251)'
873889
}
874890

875891
public static readonly hrefs = {
@@ -947,7 +963,6 @@ export class Constants {
947963
learnAboutNext: 'https://nextjs.org/learn/foundations/about-nextjs',
948964
deprecatedMainExamples: 'https://github.com/vercel/next.js/tree/deprecated-main/examples',
949965
},
950-
nativeFederationReactAppUrl: 'https://reactjs.org',
951966
comprehensiveDemoApp: {
952967
gitHub: 'https://github.com/module-federation/mfe-webpack-demo',
953968
app3: 'http://localhost:3003/',
@@ -968,5 +983,8 @@ export class Constants {
968983
federationLink: '/federation'
969984
},
970985
thirdPartyScriptsPostRequestPath: 'https://www.google-analytics.com/j/collect?**',
986+
viteReactSimpleApp: {
987+
viteLink: 'https://vitejs.dev/guide/features.html'
988+
}
971989
}
972990
}

cypress/types/cssAttr.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export const enum CssAttr {
22
backgroundColor = 'background-color',
33
background = 'background',
44
color = 'color',
5-
css = 'css'
5+
css = 'css',
6+
transform = 'transform',
67
}

native-federation-react/e2e/tests/hostComponentChecks.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("It checks host apps' component", () => {
9393
selector: baseSelectors.tags.coreElements.link,
9494
attr: Constants.commonConstantsData.commonAttributes.attr,
9595
prop: Constants.commonConstantsData.commonAttributes.href,
96-
value: Constants.hrefs.nativeFederationReactAppUrl,
96+
value: Constants.commonConstantsData.commonReactLink,
9797
isMultiple: true
9898
})
9999
})

quasar-cli-vue3-webpack-javascript/e2e/CheckAppExposes.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ appsData.forEach((
8484
})
8585
basePage.checkElementWithTextPresence({
8686
selector: baseSelectors.tags.coreElements.div,
87-
text: Constants.elementsText.quasarCliApp.appGeneral.counter,
87+
text: Constants.commonConstantsData.counter,
8888
})
8989
}
9090
if (property.host === 3001) {

rollup-federation-demo/e2e/tests/commonChecks.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('It checks rollup-federation-demo apps functionality', () => {
2323
basePage.openLocalhost(property.host)
2424
basePage.checkElementWithTextPresence({
2525
selector: selectors.rollupFederationDemoApp.header,
26-
text: Constants.elementsText.rollupFederationDemoApp.headerText,
26+
text: Constants.commonConstantsData.header,
2727
visibilityState: 'be.visible'
2828
})
2929
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { BaseMethods } from "../../../cypress/common/base";
2+
import {baseSelectors} from "../../../cypress/common/selectors";
3+
import {Constants} from "../../../cypress/fixtures/constants";
4+
import {CssAttr} from "../../../cypress/types/cssAttr";
5+
6+
const basePage: BaseMethods = new BaseMethods()
7+
8+
describe('It checks buttons & links on page', () => {
9+
const appsData = [
10+
{
11+
buttonName: Constants.commonConstantsData.webpack,
12+
buttonText: Constants.elementsText.viteReactSimpleApp.buttons.webpack,
13+
buttonColor: Constants.color.red,
14+
link: Constants.commonConstantsData.commonReactLink,
15+
linkName: Constants.elementsText.viteReactSimpleApp.links[0],
16+
},
17+
{
18+
buttonName: Constants.commonConstantsData.counter.toLowerCase(),
19+
buttonText: Constants.elementsText.viteReactSimpleApp.buttons.counter,
20+
buttonColor: Constants.color.lightGrey,
21+
link: Constants.hrefs.viteReactSimpleApp.viteLink,
22+
linkName: Constants.elementsText.viteReactSimpleApp.links[1],
23+
}
24+
]
25+
26+
appsData.forEach((property: { buttonName: string, buttonText: string, buttonColor: string, link: string, linkName: string }) => {
27+
it(`Checks ${property.buttonName} texted button visibility`, () => {
28+
basePage.openLocalhost(3000)
29+
basePage.checkElementWithTextPresence({
30+
selector: baseSelectors.tags.coreElements.button,
31+
text: property.buttonText,
32+
visibilityState: 'be.visible'
33+
})
34+
});
35+
36+
it(`Checks ${property.buttonName} texted button color`, () => {
37+
basePage.openLocalhost(3000)
38+
basePage.checkElementHaveProperty({
39+
selector: baseSelectors.tags.coreElements.button,
40+
prop: CssAttr.backgroundColor,
41+
value: property.buttonColor,
42+
text: property.buttonText,
43+
})
44+
})
45+
46+
47+
it(`Checks ${property.buttonName} texted button is not disabled`, () => {
48+
basePage.openLocalhost(3000)
49+
basePage.checkElementState({
50+
selector: baseSelectors.tags.coreElements.button,
51+
text: property.buttonText,
52+
state: 'not.be.disabled'
53+
})
54+
})
55+
56+
it(`Checks ${property.linkName} link functionality`, () => {
57+
basePage.openLocalhost(3000)
58+
basePage.clickElementWithText({
59+
selector: baseSelectors.tags.coreElements.link,
60+
text: property.linkName,
61+
isTargetChanged: true
62+
})
63+
basePage.checkUrlText(property.link, true, true)
64+
})
65+
})
66+
})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import './viteAppChecks.cy'
2+
import './commonChecks.cy'

0 commit comments

Comments
 (0)