Skip to content

Commit

Permalink
cypress POC with github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yibaebi committed Feb 2, 2024
1 parent 9275f2e commit f4341db
Show file tree
Hide file tree
Showing 33 changed files with 2,004 additions and 138 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: E2E Test
on:
push:
branches:
- cypress-experiment
- develop
- main
- master

pull_request:
types: [opened, reopened]

jobs:
e2e-tests:
runs-on: [ubuntu-latest]
concurrency:
group: ${{ github.workflow }}-ci-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
deployments: write
name: Run E2E Tests
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'npm'
- run: npm ci
- run: npm run build
- name: Cypress run
uses: cypress-io/github-action@v5
env:
CYPRESS_TEST_USERNAME: ${{ secrets.CYPRESS_TEST_USERNAME}}
CYPRESS_TEST_PASSWORD: ${{ secrets.CYPRESS_TEST_PASSWORD }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_TEST_RECORD_ID}}
CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_TEST_PROJECT_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
install: false
config: pageLoadTimeout=100000
record: true
parallel: true
29 changes: 29 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import installHotjar from 'irene/utils/install-hotjar';
import customerSuccessBox from 'irene/utils/customer-success-box';
import { registerDateLibrary } from 'ember-power-calendar';
import DateUtils from 'irene/utils/power-calendar-dayjs';
import { createServer } from 'miragejs/server';

config.isDevknox = 'secure.devknox.io' === location.hostname;
config.isAppknox = !config.isDevknox;
Expand All @@ -32,3 +33,31 @@ export default class App extends Application {
}

loadInitializers(App, config.modulePrefix);

// if (window.Cypress) {
// // If your app makes requests to domains other than / (the current domain), add them
// // here so that they are also proxied from your app to the handleFromCypress function.
// // For example: let otherDomains = ["https://my-backend.herokuapp.com/"]
// let otherDomains = [];
// let methods = ['get', 'put', 'patch', 'post', 'delete'];

// createServer({
// environment: 'test',
// routes() {
// for (const domain of ['/', ...otherDomains]) {
// for (const method of methods) {
// this[method](`${domain}*`, async (schema, request) => {
// let [status, headers, body] = await window?.handleFromCypress(
// request
// );

// return new Response(status, headers, body);
// });
// }
// }

// // If your central server has any calls to passthrough(), you'll need to duplicate them here
// // this.passthrough('https://analytics.google.com')
// },
// });
// }
2 changes: 1 addition & 1 deletion app/components/auth-assets/index.hbs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<ImgLogo></ImgLogo>
<ImgLogo id='login-logo-img' />
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<LinkTo @route='authenticated.index'>
<img
data-test-img-logo
id='org-img-logo'
src={{if @isCollapsed this.faviconImage.src this.appLogoImage.src}}
alt={{this.whitelabel.name}}
/>
Expand Down
1 change: 1 addition & 0 deletions app/components/img-logo/index.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class='has-text-centered'>
<LinkTo @route='authenticated.index'>
<img
...attributes
data-test-img-logo
local-class='img-logo__img'
src={{this.whitelabel.logo}}
Expand Down
1 change: 1 addition & 0 deletions app/components/login-component/check/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/>
<AkIconButton
data-test-login-check-button
id='login-username-check-icon'
class='button is-primary highlighted-button margin-l-h'
@type='submit'
{{on 'click' @check}}
Expand Down
45 changes: 24 additions & 21 deletions app/components/login-component/index.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<div class="bg-color-container" local-class="container">
<div class="bg-color-container" local-class="inner-container">
<AuthAssets></AuthAssets>
<section local-class="login-container">
<h1 local-class="login-title">{{t "login"}}</h1>
<div local-class="action-container">
<div class='bg-color-container' local-class='container'>
<div class='bg-color-container' local-class='inner-container'>
<AuthAssets />
<section local-class='login-container'>
<h1 local-class='login-title' id='login-title' data-test-login-title>{{t
'login'
}}</h1>
<div local-class='action-container'>
{{#if this.isCheckDone}}
{{#if this.MFAEnabled}}
<LoginComponent::Mfa
Expand All @@ -13,8 +15,7 @@
@showSpinner={{this.loginTask.isRunning}}
@login={{this.login}}
data-test-login-mfa
>
</LoginComponent::Mfa>
/>
{{else}}

{{#if this.isSSOEnabled}}
Expand All @@ -28,8 +29,7 @@
@ssologin={{this.ssologin}}
@isEnforced={{this.isSSOEnforced}}
data-test-login-sso
>
</LoginComponent::Sso>
/>
{{else}}
<LoginComponent::Login
@username={{this.username}}
Expand All @@ -38,8 +38,7 @@
@showSpinner={{this.loginTask.isRunning}}
@login={{this.login}}
data-test-login-login
>
</LoginComponent::Login>
/>
{{/if}}

{{/if}}
Expand All @@ -49,18 +48,22 @@
@check={{this.verifySSO}}
@username={{this.username}}
data-test-login-check
>
</LoginComponent::Check>
/>
{{/if}}
</div>
{{#if this.showRegistrationLink}}
<div local-class="login-footer">
<p>{{t "dontHaveAccount"}}</p>
<a data-test-login-registration-link href="{{this.registrationLink}}" local-class="register-link">
{{t "register"}}
</a>
</div>
<div local-class='login-footer'>
<p>{{t 'dontHaveAccount'}}</p>
<a
data-test-login-registration-link
id='login-registration-link'
href='{{this.registrationLink}}'
local-class='register-link'
>
{{t 'register'}}
</a>
</div>
{{/if}}
</section>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions app/components/login-component/login/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
</div>
<AkButton
data-test-login-login-button
id='login-submit-button'
class='button is-primary is-fullwidth highlighted-button
{{local-class
"login-button"
Expand Down
17 changes: 17 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
projectId: 'fkj9f2',
baseUrl: 'http://localhost:4200/',
specPattern: ['cypress/e2e/**/*.spec.{js,ts}'],
viewportHeight: 1070,
viewportWidth: 1480,
env: {
hideCredentials: true,
TEST_USERNAME: '***',
TEST_PASSWORD: '***',
},
setupNodeEvents(on, config) {},
},
});
76 changes: 76 additions & 0 deletions cypress.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Add Cypress types
declare namespace Cypress {
/**
* ==================================
* IRENE SPECIFIC INTERFACES
* ==================================
*/

export interface FrontendConfig {
name: string;
hide_poweredby_logo: boolean;
url: string;
registration_enabled: boolean;
registration_link: string;
integrations: Integrations;
images: Images;
theme: Theme;
}

export interface Images {
logo_on_darkbg: string;
logo_on_lightbg: string;
favicon: string;
}

export interface Integrations {
crisp_key: string;
hotjar_key: string;
pendo_key: string;
csb_key: string;
rollbar_key: string;
freshdesk_configuration: FreshdeskConfiguration;
}

export interface FreshdeskConfiguration {
widget_id: string;
}

export interface Theme {
scheme: string;
primary_color: string;
primary_alt_color: string;
secondary_color: string;
secondary_alt_color: string;
}

interface ServerConfig {
websocket: string;
enterprise: boolean;
url_upload_allowed: boolean;
}

/**
* ==================================
* CUSTOM CYPRESS COMMANDS
* ==================================
*/
type modelFactoriesName = 'vulnerabilities' | 'projects';

interface Chainable {
loginByCredentials(username: string, password: string): Chainable;

generateModelFixture: (
name: modelFactoriesName,
size?: number
) => Chainable;

loadAppConfig(data?: {
frontendConfig?: FrontendConfig;
serverConfig?: ServerConfig;
}): Chainable;

loadMockAppConfig(): Chainable;
loadMockHudsonProjects(): Chainable;
}
}
Loading

0 comments on commit f4341db

Please sign in to comment.