From 8c1095bf59830b38a8c2098603a4893c83bfb1df Mon Sep 17 00:00:00 2001 From: DaviMarinho Date: Sun, 5 Nov 2023 22:36:01 -0300 Subject: [PATCH] Add ci/cd on frontend Signed-off-by: DaviMarinho --- .github/workflows/ci-cd.yml | 38 +++++++++++++++ angular.json | 2 +- package-lock.json | 4 +- package.json | 2 +- src/app/pages/login/login.component.spec.ts | 47 +++++++++++++++++-- .../video-viewer.component.spec.ts | 2 +- src/app/pages/video/video.component.spec.ts | 2 +- src/app/services/video.service.spec.ts | 2 +- 8 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/ci-cd.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 00000000..b27e8ca9 --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,38 @@ +name: CI/CD Pipeline Frontend + +on: push + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: 16.x + + - name: Install dependencies + run: npm install + + - name: Build + run: npm run build + + - name: Test + run: ng test + + deploy: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Deploy to Heroku + uses: akhileshns/heroku-deploy@v3.12.12 + with: + heroku_api_key: ${{ secrets.HEROKU_API_KEY }} + heroku_app_name: your-heroku-app-name + heroku_email: your-email@example.com + heroku_deploy_branch: main diff --git a/angular.json b/angular.json index b0eaf8d8..99fd3ee6 100644 --- a/angular.json +++ b/angular.json @@ -13,7 +13,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist/un-b-tv-frontend", + "outputPath": "dist/unb-tv-frontend", "index": "src/index.html", "main": "src/main.ts", "polyfills": [ diff --git a/package-lock.json b/package-lock.json index c16ab575..8114907a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "un-b-tv-frontend", + "name": "unb-tv-frontend", "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "un-b-tv-frontend", + "name": "unb-tv-frontend", "version": "0.0.0", "dependencies": { "@angular/animations": "^15.2.0", diff --git a/package.json b/package.json index 4d026e0f..34a46221 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "un-b-tv-frontend", + "name": "unb-tv-frontend", "version": "0.0.0", "scripts": { "ng": "ng", diff --git a/src/app/pages/login/login.component.spec.ts b/src/app/pages/login/login.component.spec.ts index 10eca249..67f55c61 100644 --- a/src/app/pages/login/login.component.spec.ts +++ b/src/app/pages/login/login.component.spec.ts @@ -1,16 +1,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; - import { LoginComponent } from './login.component'; +import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; describe('LoginComponent', () => { let component: LoginComponent; let fixture: ComponentFixture; beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ LoginComponent ] - }) - .compileComponents(); + TestBed.configureTestingModule({ + declarations: [LoginComponent], + imports: [ReactiveFormsModule], + providers: [FormBuilder], + }).compileComponents(); fixture = TestBed.createComponent(LoginComponent); component = fixture.componentInstance; @@ -20,4 +21,40 @@ describe('LoginComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should have a valid form on initialization', () => { + expect(component.userForm.valid).toBeFalse(); + }); + + it('should call login method when the form is submitted', () => { + spyOn(component, 'login'); + const form = component.userForm; + form.setValue({ email: 'test@example.com', password: 'password' }); + fixture.detectChanges(); + + const submitButton = fixture.nativeElement.querySelector( + 'button[type="submit"]' + ); + submitButton.click(); + + expect(component.login).toHaveBeenCalled(); + }); + + it('should call navigator method when "Esqueceu a senha?" is clicked', () => { + spyOn(component, 'navigator'); + const forgotPasswordLink = + fixture.nativeElement.querySelector('.text-gray-400'); + forgotPasswordLink.click(); + + expect(component.navigator).toHaveBeenCalledWith('/sendCodeResetPassword'); + + it('should call navigator method when "Cadastre-se" is clicked', () => { + spyOn(component, 'navigator'); + const registerLink = + fixture.nativeElement.querySelector('.text-blue-brand'); + registerLink.click(); + + expect(component.navigator).toHaveBeenCalledWith('/register'); + }); + }); }); diff --git a/src/app/pages/video-viewer/video-viewer.component.spec.ts b/src/app/pages/video-viewer/video-viewer.component.spec.ts index feaf9281..0fcedda5 100644 --- a/src/app/pages/video-viewer/video-viewer.component.spec.ts +++ b/src/app/pages/video-viewer/video-viewer.component.spec.ts @@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { RouterTestingModule } from "@angular/router/testing"; import { VideoViewerComponent } from './video-viewer.component'; -import { VideoService } from './video.service'; +import { VideoService } from '../../services/video.service'; import { SafePipe } from 'src/app/pipes/safe.pipe'; describe('VideoViewerComponent', () => { diff --git a/src/app/pages/video/video.component.spec.ts b/src/app/pages/video/video.component.spec.ts index 79fd12db..f91dc014 100644 --- a/src/app/pages/video/video.component.spec.ts +++ b/src/app/pages/video/video.component.spec.ts @@ -1,7 +1,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { VideoComponent } from './video.component'; -import { VideoService } from './video.service'; +import { VideoService } from '../../services/video.service'; describe('VideoComponent', () => { let component: VideoComponent; diff --git a/src/app/services/video.service.spec.ts b/src/app/services/video.service.spec.ts index 3378e3ce..5230f2a5 100644 --- a/src/app/services/video.service.spec.ts +++ b/src/app/services/video.service.spec.ts @@ -2,7 +2,7 @@ import { TestBed } from '@angular/core/testing'; import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; import { VideoService } from './video.service'; import { EDUPLAY_API_URL, UNB_ID } from 'src/app/app.constant'; -import { EDUPLAY_CLIENT_KEY } from 'src/app/secret/eduplay.credentials'; +import { EDUPLAY_CLIENT_KEY } from '../environment/environment'; describe('VideoService', () => { let service: VideoService;