Skip to content

Commit

Permalink
e2e(fixed rust-wasm sample and covered checks for it) (module-federat…
Browse files Browse the repository at this point in the history
  • Loading branch information
edchai authored Jan 12, 2023
1 parent 87b8b13 commit 6eefe7b
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 16 deletions.
15 changes: 10 additions & 5 deletions cypress/common/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {baseSelectors, block, buttons, fields} from "./selectors";
import {Constants} from "../fixtures/constants";
import {CssAttr} from "../types/cssAttr";
import {StubTypes} from "../types/stubTypes";

export class BaseMethods {

Expand Down Expand Up @@ -271,12 +272,16 @@ export class BaseMethods {
.should(contain ? checkType : 'not.contain.text', text);
}

public checkInfoInConsole(info: string): void {
cy.window().then((win) => {
cy.stub(win.console, "log").as('log')
cy.get('@log').should('be.calledWith', info)
public checkInfoInConsole(info: string, chainer: StubTypes = StubTypes.beCalled, isReloaded: boolean = true, isStubbed: boolean = true): void {
if(isStubbed) {
cy.window().then((win) => {
cy.stub(win.console, "log").as('log');
})
}
cy.get('@log').should(chainer, info)
if(isReloaded) {
this.reloadWindow()
})
}
}

public checkElementVisibility(
Expand Down
4 changes: 2 additions & 2 deletions cypress/common/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const baseSelectors = {
style: '[style="{style}"]',
code: 'code',
parent: '#parent',
navigation: 'nav',
navigationItem: '.nav-item',
table: 'table',
tableRow: 'tr',
Expand Down Expand Up @@ -64,7 +63,7 @@ export const selectors = {
sharedRoutingAppInputShrinkAnimation: '[data-shrink="{state}"]',
sharedRoutingAppCardProfileImage: '[data-e2e="CARD_PROFILE__IMAGE"]',
cssIsolationAppHeader: '#root h1',
cssIsolationAppName: '#root h2'
cssIsolationAppName: '#root h2',
vue3DemoComponents : {
remote: '.remote-component',
layout: '.layout-app',
Expand All @@ -78,6 +77,7 @@ export const selectors = {
appExposesCloseButton: '[data-e2e="exposesAppNamesClose"]',
appGeneralCounter: '[data-e2e="General-counter"]',
appExposesCounter: '[data-cy="app-button-counter"]',
rustWasmGameBoard: '[data-e2e="GAME_BOARD"]',
}

export const updatedSelectors = {
Expand Down
19 changes: 17 additions & 2 deletions cypress/fixtures/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ export class Constants {
'Using momentjs for format the date'
],
welcomeToHostApp: 'Welcome to Host App',
commonHostAppName: 'Host App',
remoteAppText: 'RemoteApp',
remoteAppsNameFromReduxStore: "RemoteApp's name from the redux store : ",
vueCliAppWelcomeMessage: 'Welcome to Your Vue.js + TypeScript App',
Expand Down Expand Up @@ -577,6 +578,13 @@ export class Constants {
'I\'m RxJs from remote',
'remote got message:'
],
rustWasmConsoleMessages: {
startLoopMessage:'Infinite looping in progress',
stopLoopMessage:'Looping successfully stopped',
tickLoopMessage:'Game board successfully rerendered',
resetLoopMessage:'Game board successfully reset',
baseLoadingMessage: 'I love rust and wasm!'
}
}

public static readonly commonText = {
Expand Down Expand Up @@ -620,7 +628,13 @@ export class Constants {
starSymbol: 'star',
cloudSymbol: 'cloud'
},
displayNone: 'display: none;'
displayNone: 'display: none;',
rustWasmAppButtonsNames: [
'Play ▶️',
'Tick 🔂',
'Reset ♻️',
'Stop 🛑'
],
}

public static readonly color = {
Expand Down Expand Up @@ -653,7 +667,8 @@ export class Constants {
oceanBluePearl: 'rgb(63, 81, 181)',
alabaster: 'rgb(250, 250, 250)',
paleVioletRed: 'rgb(219, 112, 147)',
white: 'rgb(255, 255, 255)'
white: 'rgb(255, 255, 255)',
lightGrey: 'rgb(239, 239, 239)'
}

public static readonly translation = {
Expand Down
4 changes: 4 additions & 0 deletions cypress/types/stubTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const enum StubTypes {
beCalled = 'to.be.calledWith',
notToBeCalled = 'not.to.be.calledWith',
}
1 change: 0 additions & 1 deletion native-federation-react/e2e/tests/commonChecks.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@ describe('It checks components header and console message', () => {
basePage.openLocalhost(property.host)
basePage.checkInfoInConsole(Constants.elementsText.nativeFederationReactConsoleMessages.weekendMessage)
})

});
});
14 changes: 14 additions & 0 deletions rust-wasm/e2e/methods/methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {BaseMethods} from "../../../cypress/common/base";
import {baseSelectors, selectors} from "../../../cypress/common/selectors";

export class RustWasmMethods extends BaseMethods {

public checkGameBoardAppearsByClick(buttonName: string): void {
this.checkElementVisibility(selectors.rustWasmGameBoard, false)
this.clickElementWithText({
selector: baseSelectors.button,
text: buttonName
})
this.checkElementVisibility(selectors.rustWasmGameBoard)
}
}
123 changes: 123 additions & 0 deletions rust-wasm/e2e/tests/commonChecks.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { BaseMethods } from "../../../cypress/common/base";
import {baseSelectors, selectors} from "../../../cypress/common/selectors";
import { Constants } from "../../../cypress/fixtures/constants";
import {StubTypes} from "../../../cypress/types/stubTypes";
import {RustWasmMethods} from "../methods/methods";

const basePage: BaseMethods = new BaseMethods()
const methodsPage: RustWasmMethods = new RustWasmMethods()

describe('It checks buttons functionality', () => {
const appsData = [
{
buttonName: Constants.commonText.rustWasmAppButtonsNames[0],
consoleMessage: Constants.commonPhrases.rustWasmConsoleMessages.startLoopMessage,
},
{
buttonName: Constants.commonText.rustWasmAppButtonsNames[1],
consoleMessage: Constants.commonPhrases.rustWasmConsoleMessages.tickLoopMessage,
index: 1
},
{
buttonName: Constants.commonText.rustWasmAppButtonsNames[2],
consoleMessage: Constants.commonPhrases.rustWasmConsoleMessages.resetLoopMessage,
index: 2
}
]

// @ts-ignore
appsData.forEach((property: { buttonName: string, consoleMessage: string, index: number }) => {
const extraPropertyIndex: number = property.index === 1 ? 2 : 1

it(`Checks that game board appears after click on ${property.buttonName} button`, () => {
basePage.openLocalhost(8080)
basePage.checkElementVisibility(selectors.rustWasmGameBoard, false)
basePage.checkInfoInConsole(property.consoleMessage,StubTypes.notToBeCalled, false)
basePage.clickElementWithText({
selector: baseSelectors.button,
text: property.buttonName
})
basePage.checkElementVisibility(selectors.rustWasmGameBoard)
basePage.checkInfoInConsole(property.consoleMessage,StubTypes.beCalled, false, false)
})

it(`Checks that game board triggered ${property.buttonName} button disappears after reload`, () => {
basePage.openLocalhost(8080)
methodsPage.checkGameBoardAppearsByClick(property.buttonName)
basePage.reloadWindow()
basePage.checkElementVisibility(selectors.rustWasmGameBoard, false)
})

it(`Checks ${property.buttonName} button still functioning even when game already started`, () => {
basePage.skipTestByCondition(property.buttonName === appsData[0].buttonName)
basePage.openLocalhost(8080)
basePage.clickElementWithText({
selector: baseSelectors.button,
text: appsData[0].buttonName
})
basePage.checkElementVisibility(selectors.rustWasmGameBoard)
basePage.checkInfoInConsole(property.consoleMessage,StubTypes.notToBeCalled, false)
basePage.clickElementWithText({
selector: baseSelectors.button,
text: property.buttonName
})
basePage.checkInfoInConsole(property.consoleMessage,StubTypes.beCalled, false, false)
})

it(`Checks ${property.buttonName} button still functioning even when game already started and stopped`, () => {
basePage.openLocalhost(8080)
basePage.clickElementWithText({
selector: baseSelectors.button,
text: appsData[0].buttonName
})
basePage.checkElementVisibility(selectors.rustWasmGameBoard)
basePage.checkInfoInConsole(property.consoleMessage, StubTypes.notToBeCalled, false)
basePage.clickElementWithText({
selector: baseSelectors.button,
text: Constants.commonText.rustWasmAppButtonsNames[3]
})
basePage.checkInfoInConsole(Constants.commonPhrases.rustWasmConsoleMessages.stopLoopMessage,StubTypes.beCalled, false, false)
basePage.checkInfoInConsole(property.consoleMessage,property.buttonName === Constants.commonText.rustWasmAppButtonsNames[0]
? StubTypes.beCalled : StubTypes.notToBeCalled, false, false)
basePage.clickElementWithText({
selector: baseSelectors.button,
text: property.buttonName
})
basePage.checkElementVisibility(selectors.rustWasmGameBoard)
basePage.checkInfoInConsole(property.consoleMessage,StubTypes.beCalled, false, false)
})

it(`Checks game board triggered by ${Constants.commonText.rustWasmAppButtonsNames[property.index]}
can be updated by ${Constants.commonText.rustWasmAppButtonsNames[extraPropertyIndex]} `, () => {
const consoleMessage: string = property.index === 1 ? appsData[2].consoleMessage : appsData[1].consoleMessage

basePage.skipTestByCondition(property.buttonName === appsData[0].buttonName)
basePage.openLocalhost(8080)
methodsPage.checkGameBoardAppearsByClick(Constants.commonText.rustWasmAppButtonsNames[property.index])
basePage.checkInfoInConsole(consoleMessage,StubTypes.notToBeCalled, false)
basePage.clickElementWithText({
selector: baseSelectors.button,
text: Constants.commonText.rustWasmAppButtonsNames[extraPropertyIndex]
})
basePage.checkInfoInConsole(consoleMessage,StubTypes.beCalled, false, false)
})

it(`Checks game triggered by ${property.buttonName} button can be started and stopped by Play button`, () => {
basePage.skipTestByCondition(property.buttonName === appsData[0].buttonName)
basePage.openLocalhost(8080)
methodsPage.checkGameBoardAppearsByClick(property.buttonName)
basePage.checkInfoInConsole(Constants.commonPhrases.rustWasmConsoleMessages.startLoopMessage,StubTypes.notToBeCalled, false)
basePage.checkInfoInConsole(Constants.commonPhrases.rustWasmConsoleMessages.stopLoopMessage,StubTypes.notToBeCalled, false, false)
basePage.clickElementWithText({
selector: baseSelectors.button,
text: appsData[0].buttonName
})
basePage.checkInfoInConsole(Constants.commonPhrases.rustWasmConsoleMessages.startLoopMessage,StubTypes.beCalled, false, false)
basePage.clickElementWithText({
selector: baseSelectors.button,
text: Constants.commonText.rustWasmAppButtonsNames[3]
})
basePage.checkInfoInConsole(Constants.commonPhrases.rustWasmConsoleMessages.stopLoopMessage,StubTypes.beCalled, false, false)
})
});
});
Loading

0 comments on commit 6eefe7b

Please sign in to comment.