Skip to content
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

Chore/update cypress and ionic #12

Merged
merged 14 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ html
scripts/
docs/
**/.eslintrc.js
commitlint.config.js
commitlint.config.js
cypress.config.ts
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [16.13]
node-version: [20.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -35,7 +35,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [16.x]
node-version: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -54,7 +54,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [16.13]
node-version: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
16 changes: 16 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from 'cypress';

export default defineConfig({
includeShadowDom: true,
projectId: '1tfaog',
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.ts')(on, config);
},
baseUrl: 'http://localhost:3999/',
specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
experimentalRunAllSpecs: true,
},
});
6 changes: 0 additions & 6 deletions cypress.json

This file was deleted.

55 changes: 55 additions & 0 deletions cypress/e2e/components/input.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ionInputCypress } from '@lib';
import * as testHelpers from '../../../test-helpers/test-helpers.js';

describe('Ion Input', () => {
const selectors = [
'.external-label ion-input',
'.internal-label ion-input',
'.internal-label ion-input',
'.internal-aria-label ion-input',
];

selectors.forEach((selector) => {
describe(selector, () => {
beforeEach(() => {
cy.visit('./ion-input.html');
});

it('can be written on by string selector', () => {
cy.get(`${selector}.hydrated`)
.first()
.then(($ionInput) => {
const element = $ionInput[0];
const wantedText = testHelpers.convertToTestString(
element.innerText
);

ionInputCypress.write(selector, wantedText).then(() => {
const inputElement = element.querySelector('input')?.value;

expect(inputElement).to.eq(wantedText);
});
});
});

it('can be cleared', () => {
cy.get(`${selector}.hydrated`)
.first()
.then(($ionInput) => {
const element = $ionInput[0];

ionInputCypress
.write(selector, 'i am not clear here :)')
.then(() => {
return ionInputCypress.clear(selector);
})
.then(() => {
const inputElement = element.querySelector('input')?.value;

expect(inputElement).to.eq('');
});
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const selectorAndValues: Array<{

describe('using valid valid ranges', () => {
beforeEach(() => {
cy.visit('./');
cy.visit('./ion-range.html');
});

selectorAndValues.forEach((selectorAndValue) => {
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('using it to values beyond their supported max/min does not hangs', ()
];

beforeEach(() => {
cy.visit('./');
cy.visit('./ion-range.html');
});

outOfRangeValues.forEach((selectorAndValue) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ionSelectCypress } from '@lib';

describe('IonSelect', () => {
beforeEach(() => {
cy.visit('./');
cy.visit('./ion-select.html');
});

const byInterfaceSelectors = [
Expand Down Expand Up @@ -44,21 +44,39 @@ describe('IonSelect', () => {
const byTextWithSelectors: Array<{ elementSelector: string; text: string }> =
[
{
elementSelector: 'ion-select[interface=alert]',
text: 'ion-select ion-alert',
elementSelector:
'ion-select#ion-select-ion-alert-external-label[interface=alert]',
text: 'ion-select ion-alert external-label',
},
{
elementSelector: 'ion-select[interface=action-sheet]',
text: 'ion-select ion-action-sheet',
elementSelector:
'ion-select#ion-select-ion-action-sheet-external-label[interface=action-sheet]',
text: 'ion-select ion-action-sheet external-label',
},
{
elementSelector: 'ion-select[interface=popover]',
text: 'ion-select ion-popover',
elementSelector:
'ion-select#ion-select-ion-popover-external-label[interface=popover]',
text: 'ion-select ion-popover external-label',
},
{
elementSelector:
'ion-select#ion-select-ion-alert-internal-label[interface=alert]',
text: 'ion-select ion-alert internal-label',
},
{
elementSelector:
'ion-select#ion-select-ion-action-sheet-internal-label[interface=action-sheet]',
text: 'ion-select ion-action-sheet internal-label',
},
{
elementSelector:
'ion-select#ion-select-ion-popover-internal-label[interface=popover]',
text: 'ion-select ion-popover internal-label',
},
];

byTextWithSelectors.forEach((textAndSelector) => {
describe(`find ${textAndSelector.elementSelector} using text`, () => {
describe(`find ${textAndSelector.text} using text`, () => {
it(`can be found with "${textAndSelector.text}"`, () => {
cy.get(textAndSelector.elementSelector)
.should('have.length', 1) // check that just one is tested
Expand Down
43 changes: 0 additions & 43 deletions cypress/integration/components/input.spec.ts

This file was deleted.

40 changes: 20 additions & 20 deletions cypress/support/index.ts → cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands';
// Alternatively you can use CommonJS syntax:
// require('./commands')
36 changes: 36 additions & 0 deletions html/assets/ion-range.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { defineCustomElements } from '/node_modules/@ionic/core/dist/esm/loader.js';
import { convertToTestString } from '/test-helpers/test-helpers.js';

defineCustomElements(window).then(() => {
/* Ionic is loaded! */

// ------ ION RANGE ----- //
const ranges = document.querySelectorAll('ion-range');
const rangesIntervals = new Array(ranges.length);
document.querySelectorAll('ion-range').forEach((ionRange, i) => {
ionRange.addEventListener('ionChange', (event) => {
// console.log('ionRange ionChange event', event);
clearInterval(rangesIntervals[i]);
const targetIonRange = event.target;

rangesIntervals[i] = setInterval(() => {
const slot =
targetIonRange.shadowRoot.querySelector('slot[name="end"]');
if (!slot) {
return;
}

clearInterval(rangesIntervals[i]);
rangesIntervals[i] = undefined;

let eventValue = event.detail.value;

if (typeof eventValue === 'object') {
eventValue = `${eventValue.lower}/${eventValue.upper}`;
}

slot.assignedNodes()[0].innerText = eventValue;
}, 100);
});
});
});
5 changes: 5 additions & 0 deletions html/assets/ion-select.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineCustomElements } from '/node_modules/@ionic/core/dist/esm/loader.js';

defineCustomElements(window).then(() => {
/* Ionic is loaded! */
});
35 changes: 0 additions & 35 deletions html/assets/scripts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,4 @@ defineCustomElements(window).then(() => {
document.querySelector('ion-button').addEventListener('click', (event) => {
event.target.innerText = convertToTestString(event.target.innerText);
});

document.querySelector('.ion-range-dual ion-range').value = {
lower: -50,
upper: 50,
};

// ------ ION RANGE ----- //
const ranges = document.querySelectorAll('ion-range');
const rangesIntervals = new Array(ranges.length);
document.querySelectorAll('ion-range').forEach((ionRange, i) => {
ionRange.addEventListener('ionChange', (event) => {
console.log('ionRange ionChange event', event);
clearInterval(rangesIntervals[i]);
const targetIonRange = event.target;

rangesIntervals[i] = setInterval(() => {
const slot =
targetIonRange.shadowRoot.querySelector('slot[name="end"]');
if (!slot) {
return;
}

clearInterval(rangesIntervals[i]);
rangesIntervals[i] = undefined;

let eventValue = event.detail.value;

if (typeof eventValue === 'object') {
eventValue = `${eventValue.lower}/${eventValue.upper}`;
}

slot.assignedNodes()[0].innerText = eventValue;
}, 100);
});
});
});
5 changes: 5 additions & 0 deletions html/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ main {
max-width: 500px;
width: 80%;
}

h1,
h2 {
color: white;
}
Loading
Loading