Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
Remove deprecated code (#355)
Browse files Browse the repository at this point in the history
* remove deprecated code

* remove deprecated code

* fixing ci

* removing deprecated fetch

* reversing changes in middleware file

* revert unnecessary change

Co-authored-by: tayronearaujo <[email protected]>
  • Loading branch information
tayronemachadozup and tayronearaujo authored Sep 10, 2021
1 parent 26d6a71 commit f59b62a
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 692 deletions.
7 changes: 2 additions & 5 deletions __tests__/integration/beagle-keep/frontend/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@

import { uniqueId } from 'lodash'
import BeagleService from 'service/beagle-service'
import { BeagleConfig } from 'service/beagle-service/types'
import Tree from 'beagle-tree'
import { NetworkOptions } from 'beagle-view/types'
import createConfig, { ConfigOptions } from './config'

interface ViewParams {
route?: string,
networkOptions?: NetworkOptions,
initialController?: string,
}

function start(options?: ConfigOptions) {
const service = BeagleService.create(createConfig(options))

async function createBeagleRemoteView({ networkOptions, initialController, route }: ViewParams) {
const view = service.createView(networkOptions, initialController)
async function createBeagleRemoteView({ initialController, route }: ViewParams) {
const view = service.createView(initialController)
const viewId = uniqueId()
service.viewContentManagerMap.register(viewId, view)

Expand Down
52 changes: 0 additions & 52 deletions __tests__/unit/beagle-service/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe('Beagle Service: configuration', () => {
expect(() => Configuration.validate(mockConfig)).toThrow(expect.any(BeagleError))
})


it('should keep two operations with the same name (case-insensitive)', () => {
const mockConfig: BeagleConfig<any> = {
baseUrl: 'url.com',
Expand All @@ -59,57 +58,6 @@ describe('Beagle Service: configuration', () => {
})
})

describe('Beagle Service: configuration: update legacy', () => {
it('should interpret middlewares as the global lifecycle hook for beforeViewSnapshot', () => {
const middleware1 = jest.fn(t => ({ ...t, m1: true }))
const middleware2 = jest.fn(t => ({ ...t, m2: true }))
const config: BeagleConfig<any> = {
baseUrl: '',
components: {},
middlewares: [middleware1, middleware2],
}

Configuration.update(config)

expect(config.lifecycles!.beforeViewSnapshot).toBeDefined()
const tree = { _beagleComponent_: 'beagle:container', id: '1' }
const returnValue = config.lifecycles!.beforeViewSnapshot!(tree)
expect(middleware1).toHaveBeenCalledWith(tree)
expect(middleware2).toHaveBeenCalledWith({ ...tree, m1: true })
})

function shouldExecuteBothLifecycleAndMiddlewares(isLifecyclePure: boolean) {
const beforeViewSnapshot = jest.fn(t => {
if (isLifecyclePure) return { ...t, bfs: true }
t.bfs = true
})
const middleware1 = jest.fn(t => ({ ...t, m1: true }))
const middleware2 = jest.fn(t => ({ ...t, m2: true }))
const config: BeagleConfig<any> = {
baseUrl: '',
components: {},
middlewares: [middleware1, middleware2],
lifecycles: { beforeViewSnapshot },
}

Configuration.update(config)

const tree = { _beagleComponent_: 'beagle:container', id: '1' }
const returnValue = config.lifecycles!.beforeViewSnapshot!(tree)
expect(beforeViewSnapshot).toHaveBeenCalledWith(tree)
expect(middleware1).toHaveBeenCalledWith({ ...tree, bfs: true })
expect(middleware2).toHaveBeenCalledWith({ ...tree, bfs: true, m1: true })
}

it('should execute both middlewares and the global beforeViewSnapshot (pure)', () => {
shouldExecuteBothLifecycleAndMiddlewares(true)
})

it('should execute both middlewares and the global beforeViewSnapshot (impure)', () => {
shouldExecuteBothLifecycleAndMiddlewares(false)
})
})

describe('Beagle Service: configuration: component metadata', () => {
it('should create global lifecycles', () => {
const beforeStart = jest.fn()
Expand Down
32 changes: 2 additions & 30 deletions __tests__/unit/beagle-view/beagle-view.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import BeagleView from 'beagle-view'
import { BeagleView as BeagleViewType, NetworkOptions } from 'beagle-view/types'
import { BeagleView as BeagleViewType } from 'beagle-view/types'
import { HttpAdditionalData, NavigationController } from 'beagle-view/navigator/types'
import { BeagleService, BeagleConfig } from 'service/beagle-service/types'
import * as Renderer from 'beagle-view/render'
Expand All @@ -28,20 +28,6 @@ import {

describe('Beagle View', () => {
describe('general behavior', () => {
it('should return a copy of the NetworkOptions', () => {
const beagleService = createBeagleServiceMock()
const networkOptions: NetworkOptions = { strategy: 'network-only' }
const beagleView = BeagleView.create(beagleService, networkOptions)
expect(beagleView.getNetworkOptions()).not.toBe(networkOptions)
expect(beagleView.getNetworkOptions()).toEqual(networkOptions)
})

it('should return undefined if no NetworkOptions is provided', () => {
const beagleService = createBeagleServiceMock()
const beagleView = BeagleView.create(beagleService)
expect(beagleView.getNetworkOptions()).toBeUndefined()
})

it('should disable css on renderer', () => {
const originalCreateRenderer = Renderer.default.create
Renderer.default.create = jest.fn()
Expand Down Expand Up @@ -100,24 +86,10 @@ describe('Beagle View', () => {
})

it('should apply initial navigation controller', () => {
beagleView = BeagleView.create(beagleService, {}, 'secured')
beagleView = BeagleView.create(beagleService, 'secured')
expect(beagleView.getNavigator().get()).toEqual([{ routes: [], controllerId: 'secured' }])
})

it('should use network options', () => {
const networkOptions: NetworkOptions = {
method: 'POST',
headers: { testHeader: 'test-header' },
strategy: 'network-only',
}
beagleView = BeagleView.create(beagleService, networkOptions)
beagleView.getNavigator().pushStack({ url: '/home' })
expect(beagleService.viewClient.load).toHaveBeenCalledWith(expect.objectContaining({
url: 'base/home',
...networkOptions,
}))
})

it('should navigate to remote route', async () => {
await beagleView.getNavigator().pushView({
url: '/home',
Expand Down
42 changes: 0 additions & 42 deletions __tests__/unit/old-structure/BeagleAnalytics.spec.ts

This file was deleted.

91 changes: 0 additions & 91 deletions __tests__/unit/old-structure/BeagleContext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
import nock from 'nock'
import BeagleService from 'service/beagle-service'
import { BeagleView } from 'beagle-view/types'
import Tree from 'beagle-tree'
import {
createBeagleContextFromViewContentManager,
BeagleContext,
} from '../../../src/legacy/beagle-context'
import { treeA, treeC, treeD } from './mocks'
import { mockLocalStorage } from './utils/test-utils'
import {ViewContentManager} from "service/view-content-manager/types";
Expand Down Expand Up @@ -143,90 +138,4 @@ describe('BeagleContext (Legacy)', () => {
afterAll(() => {
localStorageMock.unmock()
})

it('should create a context for a view', async () => {
const context = createBeagleContextFromViewContentManager(
viewContentManagerMap.get(viewId, 'A.1'),
)

expect(context.getView).toBeDefined()
expect(context.getElement).toBeDefined()
expect(context.getElementId).toBeDefined()
expect(context.append).toBeDefined()
expect(context.prepend).toBeDefined()
expect(context.replace).toBeDefined()
expect(context.updateWithTree).toBeDefined()
})

it('should get view, element and elementId from context', () => {
const context = createBeagleContextFromViewContentManager(
viewContentManagerMap.get(viewId, 'A.1'),
)

expect(context.getView).toBeDefined()
const getView = context.getView()
expect(getView).toEqual(view)

expect(context.getElement).toBeDefined()
const element = context.getElement()
expect(element).toStrictEqual(treeA.children![1])

expect(context.getElementId).toBeDefined()
const elementId = context.getElementId()
expect(elementId).toBe('A.1')
})

it('should replace current view from context', async () => {
const context = createBeagleContextFromViewContentManager(
viewContentManagerMap.get(viewId, 'A.1'),
)
nock(baseUrl).get(path).reply(200, JSON.stringify(treeC))
const currentTree = context.getView().getTree()

await context.replace({ path })
const replacedTree = Tree.clone(currentTree)
replacedTree.children![1] = treeC
expect(context.getView().getTree()).toStrictEqual(replacedTree)
expect(nock.isDone()).toBe(true)
})

it('should append from context', async () => {
const context = createBeagleContextFromViewContentManager(
viewContentManagerMap.get(viewId, 'A'),
)
nock(baseUrl).get(path).reply(200, JSON.stringify(treeD))
const currentTree = context.getView().getTree()

await context.append({ path })
const appendedTree = Tree.clone(currentTree)
appendedTree.children!.push(treeD)
expect(context.getView().getTree()).toStrictEqual(appendedTree)
expect(nock.isDone()).toBe(true)
})

it('should prepend from context', async () => {
const context = createBeagleContextFromViewContentManager(
viewContentManagerMap.get(viewId, 'A'),
)
nock(baseUrl).get(path).reply(200, JSON.stringify(treeD))
const currentTree = context.getView().getTree()

await context.prepend({ path })
const prependedTree = Tree.clone(currentTree)
prependedTree.children!.unshift(treeD)
expect(context.getView().getTree()).toStrictEqual(prependedTree)
expect(nock.isDone()).toBe(true)
})

it('should replace even if root element', async () => {
const context = createBeagleContextFromViewContentManager(
viewContentManagerMap.get(viewId, 'A'),
)
context.updateWithTree({ sourceTree: treeA })
nock(baseUrl).get(path).reply(200, JSON.stringify(treeC))

await context.replace({ path })
expect(context.getView().getTree()).toStrictEqual(treeC)
expect(nock.isDone()).toBe(true)
})
})
13 changes: 0 additions & 13 deletions __tests__/unit/old-structure/BeagleHttpClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ describe.only('BeagleHttpClient', () => {
expect(nock.isDone()).toBe(true)
})

// todo: remove this, we should not test the browser's default fetch function
it('should use options when fetching content from server', async () => {
const { httpClient } = BeagleService.create({ baseUrl: '', components: {} })
const path = '/example';
nock(url, { reqheaders: { test: 'test' } })
.post(path, (body) => body.test).reply(200, { status: 'OK' })
const body = new URLSearchParams()
body.set('test', 'test')
const parametersOptions = { body, headers: { test: 'test' }, method: 'post' }
await httpClient.fetch(url + path, parametersOptions)
expect(nock.isDone()).toBe(true)
})

it('should use custom fetch function', async () => {
const fetchData = jest.fn()
const { httpClient } = BeagleService.create({ baseUrl: '', components: {}, fetchData })
Expand Down
Loading

0 comments on commit f59b62a

Please sign in to comment.