Skip to content

Commit

Permalink
Team flags refactor (#2331)
Browse files Browse the repository at this point in the history
* refactor some files to not use unnecessary feature flagt

* fix: change multipleTiers to tierValue

* bug: address remaining multipleTier variables
  • Loading branch information
adrian-codecov authored Oct 19, 2023
1 parent 7833ceb commit 1e18241
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 163 deletions.
6 changes: 1 addition & 5 deletions src/pages/AccountSettings/shared/Header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ import config from 'config'

import MyContextSwitcher from 'layouts/MyContextSwitcher'
import { TierNames, useTier } from 'services/tier'
import { useFlags } from 'shared/featureFlags'
import TabNavigation from 'ui/TabNavigation'

function Header() {
const { owner, provider } = useParams()
const { data: tierName } = useTier({ owner, provider })
const { multipleTiers } = useFlags({
multipleTiers: true,
})
return (
<>
<MyContextSwitcher pageName="accountAdmin" />
<TabNavigation
tabs={[
{ pageName: 'owner', children: 'Repos' },
...(tierName === TierNames.TEAM && multipleTiers
...(tierName === TierNames.TEAM
? []
: [
{
Expand Down
22 changes: 8 additions & 14 deletions src/pages/AccountSettings/shared/Header/Header.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import { MemoryRouter, Route } from 'react-router-dom'
import config from 'config'

import { TierNames } from 'services/tier'
import { useFlags } from 'shared/featureFlags'

import Header from './Header'

jest.mock('config')
jest.mock('shared/featureFlags')

const queryClient = new QueryClient()
const server = setupServer()
Expand All @@ -39,20 +37,16 @@ afterAll(() => {

describe('Header', () => {
function setup(
{ isSelfHosted = false, multipleTiers = false } = {
{ isSelfHosted = false, tierValue = TierNames.PRO } = {
isSelfHosted: false,
multipleTiers: false,
tierValue: TierNames.PRO,
}
) {
config.IS_SELF_HOSTED = isSelfHosted

useFlags.mockReturnValue({
multipleTiers,
})

server.use(
graphql.query('OwnerTier', (req, res, ctx) => {
if (multipleTiers) {
if (tierValue === TierNames.TEAM) {
return res(
ctx.status(200),
ctx.data({ owner: { plan: { tierName: TierNames.TEAM } } })
Expand Down Expand Up @@ -149,7 +143,7 @@ describe('Header', () => {

describe('when user has team tier', () => {
it('renders links to the home page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Header />, { wrapper })

expect(
Expand All @@ -160,15 +154,15 @@ describe('Header', () => {
})

it('does not render links to the analytics page', async () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Header />, { wrapper })

const analyticsLink = screen.queryByText(/Analytics/)
await waitFor(() => expect(analyticsLink).not.toBeInTheDocument())
})

it('renders links to the settings page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Header />, { wrapper })

expect(
Expand All @@ -179,7 +173,7 @@ describe('Header', () => {
})

it('renders link to plan page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Header />, { wrapper })

expect(
Expand All @@ -190,7 +184,7 @@ describe('Header', () => {
})

it('renders link to members page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Header />, { wrapper })

expect(
Expand Down
6 changes: 1 addition & 5 deletions src/pages/AnalyticsPage/AnalyticsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useLocationParams } from 'services/navigation'
import { orderingOptions } from 'services/repos'
import { TierNames, useTier } from 'services/tier'
import { useOwner } from 'services/user'
import { useFlags } from 'shared/featureFlags'
import ReposTable from 'shared/ListRepo/ReposTable'
import LoadingLogo from 'ui/LoadingLogo'

Expand Down Expand Up @@ -39,9 +38,6 @@ function AnalyticsPage() {
const { owner, provider } = useParams()
const { data: ownerData } = useOwner({ username: owner })
const { data: tierName } = useTier({ owner, provider })
const { multipleTiers } = useFlags({
multipleTiers: true,
})

const orderOptions = orderingOptions

Expand All @@ -56,7 +52,7 @@ function AnalyticsPage() {
return <NotFound />
}

if (tierName === TierNames.TEAM && multipleTiers) {
if (tierName === TierNames.TEAM) {
return <Redirect to={`/${provider}/${owner}`} />
}

Expand Down
12 changes: 3 additions & 9 deletions src/pages/AnalyticsPage/AnalyticsPage.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { MemoryRouter, Route } from 'react-router-dom'
import { useLocationParams } from 'services/navigation'
import { TierNames } from 'services/tier'
import { useOwner } from 'services/user'
import { useFlags } from 'shared/featureFlags'

import AnalyticsPage from './AnalyticsPage'

Expand All @@ -19,7 +18,6 @@ jest.mock('./Tabs', () => () => 'Tabs')
jest.mock('./ChartSelectors', () => () => 'Chart Selectors')
jest.mock('./Chart', () => () => 'Line Chart')
jest.mock('../../shared/ListRepo/ReposTable', () => () => 'ReposTable')
jest.mock('shared/featureFlags')

const queryClient = new QueryClient()
const server = setupServer()
Expand Down Expand Up @@ -56,7 +54,7 @@ afterAll(() => {
})

describe('AnalyticsPage', () => {
function setup({ owner, params, multipleTiers = false }) {
function setup({ owner, params, tierValue = TierNames.PRO }) {
useOwner.mockReturnValue({
data: owner,
})
Expand All @@ -67,13 +65,9 @@ describe('AnalyticsPage', () => {
},
})

useFlags.mockReturnValue({
multipleTiers,
})

server.use(
graphql.query('OwnerTier', (req, res, ctx) => {
if (multipleTiers) {
if (tierValue === TierNames.TEAM) {
return res(
ctx.status(200),
ctx.data({ owner: { plan: { tierName: TierNames.TEAM } } })
Expand Down Expand Up @@ -194,7 +188,7 @@ describe('AnalyticsPage', () => {
username: 'codecov',
isCurrentUserPartOfOrg: true,
},
multipleTiers: true,
tierValue: TierNames.TEAM,
})
render(<AnalyticsPage />, { wrapper })

Expand Down
6 changes: 1 addition & 5 deletions src/pages/AnalyticsPage/Tabs/Tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@ import { useParams } from 'react-router-dom'
import config from 'config'

import { TierNames, useTier } from 'services/tier'
import { useFlags } from 'shared/featureFlags'
import TabNavigation from 'ui/TabNavigation'

function Tabs() {
const { owner, provider } = useParams()
const { data: tierName } = useTier({ owner, provider })
const { multipleTiers } = useFlags({
multipleTiers: true,
})
return (
<TabNavigation
tabs={[
{
pageName: 'owner',
children: 'Repos',
},
...(tierName === TierNames.TEAM && multipleTiers
...(tierName === TierNames.TEAM
? []
: [
{
Expand Down
22 changes: 8 additions & 14 deletions src/pages/AnalyticsPage/Tabs/Tabs.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import { MemoryRouter, Route } from 'react-router-dom'
import config from 'config'

import { TierNames } from 'services/tier'
import { useFlags } from 'shared/featureFlags'

import Tabs from './Tabs'

jest.mock('config')
jest.mock('shared/featureFlags')

const queryClient = new QueryClient()
const server = setupServer()
Expand All @@ -39,20 +37,16 @@ afterAll(() => {

describe('Tabs', () => {
function setup(
{ isSelfHosted = false, multipleTiers = false } = {
{ isSelfHosted = false, tierValue = TierNames.PRO } = {
isSelfHosted: false,
multipleTiers: false,
tierValue: TierNames.PRO,
}
) {
config.IS_SELF_HOSTED = isSelfHosted

useFlags.mockReturnValue({
multipleTiers,
})

server.use(
graphql.query('OwnerTier', (req, res, ctx) => {
if (multipleTiers) {
if (tierValue === TierNames.TEAM) {
return res(
ctx.status(200),
ctx.data({ owner: { plan: { tierName: TierNames.TEAM } } })
Expand Down Expand Up @@ -125,7 +119,7 @@ describe('Tabs', () => {

describe('when user has team tier', () => {
it('renders links to the home page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Tabs />, { wrapper })

expect(
Expand All @@ -136,15 +130,15 @@ describe('Tabs', () => {
})

it('does not render links to the analytics page', async () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Tabs />, { wrapper })

const analyticsLink = screen.queryByText(/Analytics/)
await waitFor(() => expect(analyticsLink).not.toBeInTheDocument())
})

it('renders links to the settings page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Tabs />, { wrapper })

expect(
Expand All @@ -155,7 +149,7 @@ describe('Tabs', () => {
})

it('renders link to plan page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Tabs />, { wrapper })

expect(
Expand All @@ -166,7 +160,7 @@ describe('Tabs', () => {
})

it('renders link to members page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Tabs />, { wrapper })

expect(
Expand Down
7 changes: 2 additions & 5 deletions src/pages/MembersPage/Tabs/Tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ import { useParams } from 'react-router-dom'
import config from 'config'

import { TierNames, useTier } from 'services/tier'
import { useFlags } from 'shared/featureFlags'
import TabNavigation from 'ui/TabNavigation'

function Tabs() {
const { owner, provider } = useParams()
const { data: tierName } = useTier({ owner, provider })
const { multipleTiers } = useFlags({
multipleTiers: true,
})

return (
<TabNavigation
tabs={[
{
pageName: 'owner',
children: 'Repos',
},
...(tierName === TierNames.TEAM && multipleTiers
...(tierName === TierNames.TEAM
? []
: [
{
Expand Down
22 changes: 8 additions & 14 deletions src/pages/MembersPage/Tabs/Tabs.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import { MemoryRouter, Route } from 'react-router-dom'
import config from 'config'

import { TierNames } from 'services/tier'
import { useFlags } from 'shared/featureFlags'

import Tabs from './Tabs'

jest.mock('config')
jest.mock('shared/featureFlags')

const queryClient = new QueryClient()
const server = setupServer()
Expand All @@ -39,20 +37,16 @@ afterAll(() => {

describe('Tabs', () => {
function setup(
{ isSelfHosted = false, multipleTiers = false } = {
{ isSelfHosted = false, tierValue = TierNames.PRO } = {
isSelfHosted: false,
multipleTiers: false,
tierValue: TierNames.PRO,
}
) {
config.IS_SELF_HOSTED = isSelfHosted

useFlags.mockReturnValue({
multipleTiers,
})

server.use(
graphql.query('OwnerTier', (req, res, ctx) => {
if (multipleTiers) {
if (tierValue === TierNames.TEAM) {
return res(
ctx.status(200),
ctx.data({ owner: { plan: { tierName: TierNames.TEAM } } })
Expand Down Expand Up @@ -149,7 +143,7 @@ describe('Tabs', () => {

describe('when user has team tier', () => {
it('renders links to the home page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Tabs />, { wrapper })

expect(
Expand All @@ -160,15 +154,15 @@ describe('Tabs', () => {
})

it('does not render links to the analytics page', async () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Tabs />, { wrapper })

const analyticsLink = screen.queryByText(/Analytics/)
await waitFor(() => expect(analyticsLink).not.toBeInTheDocument())
})

it('renders links to the settings page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Tabs />, { wrapper })

expect(
Expand All @@ -179,7 +173,7 @@ describe('Tabs', () => {
})

it('renders link to plan page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Tabs />, { wrapper })

expect(
Expand All @@ -190,7 +184,7 @@ describe('Tabs', () => {
})

it('renders link to members page', () => {
setup({ multipleTiers: true })
setup({ tierValue: TierNames.TEAM })
render(<Tabs />, { wrapper })

expect(
Expand Down
Loading

0 comments on commit 1e18241

Please sign in to comment.