Skip to content

Commit

Permalink
test(spie-ui-e2e): fix terminal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonos committed Jan 1, 2025
1 parent 0b8d09e commit 4e4bc45
Showing 1 changed file with 25 additions and 36 deletions.
61 changes: 25 additions & 36 deletions apps/spie-ui-e2e/src/e2e/terminal.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
mockSerialPortList,
} from '../fixtures/mocks/electron-api.mock';

describe('Terminal routine', () => {
describe('Monitor routine', () => {
const mockData =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n';

Expand All @@ -21,33 +21,30 @@ describe('Terminal routine', () => {
cy.connect(mockSerialPortList[0].path, 9600);
});

it('should display data on the terminal', () => {
it('should display data on the monitor', () => {
cy.window().then((win) => {
win.onSerialPortEventTrigger({
type: 'data',
data: mockData,
});
});

cy.get('app-terminal-component ion-textarea textarea').should(
cy.get('app-monitor-component ion-textarea textarea').should(
'contain',
mockData
);
});

it('should clear the terminal', () => {
it('should clear the monitor', () => {
cy.window().then((win) => {
win.onSerialPortEventTrigger({
type: 'data',
data: mockData,
});
});

cy.get('app-terminal-component ion-button').contains('Clear').click();
cy.get('app-terminal-component ion-textarea textarea').should(
'contain',
''
);
cy.get('app-monitor-component ion-button').contains('Clear').click();
cy.get('app-monitor-component ion-textarea textarea').should('contain', '');
});

it('should auto scroll when data is emitted', () => {
Expand All @@ -60,7 +57,7 @@ describe('Terminal routine', () => {
}
});

cy.get('app-terminal-component ion-textarea textarea').then((textarea) => {
cy.get('app-monitor-component ion-textarea textarea').then((textarea) => {
const scrollTop = textarea[0].scrollTop;
const scrollHeight = textarea[0].scrollHeight;
const clientHeight = textarea[0].clientHeight;
Expand All @@ -69,7 +66,7 @@ describe('Terminal routine', () => {
});
});

it('should clear the terminal with clear event', () => {
it('should clear the monitor with clear event', () => {
cy.window().then((win) => {
win.onSerialPortEventTrigger({
type: 'data',
Expand All @@ -83,26 +80,22 @@ describe('Terminal routine', () => {
});
});

// cy.get('app-terminal-component ion-button').contains('Clear').click();
cy.get('app-terminal-component ion-textarea textarea').should(
'contain',
''
);
cy.get('app-monitor-component ion-textarea textarea').should('contain', '');
});

it('should open and close the advanced modal', () => {
cy.get('app-terminal-component ion-button [name="icon-settings-outlined"]')
cy.get('app-monitor-component ion-button [name="icon-settings-outlined"]')
.parent()
.click();
cy.get('ion-modal ion-toolbar ion-title').should(
'contain',
'Advanced Terminal Settings'
'Advanced Monitor Settings'
);
cy.get('ion-modal ion-toolbar ion-button').click();
cy.get('ion-modal').should('not.be.visible');
});

it('should clear the terminal after changing encoding', () => {
it('should clear the monitor after changing encoding', () => {
cy.window().then((win) => {
for (let index = 0; index < 10; index++) {
win.onSerialPortEventTrigger({
Expand All @@ -112,21 +105,18 @@ describe('Terminal routine', () => {
}
});

cy.get('app-terminal-component ion-button [name="icon-settings-outlined"')
cy.get('app-monitor-component ion-button [name="icon-settings-outlined"')
.parent()
.click();
cy.getAdvancedModalSelectElement(
'terminal-advanced-modal',
'monitor-advanced-modal',
'Encoding'
).selectDropdownOption('Hex');

cy.get('app-terminal-component ion-textarea textarea').should(
'contain',
''
);
cy.get('app-monitor-component ion-textarea textarea').should('contain', '');
});

it('should clear the terminal after changing show timestamps', () => {
it('should clear the monitor after changing show timestamps', () => {
cy.window().then((win) => {
for (let index = 0; index < 10; index++) {
win.onSerialPortEventTrigger({
Expand All @@ -136,28 +126,25 @@ describe('Terminal routine', () => {
}
});

cy.get('app-terminal-component ion-button [name="icon-settings-outlined"')
cy.get('app-monitor-component ion-button [name="icon-settings-outlined"')
.parent()
.click();
cy.getAdvancedModalCheckboxElement(
'terminal-advanced-modal',
'monitor-advanced-modal',
'Show Timestamps'
).click();

cy.get('app-terminal-component ion-textarea textarea').should(
'contain',
''
);
cy.get('app-monitor-component ion-textarea textarea').should('contain', '');
});

it('should not auto scroll when auto scroll is disabled and data is emitted', () => {
let initialScrollTop = 0;

cy.get('app-terminal-component ion-button [name="icon-settings-outlined"')
cy.get('app-monitor-component ion-button [name="icon-settings-outlined"')
.parent()
.click();
cy.getAdvancedModalCheckboxElement(
'terminal-advanced-modal',
'monitor-advanced-modal',
'Auto Scroll'
).click();
cy.get('ion-modal ion-toolbar ion-button').click();
Expand All @@ -175,11 +162,13 @@ describe('Terminal routine', () => {
}
});

cy.get('app-terminal-component ion-textarea textarea').then((textarea) => {
cy.get('app-monitor-component ion-textarea textarea').then((textarea) => {
const currentScrollTop = textarea[0].scrollTop;
expect(currentScrollTop).to.equal(initialScrollTop);
});
});

// TODO: PAUSE/CONTINUE
// TODO: should handle pause and continue
// TODO: should handle readline parser
// TODO: should change ascii encoding when going to plotter tab
});

0 comments on commit 4e4bc45

Please sign in to comment.