Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
037499a6
Commit
037499a6
authored
Jan 30, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[skip ci] testing feature flags
parent
4374a6f3
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
97 additions
and
21 deletions
+97
-21
.env.example
.env.example
+2
-1
playwright-ct.config.ts
playwright-ct.config.ts
+3
-0
contextWithEnvs.ts
playwright/fixtures/contextWithEnvs.ts
+2
-14
contextWithFeatures.ts
playwright/fixtures/contextWithFeatures.ts
+18
-0
createContextWithStorage.ts
playwright/fixtures/createContextWithStorage.ts
+14
-0
useFeatureValue.js
playwright/mocks/lib/growthbook/useFeatureValue.js
+25
-0
Login.pw.tsx
ui/pages/Login.pw.tsx
+25
-0
Burger.pw.tsx
ui/snippets/header/Burger.pw.tsx
+3
-2
NavigationDesktop.pw.tsx
ui/snippets/navigation/NavigationDesktop.pw.tsx
+5
-4
No files found.
.env.example
View file @
037499a6
...
...
@@ -6,4 +6,5 @@ NEXT_PUBLIC_GOOGLE_ANALYTICS_PROPERTY_ID=UA-XXXXXX-X
NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN=xxx
NEXT_PUBLIC_GROWTH_BOOK_CLIENT_KEY=xxx
NEXT_PUBLIC_AUTH0_CLIENT_ID=xxx
FAVICON_GENERATOR_API_KEY=xxx
\ No newline at end of file
FAVICON_GENERATOR_API_KEY=xxx
NEXT_PUBLIC_GROWTH_BOOK_CLIENT_KEY=xxx
\ No newline at end of file
playwright-ct.config.ts
View file @
037499a6
...
...
@@ -65,6 +65,9 @@ const config: PlaywrightTestConfig = defineConfig({
// so for now we just mock these modules in tests
'
@metamask/post-message-stream
'
:
'
./playwright/mocks/modules/@metamask/post-message-stream.js
'
,
'
@metamask/providers
'
:
'
./playwright/mocks/modules/@metamask/providers.js
'
,
// Mock for growthbook to test feature flags
'
lib/growthbook/useFeatureValue
'
:
'
./playwright/mocks/lib/growthbook/useFeatureValue.js
'
,
},
},
define
:
{
...
...
playwright/fixtures/contextWithEnvs.ts
View file @
037499a6
import
type
{
test
}
from
'
@playwright/experimental-ct-react
'
;
import
type
{
Browser
}
from
'
@playwright/test
'
;
import
*
as
app
from
'
playwright/utils/app
'
;
import
createContextWithStorage
from
'
./createContextWithStorage
'
;
interface
Env
{
name
:
string
;
...
...
@@ -11,20 +10,9 @@ interface Env {
// keep in mind that all passed variables here should be present in env config files (.env.pw or .env.poa)
export
default
function
contextWithEnvsFixture
(
envs
:
Array
<
Env
>
):
Parameters
<
typeof
test
.
extend
>
[
0
][
'
context
'
]
{
return
async
({
browser
},
use
)
=>
{
const
context
=
await
createContextWith
Envs
(
browser
,
envs
);
const
context
=
await
createContextWith
Storage
(
browser
,
envs
);
await
use
(
context
);
await
context
.
close
();
};
}
export
async
function
createContextWithEnvs
(
browser
:
Browser
,
envs
:
Array
<
Env
>
)
{
return
browser
.
newContext
({
storageState
:
{
origins
:
[
{
origin
:
app
.
url
,
localStorage
:
envs
},
],
cookies
:
[],
},
});
}
playwright/fixtures/contextWithFeatures.ts
0 → 100644
View file @
037499a6
import
type
{
test
}
from
'
@playwright/experimental-ct-react
'
;
import
createContextWithStorage
from
'
./createContextWithStorage
'
;
interface
Feature
{
id
:
string
;
value
:
unknown
;
}
export
default
function
contextWithFeaturesFixture
(
envs
:
Array
<
Feature
>
):
Parameters
<
typeof
test
.
extend
>
[
0
][
'
context
'
]
{
return
async
({
browser
},
use
)
=>
{
const
storageItems
=
envs
.
map
(({
id
,
value
})
=>
({
name
:
`pw_feature:
${
id
}
`
,
value
:
JSON
.
stringify
({
value
,
type
:
typeof
value
})
}));
const
context
=
await
createContextWithStorage
(
browser
,
storageItems
);
await
use
(
context
);
await
context
.
close
();
};
}
playwright/fixtures/createContextWithStorage.ts
0 → 100644
View file @
037499a6
import
type
{
Browser
}
from
'
@playwright/test
'
;
import
*
as
app
from
'
playwright/utils/app
'
;
export
default
async
function
createContextWithEnvs
(
browser
:
Browser
,
localStorage
:
Array
<
{
name
:
string
;
value
:
string
}
>
)
{
return
browser
.
newContext
({
storageState
:
{
origins
:
[
{
origin
:
app
.
url
,
localStorage
},
],
cookies
:
[],
},
});
}
playwright/mocks/lib/growthbook/useFeatureValue.js
0 → 100644
View file @
037499a6
const
useFeatureValue
=
(
name
,
fallback
)
=>
{
try
{
const
{
value
,
type
}
=
JSON
.
parse
(
localStorage
.
getItem
(
`pw_feature:
${
name
}
`
));
const
formattedValue
=
(()
=>
{
switch
(
type
)
{
case
'
boolean
'
:
{
return
value
===
'
true
'
;
}
case
'
number
'
:
{
return
Number
(
value
);
}
default
:
return
value
;
}
})();
return
{
isLoading
:
false
,
value
:
formattedValue
};
}
catch
(
error
)
{
return
{
isLoading
:
false
,
value
:
fallback
};
}
};
export
default
useFeatureValue
;
ui/pages/Login.pw.tsx
0 → 100644
View file @
037499a6
import
{
test
as
base
,
expect
}
from
'
@playwright/experimental-ct-react
'
;
import
React
from
'
react
'
;
import
contextWithFeatures
from
'
playwright/fixtures/contextWithFeatures
'
;
import
TestApp
from
'
playwright/TestApp
'
;
import
Login
from
'
./Login
'
;
const
testWithFeature
=
base
.
extend
({
context
:
contextWithFeatures
([
{
id
:
'
test_value
'
,
value
:
'
kitty
'
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
])
as
any
,
});
testWithFeature
(
'
has feature text
'
,
async
({
mount
})
=>
{
const
component
=
await
mount
(
<
TestApp
>
<
Login
/>
</
TestApp
>,
);
const
featureText
=
component
.
getByText
(
'
kitty
'
);
await
expect
(
featureText
).
toBeVisible
();
});
ui/snippets/header/Burger.pw.tsx
View file @
037499a6
...
...
@@ -4,7 +4,8 @@ import React from 'react';
import
{
buildExternalAssetFilePath
}
from
'
configs/app/utils
'
;
import
{
FEATURED_NETWORKS_MOCK
}
from
'
mocks/config/network
'
;
import
authFixture
from
'
playwright/fixtures/auth
'
;
import
contextWithEnvs
,
{
createContextWithEnvs
}
from
'
playwright/fixtures/contextWithEnvs
'
;
import
contextWithEnvs
from
'
playwright/fixtures/contextWithEnvs
'
;
import
createContextWithStorage
from
'
playwright/fixtures/createContextWithStorage
'
;
import
TestApp
from
'
playwright/TestApp
'
;
import
*
as
app
from
'
playwright/utils/app
'
;
...
...
@@ -104,7 +105,7 @@ test('submenu', async({ mount, page }) => {
test
.
describe
(
'
auth
'
,
()
=>
{
const
extendedTest
=
base
.
extend
({
context
:
async
({
browser
},
use
)
=>
{
const
context
=
await
createContextWith
Envs
(
browser
,
[
const
context
=
await
createContextWith
Storage
(
browser
,
[
{
name
:
'
NEXT_PUBLIC_FEATURED_NETWORKS
'
,
value
:
FEATURED_NETWORKS_URL
},
]);
authFixture
(
context
);
...
...
ui/snippets/navigation/NavigationDesktop.pw.tsx
View file @
037499a6
...
...
@@ -6,7 +6,8 @@ import React from 'react';
import
{
buildExternalAssetFilePath
}
from
'
configs/app/utils
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
authFixture
from
'
playwright/fixtures/auth
'
;
import
contextWithEnvs
,
{
createContextWithEnvs
}
from
'
playwright/fixtures/contextWithEnvs
'
;
import
contextWithEnvs
from
'
playwright/fixtures/contextWithEnvs
'
;
import
createContextWithStorage
from
'
playwright/fixtures/createContextWithStorage
'
;
import
TestApp
from
'
playwright/TestApp
'
;
import
*
as
app
from
'
playwright/utils/app
'
;
import
*
as
configs
from
'
playwright/utils/configs
'
;
...
...
@@ -61,7 +62,7 @@ test.describe('no auth', () => {
base
.
describe
(
'
auth
'
,
()
=>
{
const
test
=
base
.
extend
({
context
:
async
({
browser
},
use
)
=>
{
const
context
=
await
createContextWith
Envs
(
browser
,
[
const
context
=
await
createContextWith
Storage
(
browser
,
[
{
name
:
'
NEXT_PUBLIC_FEATURED_NETWORKS
'
,
value
:
FEATURED_NETWORKS_URL
},
]);
authFixture
(
context
);
...
...
@@ -150,7 +151,7 @@ test.describe('with submenu', () => {
base
.
describe
(
'
cookie set to false
'
,
()
=>
{
const
test
=
base
.
extend
({
context
:
async
({
browser
},
use
)
=>
{
const
context
=
await
createContextWith
Envs
(
browser
,
[
const
context
=
await
createContextWith
Storage
(
browser
,
[
{
name
:
'
NEXT_PUBLIC_FEATURED_NETWORKS
'
,
value
:
FEATURED_NETWORKS_URL
},
]);
context
.
addCookies
([
{
name
:
cookies
.
NAMES
.
NAV_BAR_COLLAPSED
,
value
:
'
false
'
,
domain
:
app
.
domain
,
path
:
'
/
'
}
]);
...
...
@@ -190,7 +191,7 @@ base.describe('cookie set to false', () => {
base
.
describe
(
'
cookie set to true
'
,
()
=>
{
const
test
=
base
.
extend
({
context
:
async
({
browser
},
use
)
=>
{
const
context
=
await
createContextWith
Envs
(
browser
,
[
const
context
=
await
createContextWith
Storage
(
browser
,
[
{
name
:
'
NEXT_PUBLIC_FEATURED_NETWORKS
'
,
value
:
FEATURED_NETWORKS_URL
},
]);
context
.
addCookies
([
{
name
:
cookies
.
NAMES
.
NAV_BAR_COLLAPSED
,
value
:
'
true
'
,
domain
:
'
localhost
'
,
path
:
'
/
'
}
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment