Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:fga-eps-mds/2023.2-UnB-TV-Fronte…
Browse files Browse the repository at this point in the history
…nd into 59-admin-crud
  • Loading branch information
nYCSTs committed Nov 12, 2023
2 parents 217f143 + c2fa3c6 commit 2b9ba02
Show file tree
Hide file tree
Showing 38 changed files with 1,259 additions and 121 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/continous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI Pipeline Frontend

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout ✅
uses: actions/checkout@v3

- name: Setup 🏗
uses: actions/setup-node@v2
with:
node-version: lts/*
cache: 'npm'

- name: Install ⚙️
run: npm install

- name: Build 🛠
run: npm run build

- name: Test 📋
run: npm run test:prod
41 changes: 41 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: netlify-deploy
on:
pull_request:
types:
- closed
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout ✅
uses: actions/checkout@v3

- name: Setup 🏗
uses: actions/setup-node@v2
with:
node-version: lts/*
cache: 'npm'

- name: Install ⚙️
run: npm install

- name: Build 🛠
run: npm run build

- name: Test 📋
run: npm run test:prod

- name: Deploy to Netlify
uses: nwtgck/[email protected]
with:
publish-dir: './dist/unb-tv-frontend'
production-branch: devel
github-token: ${{ secrets.GITHUB_TOKEN }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ testem.log
Thumbs.db

./github
/src/app/secret/
/src/app/environment
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ FROM node:16 as angular

WORKDIR /unb-tv-web

RUN apt-get update
RUN apt-get -y install chromium

# set CHROME_BIN environment variable, so that karma knows which crome should be started
ENV CHROME_BIN=/usr/bin/chromium

ENV PATH /unb-tv-web/node_modules/.bin:$PATH
ENV NODE_ENV=dev

Expand Down
8 changes: 5 additions & 3 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -22,7 +22,8 @@
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
"src/assets",
"src/_redirects"
],
"styles": [
"src/styles.css"
Expand Down Expand Up @@ -89,7 +90,8 @@
"styles": [
"src/styles.css"
],
"scripts": []
"scripts": [],
"karmaConfig": "karma.conf.js"
}
}
}
Expand Down
52 changes: 52 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
config.set({
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: [
'--no-sandbox',
'--disable-gpu',
'--headless',
'--remote-debugging-port=9222'
]
}
},
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage/unb-tv-frontend'),
subdir: '.',
reporters: [
{ type: 'html' },
{ type: 'lcov' },
{ type: 'cobertura' },
{ type: 'text-summary' }
]
},
reporters: ['progress', 'kjhtml'],
browsers: ['Chrome'],
restartOnFileChange: true
});
};
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"name": "un-b-tv-frontend",
"name": "unb-tv-frontend",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"build:tailwind": "postcss src/styles.css -o dist/styles.css",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
"test": "ng test",
"build:prod": "ng build --prod",
"test:prod": "ng test --browsers=ChromeHeadless --watch=false --code-coverage"
},
"private": true,
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* /index.html 200
2 changes: 1 addition & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { LoginComponent } from './pages/login/login.component';
import { RegisterComponent } from './pages/register/register.component';
import { LoginSocialComponent } from './pages/login-social/login-social.component';
import { VideoComponent } from './pages/video/video.component';
import { VideoViewerComponent } from './pages/video/video-viewer.component';
import { VideoViewerComponent } from './pages/video-viewer/video-viewer.component';
import { ActiveAccountComponent } from './pages/active-account/active-account.component';
import { ProfileComponent } from './pages/profile/profile.component';
import { CheckCodeRestPasswordComponent } from './pages/check-code-rest-password/check-code-rest-password.component';
Expand Down
35 changes: 12 additions & 23 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
import { TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import { BackgroundComponent } from './components/background/background.component';

describe('AppComponent', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
AppComponent
],
imports: [RouterTestingModule],
declarations: [AppComponent, BackgroundComponent],
}).compileComponents();
});

it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it(`should have as title 'UnB-TV-Frontend'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('UnB-TV-Frontend');
it('should create the app', () => {
expect(component).toBeTruthy();
});

// it('should render title', () => {
// const fixture = TestBed.createComponent(AppComponent);
// fixture.detectChanges();
// const compiled = fixture.nativeElement as HTMLElement;
// expect(compiled.querySelector('.content span')?.textContent).toContain('UnB-TV-Frontend app is running!');
// });
});
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AppComponent } from './app.component';
import { LoginComponent } from './pages/login/login.component';
import { RegisterComponent } from './pages/register/register.component';
import { VideoComponent } from './pages/video/video.component';
import { VideoViewerComponent } from './pages/video/video-viewer.component';
import { VideoViewerComponent } from './pages/video-viewer/video-viewer.component';
import { SafePipe } from './pipes/safe.pipe';
import { BackgroundComponent } from './components/background/background.component';
import { LoginSocialComponent } from './pages/login-social/login-social.component';
Expand Down
3 changes: 2 additions & 1 deletion src/app/environment/environment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const EDUPLAY_CLIENT_KEY = "a1cdba06226408fcda63b49c50223c68d56005d234cc98bcdc1ae787d2b4de1d";
export const environment = {
apiURL: 'http://localhost:8000/api'
apiURL: 'https://unb-tv-backend-2be1ed3a0485.herokuapp.com/api',
};
71 changes: 68 additions & 3 deletions src/app/pages/active-account/active-account.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,88 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ActiveAccountComponent } from './active-account.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { AuthService } from 'src/app/services/auth.service';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { of, throwError } from 'rxjs';
import { RouterTestingModule } from '@angular/router/testing';
import { LoginComponent } from '../login/login.component';

const mockData: any = {
"email": "[email protected]",
"code": 123456,
}

class AuthServiceMock {
constructor() { }
activeAccount() {
return of({ success: true });
}
resendCode() {
return of({ success: true });
}
}

describe('ActiveAccountComponent', () => {
let component: ActiveAccountComponent;
let fixture: ComponentFixture<ActiveAccountComponent>;
let authService: AuthService;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ActiveAccountComponent ]
imports: [HttpClientTestingModule, RouterTestingModule.withRoutes(
[
{ path: 'login', component: LoginComponent },
]
), ReactiveFormsModule],
providers: [{ provide: AuthService, useValue: new AuthServiceMock() }, FormBuilder],
declarations: [ActiveAccountComponent]
})
.compileComponents();
.compileComponents();

fixture = TestBed.createComponent(ActiveAccountComponent);
component = fixture.componentInstance;
fixture.detectChanges();
authService = TestBed.inject(AuthService);
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should call activeAccount method when the form is submitted', () => {
fixture.detectChanges();
spyOn(component, 'activeAccount').and.callThrough();
const form = component.userForm;
form.setValue(mockData);

const submitButton = fixture.nativeElement.querySelector(
'button[type="submit"]'
);
submitButton.click();

expect(component.activeAccount).toHaveBeenCalled();
});

it('should call alert when form is not valid', () => {
spyOn(component, 'activeAccount').and.callThrough();
const alertSpy = spyOn(window, 'alert');
fixture.detectChanges();

const submitButton = fixture.nativeElement.querySelector(
'button[type="submit"]'
);
submitButton.click();

expect(alertSpy).toHaveBeenCalledWith('Preencha todos os campos corretamente!');
});

it('should call activeAccount and return an error', () => {
fixture.detectChanges();
const form = component.userForm;
form.setValue(mockData);
const mySpy = spyOn(authService, 'activeAccount').and.returnValue(throwError(() => new Error('Erro')));
component.activeAccount();
expect(mySpy).toHaveBeenCalled();
});

});
Loading

0 comments on commit 2b9ba02

Please sign in to comment.