From c345946703cd65082a04a7aa8825a84a2e045bdc Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 26 Jan 2022 09:27:15 +0100 Subject: [PATCH] chore: added a test to check the secrets context is being updated with the secrets returned from the scmAuthApi Signed-off-by: blam --- .../RepoUrlPicker/RepoUrlPicker.test.tsx | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.test.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.test.tsx index f10dd3ea0e..8456825462 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.test.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.test.tsx @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import React from 'react'; +import React, { useContext } from 'react'; import { RepoUrlPicker } from './RepoUrlPicker'; import Form from '@rjsf/core'; import { renderInTestApp, TestApiProvider } from '@backstage/test-utils'; @@ -24,7 +24,10 @@ import { ScmAuthApi, } from '@backstage/integration-react'; import { scaffolderApiRef } from '../../../api'; -import { SecretsContextProvider } from '../../secrets/SecretsContext'; +import { + SecretsContextProvider, + SecretsContext, +} from '../../secrets/SecretsContext'; import { ScaffolderApi } from '../../..'; import { act, fireEvent } from '@testing-library/react'; @@ -112,7 +115,11 @@ describe('RepoUrlPicker', () => { describe('requestUserCredentials', () => { it('should call the scmAuthApi with the correct params', async () => { - const { getAllByRole } = await renderInTestApp( + const SecretsComponent = () => { + const value = useContext(SecretsContext); + return
{JSON.stringify(value)}
; + }; + const { getAllByRole, getByTestId } = await renderInTestApp( { }} fields={{ RepoUrlPicker: RepoUrlPicker }} /> + , ); @@ -157,8 +165,14 @@ describe('RepoUrlPicker', () => { }, }, }); - }); - // TODO(blam): need a test here for making sure that the secret is pushed to the context + const currentSecrets = JSON.parse( + getByTestId('current-secrets').textContent!, + ); + + expect(currentSecrets).toEqual({ + secrets: { testKey: 'abc123' }, + }); + }); }); });