# 🧪 Como Testar a Biblioteca em Outra Aplicação

## 📋 Índice Rápido

1. [Teste Automatizado (Mais Rápido)](#teste-automatizado) ⭐ Recomendado
2. [Instalação Local Manual](#instalação-local-manual)
3. [Testar via npm link](#testar-via-npm-link)
4. [Testar via GitHub](#testar-via-github)
5. [Publicar no npm](#publicar-no-npm)

---

## ⚡ Teste Automatizado (Recomendado)

### Windows (PowerShell):
```powershell
cd c:\projetos\masfelix\react-native-bluetooth-datecs-printer
.\test-library.ps1
cd ..\test-printer-app
npx expo run:android
```

### Linux/Mac:
```bash
cd /path/to/react-native-bluetooth-datecs-printer
chmod +x test-library.sh
./test-library.sh
cd ../test-printer-app
npx expo run:android
```

**O que o script faz:**
- ✅ Cria novo projeto Expo automaticamente
- ✅ Instala e configura tudo
- ✅ Cria app de teste completo
- ✅ Pronto para usar em 2 minutos!

---

## 📦 Instalação Local Manual

### Opção A: Via file:

```bash
# 1. Criar projeto de teste
npx create-expo-app@latest test-printer
cd test-printer

# 2. Instalar biblioteca local
npm install file:../react-native-bluetooth-datecs-printer

# 3. Instalar dependências Expo
npx expo install expo-build-properties

# 4. Configurar app.json (copie de app.json.example)

# 5. Build e executar
npx expo prebuild --clean
npx expo run:android
```

**Atualizar após mudanças:**
```bash
npm uninstall react-native-bluetooth-datecs-printer
npm install file:../react-native-bluetooth-datecs-printer
npx expo prebuild --clean
```

---

### Opção B: Via npm link

```bash
# Na pasta da biblioteca
cd c:\projetos\masfelix\react-native-bluetooth-datecs-printer
npm link

# No projeto de teste
cd c:\projetos\test-printer
npm link react-native-bluetooth-datecs-printer
npx expo prebuild --clean
npx expo run:android
```

**Desvincular depois:**
```bash
# No projeto de teste
npm unlink react-native-bluetooth-datecs-printer

# Na biblioteca
npm unlink
```

---

## 🌐 Testar via GitHub

```bash
# Instalar diretamente do GitHub
npm install https://github.com/masfelix/react-native-bluetooth-datecs-printer.git

# Ou branch específico
npm install https://github.com/masfelix/react-native-bluetooth-datecs-printer.git#main

# Ou no package.json:
{
  "dependencies": {
    "react-native-bluetooth-datecs-printer": "github:masfelix/react-native-bluetooth-datecs-printer#main"
  }
}
```

---

## 📢 Publicar no npm (Produção)

```bash
# 1. Atualizar versão
cd c:\projetos\masfelix\react-native-bluetooth-datecs-printer
# Edite package.json: "version": "2.0.0"

# 2. Login no npm
npm login

# 3. Publicar
npm publish

# 4. Usar em qualquer projeto
npm install react-native-bluetooth-datecs-printer@2.0.0
```

---

## 📱 Configuração do Projeto de Teste

### Mínimo necessário no app.json:

```json
{
  "expo": {
    "plugins": [
      ["expo-build-properties", {
        "android": {
          "compileSdkVersion": 36,
          "targetSdkVersion": 36,
          "minSdkVersion": 26,
          "buildToolsVersion": "35.0.0"
        }
      }]
    ],
    "android": {
      "permissions": [
        "BLUETOOTH_CONNECT",
        "BLUETOOTH_SCAN"
      ]
    }
  }
}
```

### Código mínimo para testar (App.tsx):

```typescript
import React from 'react';
import { View, Button, Alert, PermissionsAndroid, Platform } from 'react-native';
import { RNBluetoothDatecsPrinter } from 'react-native-bluetooth-datecs-printer';

export default function App() {
  const test = async () => {
    // Solicitar permissões
    if (Platform.Version >= 31) {
      await PermissionsAndroid.requestMultiple([
        'android.permission.BLUETOOTH_CONNECT',
        'android.permission.BLUETOOTH_SCAN',
      ]);
    }
    
    // Buscar dispositivos
    const devices = await RNBluetoothDatecsPrinter.getDeviceList();
    Alert.alert('Encontrados', `${devices.length} dispositivos`);
  };

  return (
    <View style={{ flex: 1, justifyContent: 'center', padding: 20 }}>
      <Button title="Testar Biblioteca" onPress={test} />
    </View>
  );
}
```

---

## 🎯 Qual Método Usar?

| Método | Quando Usar | Vantagens | Desvantagens |
|--------|-------------|-----------|--------------|
| **Script Automatizado** | Teste rápido | ⚡ Muito rápido, tudo automático | Cria novo projeto |
| **file:** | Desenvolvimento ativo | 🔄 Fácil atualizar | Manual |
| **npm link** | Desenvolvimento com múltiplos projetos | 🔗 Link simbólico | Pode dar problemas |
| **GitHub** | Teste beta, CI/CD | 🌐 Não precisa publicar | Requer git push |
| **npm publish** | Produção | 📦 Oficial, fácil instalar | Precisa nova versão |

---

## ✅ Checklist de Teste

Antes de considerar o teste completo:

- [ ] App compila sem erros
- [ ] Permissões são solicitadas
- [ ] getDeviceList() retorna dispositivos
- [ ] Conecta à impressora
- [ ] Imprime texto
- [ ] Desconecta corretamente
- [ ] Funciona em Android 12+
- [ ] Funciona em Android 8-11
- [ ] Build de produção funciona

---

## 🐛 Problemas Comuns

### "Cannot find module"
```bash
npm cache clean --force
rm -rf node_modules package-lock.json
npm install
npx expo prebuild --clean
```

### Build falha
```bash
cd android
./gradlew clean
cd ..
npx expo prebuild --clean
```

### Mudanças não aparecem
```bash
# Se usando file:
npm uninstall react-native-bluetooth-datecs-printer
npm install file:../react-native-bluetooth-datecs-printer
npx expo prebuild --clean

# Se usando npm link:
npm unlink react-native-bluetooth-datecs-printer
npm link react-native-bluetooth-datecs-printer
npx expo prebuild --clean
```

---

## 📚 Documentação Completa

- **[TESTING_GUIDE.md](./TESTING_GUIDE.md)** - Guia completo de testes
- **[EXPO_SETUP.md](./EXPO_SETUP.md)** - Setup para Expo SDK 54
- **[QUICK_START.md](./QUICK_START.md)** - Início rápido
- **[examples/ExpoExample.tsx](./examples/ExpoExample.tsx)** - Exemplo completo

---

## 💡 Dica Profissional

Para desenvolvimento ativo, use o **script automatizado** para criar um projeto de teste base, depois use **file:** ou **npm link** para iterar rapidamente:

```bash
# 1. Criar base com script
.\test-library.ps1

# 2. Fazer mudanças na biblioteca
# ... editar código ...

# 3. Atualizar no teste
cd ..\test-printer-app
npm uninstall react-native-bluetooth-datecs-printer
npm install file:../react-native-bluetooth-datecs-printer
npx expo run:android --no-build-cache
```

---

## 🆘 Precisa de Ajuda?

1. Veja [TESTING_GUIDE.md](./TESTING_GUIDE.md) para guia detalhado
2. Veja [MIGRATION_CHECKLIST.md](./MIGRATION_CHECKLIST.md) para troubleshooting
3. Teste com o script automatizado primeiro
4. Verifique que o Android SDK 36 está instalado
