Skip to content

Commit cdc87f2

Browse files
committed
test(spie-ui-e2e): add more tests
1 parent 91696d6 commit cdc87f2

File tree

11 files changed

+655
-145
lines changed

11 files changed

+655
-145
lines changed

apps/spie-ui-e2e/src/e2e/app.cy.ts

-87
This file was deleted.

apps/spie-ui-e2e/src/e2e/send.cy.ts

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
import { type SerialPortEvent } from '@spie/types';
2+
3+
import { mockElectronAPI } from '../fixtures/mocks/electron-api.mock';
4+
5+
describe('Serial Port Advanced Modal', () => {
6+
const mockSerialPortList = [
7+
{ path: '/dev/ttyUSB0', manufacturer: 'Manufacturer1' },
8+
{ path: '/dev/ttyUSB1', manufacturer: 'Manufacturer2' },
9+
];
10+
11+
let onEventTrigger: ((event: SerialPortEvent) => void) | null;
12+
13+
beforeEach(() => {
14+
cy.visit('/');
15+
16+
cy.on('window:before:load', (win) => {
17+
const listeners: Array<(serialPortEvent: SerialPortEvent) => void> = [];
18+
19+
win.electron = mockElectronAPI();
20+
win.electron.serialPort.list = cy.stub().resolves(mockSerialPortList);
21+
22+
win.electron.serialPort.onEvent = cy
23+
.stub()
24+
.callsFake((callback: (serialPortEvent: SerialPortEvent) => void) => {
25+
listeners.push(callback);
26+
27+
onEventTrigger = (serialPortEvent) => {
28+
listeners.forEach((listener) => listener(serialPortEvent));
29+
};
30+
31+
return () => {
32+
const index = listeners.indexOf(callback);
33+
if (index !== -1) {
34+
listeners.splice(index, 1);
35+
}
36+
};
37+
});
38+
});
39+
});
40+
41+
it('should enable/disable send based on serial port status', () => {
42+
const data = 'test test test test test test test test test test';
43+
44+
cy.wrap(null).then(() => {
45+
if (onEventTrigger) {
46+
onEventTrigger({ event: 'open' });
47+
}
48+
});
49+
50+
cy.get('app-send ion-input input').invoke('val', data).trigger('input');
51+
52+
cy.get('app-send ion-button')
53+
.contains('Send')
54+
.should('not.have.class', 'button-disabled');
55+
56+
cy.wrap(null).then(() => {
57+
if (onEventTrigger) {
58+
onEventTrigger({ event: 'close' });
59+
}
60+
});
61+
62+
cy.get('app-send ion-button')
63+
.contains('Send')
64+
.should('have.class', 'button-disabled');
65+
});
66+
67+
it('should clear input after pressing clear input button', () => {
68+
const data = 'test test test test test test test test test test';
69+
70+
cy.wrap(null).then(() => {
71+
if (onEventTrigger) {
72+
onEventTrigger({ event: 'open' });
73+
}
74+
});
75+
76+
cy.get('app-send ion-input input').invoke('val', data).trigger('input');
77+
cy.get('app-send ion-input button').click();
78+
79+
cy.get('app-send ion-input input').should('have.value', '');
80+
});
81+
82+
it('should send input with default options', () => {
83+
const data = 'test test test test test test test test test test';
84+
const formattedData = `${data}\n`;
85+
86+
cy.wrap(null).then(() => {
87+
if (onEventTrigger) {
88+
onEventTrigger({ event: 'open' });
89+
}
90+
});
91+
92+
cy.get('app-send ion-input input').invoke('val', data).trigger('input');
93+
94+
cy.get('app-send ion-button').contains('Send').click();
95+
96+
cy.window().then((win) => {
97+
cy.wrap(win.electron.serialPort.write).should(
98+
'have.been.calledOnceWithExactly',
99+
formattedData,
100+
'ascii'
101+
);
102+
});
103+
});
104+
105+
it('should open and close the advanced modal', () => {
106+
cy.get('app-send ion-button ion-icon').parent().click();
107+
cy.get('ion-modal').should('be.visible');
108+
cy.get('ion-modal ion-toolbar ion-button').click();
109+
cy.get('ion-modal').should('not.be.visible');
110+
});
111+
112+
it('should clear input after changing encoding', () => {
113+
const data = 'test test test test test test test test test test';
114+
cy.get('app-send ion-input input').invoke('val', data).trigger('input');
115+
116+
cy.get('app-send ion-button ion-icon').parent().click();
117+
cy.getAdvancedModalSelectElement(
118+
'send-advanced-modal',
119+
'Encoding'
120+
).selectOption('Hex');
121+
cy.get('ion-modal ion-toolbar ion-button').click();
122+
123+
cy.get('app-send ion-input input').should('have.value', '');
124+
});
125+
126+
it('should format hex input', () => {
127+
const data = 'test test test test test test test test test test';
128+
const expectedHexData = 'EE EE EE EE EE';
129+
130+
cy.get('app-send ion-button ion-icon').parent().click();
131+
cy.getAdvancedModalSelectElement(
132+
'send-advanced-modal',
133+
'Encoding'
134+
).selectOption('Hex');
135+
cy.get('ion-modal ion-toolbar ion-button').click();
136+
137+
cy.get('app-send ion-input input').invoke('val', data).trigger('input');
138+
139+
cy.get('app-send ion-input input').should('have.value', expectedHexData);
140+
});
141+
142+
it('should send input with hex encoding', () => {
143+
const data = 'test test test test test test test test test test\n\n\n';
144+
const formattedData = 'EEEEEEEEEE';
145+
146+
cy.get('app-send ion-button ion-icon').parent().click();
147+
cy.getAdvancedModalSelectElement(
148+
'send-advanced-modal',
149+
'Encoding'
150+
).selectOption('Hex');
151+
cy.get('ion-modal ion-toolbar ion-button').click();
152+
153+
cy.wrap(null).then(() => {
154+
if (onEventTrigger) {
155+
onEventTrigger({ event: 'open' });
156+
}
157+
});
158+
159+
cy.get('app-send ion-input input').invoke('val', data).trigger('input');
160+
161+
cy.get('app-send ion-button').contains('Send').click();
162+
163+
cy.window().then((win) => {
164+
cy.wrap(win.electron.serialPort.write).should(
165+
'have.been.calledOnceWithExactly',
166+
formattedData,
167+
'hex'
168+
);
169+
});
170+
});
171+
172+
it('should send input with advanced delimiter', () => {
173+
const data = 'test test test test test test test test test test';
174+
const formattedData = `${data}\r\n`;
175+
176+
cy.get('app-send ion-button ion-icon').parent().click();
177+
cy.getAdvancedModalSelectElement(
178+
'send-advanced-modal',
179+
'Delimiter'
180+
).selectOption('CRLF (\\r\\n)');
181+
cy.get('ion-modal ion-toolbar ion-button').click();
182+
183+
cy.wrap(null).then(() => {
184+
if (onEventTrigger) {
185+
onEventTrigger({ event: 'open' });
186+
}
187+
});
188+
189+
cy.get('app-send ion-input input').invoke('val', data).trigger('input');
190+
191+
cy.get('app-send ion-button').contains('Send').click();
192+
193+
cy.window().then((win) => {
194+
cy.wrap(win.electron.serialPort.write).should(
195+
'have.been.calledOnceWithExactly',
196+
formattedData,
197+
'ascii'
198+
);
199+
});
200+
});
201+
});

0 commit comments

Comments
 (0)