@designliquido/delegua-interface-grafica 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.release-it.json +15 -0
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/fontes/delegua-modulo.ts +238 -0
- package/fontes/index.ts +3 -0
- package/fontes/infraestruturas/electron/README.md +92 -0
- package/fontes/infraestruturas/electron/infraestrutura-electron.ts +284 -0
- package/fontes/infraestruturas/index.ts +2 -0
- package/fontes/infraestruturas/vazia/README.md +53 -0
- package/fontes/infraestruturas/vazia/infraestrutura-vazia.ts +61 -0
- package/fontes/interface-grafica.ts +172 -0
- package/fontes/interfaces/componente-interface-grafica-interface.ts +8 -0
- package/fontes/interfaces/index.ts +2 -0
- package/fontes/interfaces/infraestrutura-grafica-interface.ts +46 -0
- package/jest.config.ts +21 -0
- package/package.json +41 -0
- package/testes/interface-grafica.test.ts +159 -0
- package/tsconfig.json +22 -0
- package/tsconfig.spec.json +21 -0
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@designliquido/delegua-interface-grafica",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Biblioteca de interface gráfica para Delégua",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/DesignLiquido/delegua-interface-grafica.git"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"empacotar": "yarn rimraf ./dist && tsc && yarn copyfiles -V ./README.md ./dist && yarn copyfiles -V ./LICENSE ./dist",
|
|
13
|
+
"publicar-npm": "npm publish --access public",
|
|
14
|
+
"testes-unitarios": "yarn jest --coverage",
|
|
15
|
+
"lint": "yarn eslint . --ext .ts --fix"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"delegua",
|
|
19
|
+
"interface",
|
|
20
|
+
"gui",
|
|
21
|
+
"janela"
|
|
22
|
+
],
|
|
23
|
+
"author": "Leonel Sanches da Silva",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@designliquido/delegua": ">=1.15.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/jest": "^29.5.14",
|
|
33
|
+
"@types/node": "^22.14.0",
|
|
34
|
+
"copyfiles": "^2.4.1",
|
|
35
|
+
"jest": "^29.7.0",
|
|
36
|
+
"rimraf": "^6.0.1",
|
|
37
|
+
"ts-jest": "^29.3.0",
|
|
38
|
+
"ts-node": "^10.9.2",
|
|
39
|
+
"typescript": "^5.8.3"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { InfraestruturaVazia } from '../fontes/infraestruturas/vazia/infraestrutura-vazia';
|
|
2
|
+
import { InterfaceGrafica } from '../fontes/interface-grafica';
|
|
3
|
+
import { ComponenteInterfaceGraficaInterface } from '../fontes/interfaces/componente-interface-grafica-interface';
|
|
4
|
+
|
|
5
|
+
const interpretadorFalso: any = {
|
|
6
|
+
executarChamavel: jest.fn().mockResolvedValue(undefined),
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
describe('InterfaceGrafica com InfraestruturaVazia', () => {
|
|
10
|
+
let ig: InterfaceGrafica;
|
|
11
|
+
let infraestrutura: InfraestruturaVazia;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
infraestrutura = new InfraestruturaVazia();
|
|
15
|
+
ig = new InterfaceGrafica(infraestrutura);
|
|
16
|
+
interpretadorFalso.executarChamavel.mockClear();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('criação de componentes', () => {
|
|
20
|
+
it('janela retorna um componente com idComponente', () => {
|
|
21
|
+
const janela = ig.janela(interpretadorFalso, 800, 600, 'Teste');
|
|
22
|
+
expect(janela).toBeDefined();
|
|
23
|
+
expect(janela.idComponente).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('botao retorna um componente com idComponente', () => {
|
|
27
|
+
const janela = ig.janela(interpretadorFalso, 800, 600, 'Teste');
|
|
28
|
+
const botao = ig.botao(interpretadorFalso, janela, 'Clique aqui');
|
|
29
|
+
expect(botao).toBeDefined();
|
|
30
|
+
expect(botao.idComponente).toBeTruthy();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('rotulo retorna um componente com idComponente', () => {
|
|
34
|
+
const janela = ig.janela(interpretadorFalso, 800, 600, 'Teste');
|
|
35
|
+
const rotulo = ig.rotulo(interpretadorFalso, janela, 'Olá');
|
|
36
|
+
expect(rotulo).toBeDefined();
|
|
37
|
+
expect(rotulo.idComponente).toBeTruthy();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('caixaTexto retorna um componente com idComponente', () => {
|
|
41
|
+
const janela = ig.janela(interpretadorFalso, 800, 600, 'Teste');
|
|
42
|
+
const caixa = ig.caixaTexto(interpretadorFalso, janela, 'inicial');
|
|
43
|
+
expect(caixa).toBeDefined();
|
|
44
|
+
expect(caixa.idComponente).toBeTruthy();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('caixaTexto usa texto vazio por padrão', () => {
|
|
48
|
+
const janela = ig.janela(interpretadorFalso, 800, 600, 'Teste');
|
|
49
|
+
const caixa = ig.caixaTexto(interpretadorFalso, janela);
|
|
50
|
+
expect(ig.obterTexto(interpretadorFalso, caixa)).toBe('');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('caixaVertical retorna um componente com idComponente', () => {
|
|
54
|
+
const janela = ig.janela(interpretadorFalso, 800, 600, 'Teste');
|
|
55
|
+
const caixa = ig.caixaVertical(interpretadorFalso, janela);
|
|
56
|
+
expect(caixa).toBeDefined();
|
|
57
|
+
expect(caixa.idComponente).toBeTruthy();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('caixaHorizontal retorna um componente com idComponente', () => {
|
|
61
|
+
const janela = ig.janela(interpretadorFalso, 800, 600, 'Teste');
|
|
62
|
+
const caixa = ig.caixaHorizontal(interpretadorFalso, janela);
|
|
63
|
+
expect(caixa).toBeDefined();
|
|
64
|
+
expect(caixa.idComponente).toBeTruthy();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('cada componente recebe um idComponente único', () => {
|
|
68
|
+
const janela = ig.janela(interpretadorFalso, 800, 600, 'Teste');
|
|
69
|
+
const botao1 = ig.botao(interpretadorFalso, janela, 'Botão 1');
|
|
70
|
+
const botao2 = ig.botao(interpretadorFalso, janela, 'Botão 2');
|
|
71
|
+
expect(botao1.idComponente).not.toBe(botao2.idComponente);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('texto de componentes', () => {
|
|
76
|
+
let janela: ComponenteInterfaceGraficaInterface;
|
|
77
|
+
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
janela = ig.janela(interpretadorFalso, 800, 600, 'Teste');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('rotulo preserva o texto inicial', () => {
|
|
83
|
+
const rotulo = ig.rotulo(interpretadorFalso, janela, 'Olá, mundo!');
|
|
84
|
+
expect(ig.obterTexto(interpretadorFalso, rotulo)).toBe('Olá, mundo!');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('caixaTexto preserva o texto inicial', () => {
|
|
88
|
+
const caixa = ig.caixaTexto(interpretadorFalso, janela, 'valor inicial');
|
|
89
|
+
expect(ig.obterTexto(interpretadorFalso, caixa)).toBe('valor inicial');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('definirTexto atualiza o texto do componente', () => {
|
|
93
|
+
const rotulo = ig.rotulo(interpretadorFalso, janela, 'antes');
|
|
94
|
+
ig.definirTexto(interpretadorFalso, rotulo, 'depois');
|
|
95
|
+
expect(ig.obterTexto(interpretadorFalso, rotulo)).toBe('depois');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('definirTexto não afeta outros componentes', () => {
|
|
99
|
+
const rotulo1 = ig.rotulo(interpretadorFalso, janela, 'rótulo 1');
|
|
100
|
+
const rotulo2 = ig.rotulo(interpretadorFalso, janela, 'rótulo 2');
|
|
101
|
+
ig.definirTexto(interpretadorFalso, rotulo1, 'alterado');
|
|
102
|
+
expect(ig.obterTexto(interpretadorFalso, rotulo2)).toBe('rótulo 2');
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('eventos', () => {
|
|
107
|
+
let janela: ComponenteInterfaceGraficaInterface;
|
|
108
|
+
let botao: ComponenteInterfaceGraficaInterface;
|
|
109
|
+
|
|
110
|
+
beforeEach(() => {
|
|
111
|
+
janela = ig.janela(interpretadorFalso, 800, 600, 'Teste');
|
|
112
|
+
botao = ig.botao(interpretadorFalso, janela, 'OK');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('aoClicar registra sem lançar exceção', () => {
|
|
116
|
+
const funcaoDelegua = {};
|
|
117
|
+
expect(() => ig.aoClicar(interpretadorFalso, botao, funcaoDelegua)).not.toThrow();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('aoAlterar registra sem lançar exceção', () => {
|
|
121
|
+
const caixa = ig.caixaTexto(interpretadorFalso, janela, '');
|
|
122
|
+
const funcaoDelegua = {};
|
|
123
|
+
expect(() => ig.aoAlterar(interpretadorFalso, caixa, funcaoDelegua)).not.toThrow();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('ciclo de vida', () => {
|
|
128
|
+
it('iniciar resolve sem erros', async () => {
|
|
129
|
+
await expect(ig.iniciar(interpretadorFalso)).resolves.toBeUndefined();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('encerrar não lança exceção', () => {
|
|
133
|
+
expect(() => ig.encerrar(interpretadorFalso)).not.toThrow();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('InfraestruturaVazia isolado', () => {
|
|
139
|
+
let infraestrutura: InfraestruturaVazia;
|
|
140
|
+
|
|
141
|
+
beforeEach(() => {
|
|
142
|
+
infraestrutura = new InfraestruturaVazia();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('criarJanela retorna componente válido', () => {
|
|
146
|
+
const c = infraestrutura.criarJanela(800, 600, 'Teste');
|
|
147
|
+
expect(c.idComponente).toBeTruthy();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('obterTexto retorna string vazia para componente sem texto', () => {
|
|
151
|
+
const janela = infraestrutura.criarJanela(800, 600, 'Teste');
|
|
152
|
+
const botao = infraestrutura.criarBotao(janela, 'OK');
|
|
153
|
+
expect(infraestrutura.obterTexto(botao)).toBe('');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('iniciarLaco resolve imediatamente', async () => {
|
|
157
|
+
await expect(infraestrutura.iniciarLaco()).resolves.toBeUndefined();
|
|
158
|
+
});
|
|
159
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "dist",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"target": "es2017",
|
|
6
|
+
"rootDir": "fontes",
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"lib": ["es2017", "dom"],
|
|
13
|
+
"skipLibCheck": true
|
|
14
|
+
},
|
|
15
|
+
"exclude": [
|
|
16
|
+
"coverage",
|
|
17
|
+
"dist/**/*",
|
|
18
|
+
"jest.config.ts",
|
|
19
|
+
"node_modules",
|
|
20
|
+
"testes"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "dist",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"target": "es2017",
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationMap": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"lib": ["es2017", "dom"],
|
|
12
|
+
"skipLibCheck": true
|
|
13
|
+
},
|
|
14
|
+
"include": [
|
|
15
|
+
"fontes/**/*",
|
|
16
|
+
"testes/**/*"
|
|
17
|
+
],
|
|
18
|
+
"exclude": [
|
|
19
|
+
"node_modules"
|
|
20
|
+
]
|
|
21
|
+
}
|