Skip to content

Commit

Permalink
Merge pull request #806 from cloud-pi-native/feat/stage-management-ad…
Browse files Browse the repository at this point in the history
…min#802

Feat/stage management admin#802
  • Loading branch information
clairenollet committed Nov 10, 2023
2 parents 215023b + e133853 commit 36235c1
Show file tree
Hide file tree
Showing 56 changed files with 2,056 additions and 229 deletions.
115 changes: 115 additions & 0 deletions apps/client/cypress/components/specs/stage-form.ct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import '@gouvfr/dsfr/dist/dsfr.min.css'
import '@gouvfr/dsfr/dist/utility/icons/icons.min.css'
import '@gouvfr/dsfr/dist/utility/utility.main.min.css'
import '@gouvminint/vue-dsfr/styles'
import '@/main.css'
import StageForm from '@/components/StageForm.vue'
import { getRandomCluster, getRandomEnv, getRandomQuota, getRandomQuotaStage, getRandomStage, repeatFn } from '@dso-console/test-utils'

describe('StageForm.vue', () => {
it('Should mount a new quota StageForm', () => {
const allQuotas = repeatFn(4)(getRandomQuota)
const allClusters = repeatFn(3)(getRandomCluster)

const props = {
isNewStage: true,
allQuotas,
allClusters,
}

cy.mount(StageForm, { props })
cy.get('h1').invoke('text').should('match', /^Informations du stage $/)
cy.getByDataTestid('updateStageBtn').should('not.exist')
cy.getByDataTestid('addStageBtn').should('be.visible').and('be.disabled')
cy.getByDataTestid('nameInput')
.find('input')
.type('integ')
cy.get('h1').invoke('text').should('match', /^Informations du stage integ$/)
cy.getByDataTestid('addStageBtn').should('be.enabled')
cy.get('#quotas-select')
.select(`${allQuotas[1].name}`)
cy.get('#clusters-select')
.select(`${allClusters[0].label}`)
cy.get('#clusters-select')
.select(`${allClusters[1].label}`)
cy.getByDataTestid('addStageBtn').should('be.enabled')
})

it('Should mount an update stage StageForm', () => {
const allQuotas = repeatFn(4)(getRandomQuota)
const allClusters = repeatFn(3)(getRandomCluster)
const stageToUpdate = getRandomStage()
const quotaStage = getRandomQuotaStage(allQuotas[0].id, stageToUpdate.id, 'active')
// @ts-ignore
stageToUpdate.quotaStage = [quotaStage]
// @ts-ignore
stageToUpdate.clusters = [allClusters[0]]
const associatedEnvironments = [getRandomEnv('env1', 'projectId', quotaStage.id, allClusters[0].id), getRandomEnv('env2', 'projectId', quotaStage.id, allClusters[1].id)]

const props = {
stage: stageToUpdate,
allQuotas,
allClusters,
associatedEnvironments,
}

cy.mount(StageForm, { props })
cy.get('h1').invoke('text').should('contain', `Informations du stage ${stageToUpdate.name}`)
cy.getByDataTestid('addStageBtn').should('not.exist')
cy.getByDataTestid('updateStageBtn').should('be.visible').and('be.enabled')
cy.getByDataTestid('nameInput')
.find('input')
.should('have.value', stageToUpdate.name)
.and('be.disabled')
cy.getByDataTestid(`${allQuotas[0].name}-quotas-select-tag`)
.should('exist')
cy.get('#quotas-select')
.should('be.enabled')
cy.getByDataTestid(`${allClusters[0].label}-clusters-select-tag`)
.should('exist')
cy.get('#clusters-select')
.should('be.enabled')
cy.getByDataTestid('updateStageBtn').should('be.enabled')
cy.getByDataTestid('deleteQuotaZone').should('not.exist')
cy.getByDataTestid('associatedEnvironmentsTable').should('exist')
.find('tbody > tr')
.should('have.length', associatedEnvironments.length)
})

it('Should mount an update quotaForm without associatedEnvironments', () => {
const allQuotas = repeatFn(4)(getRandomQuota)
const allClusters = repeatFn(3)(getRandomCluster)
const stageToUpdate = getRandomStage()
const quotaStage = getRandomQuotaStage(allQuotas[0].id, stageToUpdate.id, 'active')
// @ts-ignore
stageToUpdate.quotaStage = [quotaStage]
// @ts-ignore
stageToUpdate.clusters = [allClusters[0]]

const props = {
stage: stageToUpdate,
allQuotas,
allClusters,
}

cy.mount(StageForm, { props })
cy.get('h1').invoke('text').should('contain', `Informations du stage ${stageToUpdate.name}`)
cy.getByDataTestid('addStageBtn').should('not.exist')
cy.getByDataTestid('updateStageBtn').should('be.visible').and('be.enabled')
cy.getByDataTestid('nameInput')
.find('input')
.should('have.value', stageToUpdate.name)
.and('be.disabled')
cy.getByDataTestid(`${allQuotas[0].name}-quotas-select-tag`)
.should('exist')
cy.get('#quotas-select')
.should('be.enabled')
cy.getByDataTestid(`${allClusters[0].label}-clusters-select-tag`)
.should('exist')
cy.get('#clusters-select')
.should('be.enabled')
cy.getByDataTestid('updateStageBtn').should('be.enabled')
cy.getByDataTestid('associatedEnvironmentsZone').should('not.exist')
cy.getByDataTestid('deleteStageZone').should('exist')
})
})
4 changes: 2 additions & 2 deletions apps/client/cypress/e2e/specs/admin/clusters.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ describe('Administration clusters', () => {
}

beforeEach(() => {
cy.intercept('GET', 'api/v1/admin/clusters').as('getAllClusters')
cy.intercept('GET', 'api/v1/clusters').as('getClusters')
cy.intercept('GET', '/api/v1/admin/projects').as('getAdminProjects')
cy.intercept('GET', '/api/v1/stages').as('getStages')

cy.kcLogin('tcolin')
cy.visit('/admin/clusters')
cy.url().should('contain', '/admin/clusters')
cy.wait('@getAllClusters').its('response').then(response => {
cy.wait('@getClusters').its('response').then(response => {
allClusters = response.body
cluster1.stages = allClusters
.find(cluster => cluster.id === cluster1.id)
Expand Down
27 changes: 18 additions & 9 deletions apps/client/cypress/e2e/specs/admin/quotas.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ describe('Administration quotas', () => {
let allQuotas

beforeEach(() => {
cy.intercept('GET', 'api/v1/quotas').as('getAllQuotas')
cy.intercept('GET', '/api/v1/stages').as('getAllStages')
cy.intercept('GET', 'api/v1/quotas').as('getQuotas')
cy.intercept('GET', '/api/v1/stages').as('getStages')

cy.kcLogin('tcolin')
cy.visit('/admin/quotas')
cy.url().should('contain', '/admin/quotas')
cy.wait('@getAllQuotas').its('response').then(response => {
cy.wait('@getQuotas').its('response').then(response => {
allQuotas = response.body
quota1 = allQuotas.find(quota => quota.id === quota1.id)
quota2 = allQuotas.find(quota => quota.id === quota2.id)
})
cy.wait('@getAllStages')
cy.wait('@getStages')
})

it('Should display quotas list', () => {
Expand All @@ -44,6 +44,7 @@ describe('Administration quotas', () => {

it('Should create a public quota', () => {
cy.intercept('POST', '/api/v1/admin/quotas').as('createQuota')
cy.intercept('GET', 'api/v1/clusters').as('getClusters')
cy.intercept('GET', 'api/v1/stages').as('getStages')
cy.intercept('GET', 'api/v1/quotas').as('getQuotas')
cy.intercept('GET', '/api/v1/projects').as('getProjects')
Expand Down Expand Up @@ -87,7 +88,7 @@ describe('Administration quotas', () => {

// Check quota creation
cy.reload()
.wait('@getAllStages')
.wait('@getStages')
cy.getByDataTestid(`quotaTile-${publicQuota.name}`)
.should('be.visible')
.click()
Expand Down Expand Up @@ -121,6 +122,7 @@ describe('Administration quotas', () => {
.getByDataTestid(`projectTile-${project?.name}`).click()
.getByDataTestid('menuEnvironments').click()
.url().should('contain', '/environments')
cy.wait('@getClusters')
cy.getByDataTestid('addEnvironmentLink').click()
cy.wait('@getStages')
cy.wait('@getQuotas')
Expand All @@ -142,6 +144,7 @@ describe('Administration quotas', () => {
.getByDataTestid(`projectTile-${project?.name}`).click()
.getByDataTestid('menuEnvironments').click()
.url().should('contain', '/environments')
cy.wait('@getClusters')
cy.getByDataTestid('addEnvironmentLink').click()
cy.wait('@getStages')
cy.wait('@getQuotas')
Expand Down Expand Up @@ -196,6 +199,7 @@ describe('Administration quotas', () => {

it('Should create a private quota', () => {
cy.intercept('POST', '/api/v1/admin/quotas').as('createQuota')
cy.intercept('GET', 'api/v1/clusters').as('getClusters')
cy.intercept('GET', 'api/v1/stages').as('getStages')
cy.intercept('GET', 'api/v1/quotas').as('getQuotas')
cy.intercept('GET', '/api/v1/projects').as('getProjects')
Expand Down Expand Up @@ -240,7 +244,7 @@ describe('Administration quotas', () => {

// Check quota creation
cy.reload()
.wait('@getAllStages')
.wait('@getStages')
cy.getByDataTestid(`quotaTile-${privateQuota.name}`)
.should('be.visible')
.click()
Expand Down Expand Up @@ -274,6 +278,7 @@ describe('Administration quotas', () => {
.getByDataTestid(`projectTile-${project?.name}`).click()
.getByDataTestid('menuEnvironments').click()
.url().should('contain', '/environments')
cy.wait('@getClusters')
cy.getByDataTestid('addEnvironmentLink').click()
cy.wait('@getStages')
cy.wait('@getQuotas')
Expand All @@ -290,6 +295,7 @@ describe('Administration quotas', () => {
.getByDataTestid(`projectTile-${project?.name}`).click()
.getByDataTestid('menuEnvironments').click()
.url().should('contain', '/environments')
cy.wait('@getClusters')
cy.getByDataTestid('addEnvironmentLink').click()
cy.wait('@getStages')
cy.wait('@getQuotas')
Expand All @@ -305,7 +311,8 @@ describe('Administration quotas', () => {
const newStage = allStages?.find(stage => !publicQuota.stages?.find(pqStage => pqStage.id === stage.id))

cy.intercept('PUT', '/api/v1/admin/quotas/quotastages').as('updateQuotaStage')
cy.intercept('PATCH', '/api/v1/admin/quotas/*').as('updateQuotaPrivacy')
cy.intercept('PATCH', '/api/v1/admin/quotas/*/privacy').as('updateQuotaPrivacy')
cy.intercept('GET', 'api/v1/clusters').as('getClusters')
cy.intercept('GET', 'api/v1/stages').as('getStages')
cy.intercept('GET', 'api/v1/quotas').as('getQuotas')
cy.intercept('GET', '/api/v1/projects').as('getProjects')
Expand Down Expand Up @@ -350,7 +357,7 @@ describe('Administration quotas', () => {

// Check quota update
cy.reload()
.wait('@getAllStages')
.wait('@getStages')
cy.getByDataTestid(`quotaTile-${publicQuota.name}`)
.should('be.visible')
.click()
Expand Down Expand Up @@ -384,6 +391,7 @@ describe('Administration quotas', () => {
.getByDataTestid(`projectTile-${project?.name}`).click()
.getByDataTestid('menuEnvironments').click()
.url().should('contain', '/environments')
cy.wait('@getClusters')
cy.getByDataTestid('addEnvironmentLink').click()
cy.wait('@getStages')
cy.wait('@getQuotas')
Expand All @@ -400,6 +408,7 @@ describe('Administration quotas', () => {
.getByDataTestid(`projectTile-${project?.name}`).click()
.getByDataTestid('menuEnvironments').click()
.url().should('contain', '/environments')
cy.wait('@getClusters')
cy.getByDataTestid('addEnvironmentLink').click()
cy.wait('@getStages')
cy.wait('@getQuotas')
Expand Down Expand Up @@ -480,8 +489,8 @@ describe('Administration quotas', () => {
cy.getByDataTestid('updateQuotaBtn').should('be.enabled')
cy.get('[data-testid$="stages-select-tag"]')
.should('have.length', quota2.quotaStage.length)
cy.getByDataTestid('associatedEnvironmentsZone').should('not.exist')
cy.getByDataTestid('deleteQuotaZone').should('not.exist')
cy.getByDataTestid('associatedEnvironmentsZone').should('exist')
cy.getByDataTestid('associatedEnvironmentsTable').should('exist')
})

Expand Down
Loading

0 comments on commit 36235c1

Please sign in to comment.