From e03b5daaff505a9992b1d64c2a39c90481c4db1a Mon Sep 17 00:00:00 2001 From: danis Date: Tue, 3 Jan 2023 19:16:49 +0300 Subject: [PATCH] save dev --- .github/workflows/front-docker.yml | 67 +++++++++++++++++++ front/Dockerfile.test | 7 ++ front/views/AuthenticationView.test.tsx | 29 +++++--- front/views/HomeView.test.tsx | 26 ++++--- front/views/SettingsView.test.tsx | 22 +++--- .../AuthenticationView.test.tsx.snap | 3 + .../__snapshots__/HomeView.test.tsx.snap | 3 + .../__snapshots__/SettingsView.test.tsx.snap | 5 ++ 8 files changed, 133 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/front-docker.yml create mode 100644 front/Dockerfile.test create mode 100644 front/views/__snapshots__/AuthenticationView.test.tsx.snap create mode 100644 front/views/__snapshots__/HomeView.test.tsx.snap create mode 100644 front/views/__snapshots__/SettingsView.test.tsx.snap diff --git a/.github/workflows/front-docker.yml b/.github/workflows/front-docker.yml new file mode 100644 index 0000000..a08b831 --- /dev/null +++ b/.github/workflows/front-docker.yml @@ -0,0 +1,67 @@ +# name: Build + +# on: +# push: +# branches: +# - 'main' +# pull_request: +# branches: [ main ] +# workflow_dispatch: + +# jobs: +# build_front: +# name: Run tests in docker +# runs-on: ubuntu-latest +# defaults: +# run: +# working-directory: ./front/ +# steps: +# -name: checkout the repo +# uses: actions/checkout@v3 +# runs: +# action.yml +# name: 'Hello World' +# description: 'Greet someone and record the time' +# inputs: +# who-to-greet: # id of input +# description: 'Who to greet' +# required: true +# default: 'World' +# outputs: +# time: # id of output +# description: 'The time we greeted you' +# runs: +# using: 'docker' +# image: 'Dockerfile.test' + +name: ci-front + +on: + push: + branches: + - "main" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + file: ./Dockerfile.test + push: true + # tags: ${{ secrets.DOCKER_HUB_USERNAME }}/clockbox:latest diff --git a/front/Dockerfile.test b/front/Dockerfile.test new file mode 100644 index 0000000..1e1af47 --- /dev/null +++ b/front/Dockerfile.test @@ -0,0 +1,7 @@ +# run tests +FROM node:17 +WORKDIR /app +COPY package.json yarn.lock ./ +RUN yarn install +RUN yarn global add expo-cli +RUN yarn test \ No newline at end of file diff --git a/front/views/AuthenticationView.test.tsx b/front/views/AuthenticationView.test.tsx index 3006d1c..564593d 100644 --- a/front/views/AuthenticationView.test.tsx +++ b/front/views/AuthenticationView.test.tsx @@ -1,32 +1,39 @@ import React from 'react'; -import { Provider } from 'react-redux'; -import { fireEvent, render, screen } from '@testing-library/react-native'; -import store from '../state/Store'; +// import { Provider } from 'react-redux'; +// import { fireEvent, render, screen } from '@testing-library/react-native'; +// import store from '../state/Store'; import AuthenticationView from '../views/AuthenticationView'; -import { en, fr } from '../i18n/Translations'; -import { useLanguage } from '../state/LanguageSlice'; +// import { en, fr } from '../i18n/Translations'; +// import { useLanguage } from '../state/LanguageSlice'; import renderer from 'react-test-renderer' import { NativeBaseProvider } from "native-base"; import Theme from '../Theme'; -import { setUserToken } from '../state/UserSlice'; +// import { setUserToken } from '../state/UserSlice'; describe('AuthenticationView Component', () => { jest.setTimeout(150000); const view = () => ; - beforeEach(() => render(view())); + // beforeEach(() => render(view())); it('view should render', () => { - expect(screen).toBeDefined(); + const tree = renderer.create(view()).toJSON; + expect(tree).toMatchSnapshot(); + // expect(screen).toBeDefined(); }); + + // it('should fail', () => { + // expect(AuthenticationView.) + // }); + // it('should render forms', async () => { // expect(await screen.findByDisplayValue('username')).toBeTruthy(); // }); - it('renders the submit button', () => { - expect(screen.findAllByText('en.signinBtn')).toBeTruthy(); - }); + // it('renders the submit button', () => { + // expect(screen.findAllByText('en.signinBtn')).toBeTruthy(); + // }); // it('renders the forms', async () => { // expect(screen.findAllByPlaceholderText) // }) diff --git a/front/views/HomeView.test.tsx b/front/views/HomeView.test.tsx index 5e53078..b2445c2 100644 --- a/front/views/HomeView.test.tsx +++ b/front/views/HomeView.test.tsx @@ -1,22 +1,30 @@ import React from 'react'; -import { Provider } from 'react-redux'; -import store from '../state/Store'; -import { fireEvent, render, screen } from '@testing-library/react-native'; +// import { Provider } from 'react-redux'; +// import store from '../state/Store'; +// import { fireEvent, render, screen } from '@testing-library/react-native'; import { NativeBaseProvider } from "native-base"; import Theme from '../Theme'; import HomeView from './HomeView'; -import { en, fr } from '../i18n/Translations'; +// import { en, fr } from '../i18n/Translations'; +import renderer from 'react-test-renderer' + describe('', () => { jest.setTimeout(150000); - const view = () => ; - beforeEach(() => render(view())); + // const view = () => ; + // beforeEach(() => render(view())); - it('should render correctly', () => { - expect(screen).toBeDefined(); - }) + // it('should render correctly', () => { + // expect(screen).toBeDefined(); + // }) + //const View = () => ; + + it('Main View should render correctly', async () => { + const tree = renderer.create().toJSON; + expect(tree).toMatchSnapshot(); + }); // it('has should display the text in default language', async () => { diff --git a/front/views/SettingsView.test.tsx b/front/views/SettingsView.test.tsx index aa9402c..e088fcf 100644 --- a/front/views/SettingsView.test.tsx +++ b/front/views/SettingsView.test.tsx @@ -1,24 +1,28 @@ import React from 'react'; -import { Provider } from 'react-redux'; -import TestRenderer from 'react-test-renderer'; -import store from '../state/Store'; +// import { Provider } from 'react-redux'; +// import TestRenderer from 'react-test-renderer'; +// import store from '../state/Store'; import { Button, NativeBaseProvider } from "native-base"; import Theme from '../Theme'; -import { fireEvent, render, screen } from '@testing-library/react-native'; +// import { fireEvent, render, screen } from '@testing-library/react-native'; +import renderer from 'react-test-renderer' - -import { MainView, PreferencesView } from './SettingsView' +// import { MainView, PreferencesView } from './SettingsView' describe('testing Setting\'s main view', () => { jest.setTimeout(150000); const MainView = () => ; const PreferencesView = () => ; - render(MainView()); it('Main View should render correctly', async () => { - - expect(screen.findAllByText('en.prefBtn')).toBeTruthy(); + const tree = renderer.create(MainView()).toJSON; + expect(tree).toMatchSnapshot(); + }); + + it('Preference View should render correctly', async () => { + const tree = renderer.create(PreferencesView()).toJSON; + expect(tree).toMatchSnapshot(); }) // it('Preference View should render correctly', async() => { diff --git a/front/views/__snapshots__/AuthenticationView.test.tsx.snap b/front/views/__snapshots__/AuthenticationView.test.tsx.snap new file mode 100644 index 0000000..67de779 --- /dev/null +++ b/front/views/__snapshots__/AuthenticationView.test.tsx.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AuthenticationView Component view should render 1`] = `[Function]`; diff --git a/front/views/__snapshots__/HomeView.test.tsx.snap b/front/views/__snapshots__/HomeView.test.tsx.snap new file mode 100644 index 0000000..5d66f46 --- /dev/null +++ b/front/views/__snapshots__/HomeView.test.tsx.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` Main View should render correctly 1`] = `[Function]`; diff --git a/front/views/__snapshots__/SettingsView.test.tsx.snap b/front/views/__snapshots__/SettingsView.test.tsx.snap new file mode 100644 index 0000000..471f62a --- /dev/null +++ b/front/views/__snapshots__/SettingsView.test.tsx.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`testing Setting's main view Main View should render correctly 1`] = `[Function]`; + +exports[`testing Setting's main view Preference View should render correctly 1`] = `[Function]`;