Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
0e8ad5ae
Commit
0e8ad5ae
authored
Jan 30, 2020
by
Zack Cuddy
Committed by
Paul Slaughter
Jan 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generic Vue Alert Component
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/23125
parent
1e035fd9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
198 additions
and
0 deletions
+198
-0
app/assets/javascripts/vue_alerts.js
app/assets/javascripts/vue_alerts.js
+22
-0
app/assets/javascripts/vue_shared/components/dismissible_alert.vue
...s/javascripts/vue_shared/components/dismissible_alert.vue
+32
-0
spec/frontend/vue_alerts_spec.js
spec/frontend/vue_alerts_spec.js
+87
-0
spec/frontend/vue_shared/components/dismissible_alert_spec.js
.../frontend/vue_shared/components/dismissible_alert_spec.js
+57
-0
No files found.
app/assets/javascripts/vue_alerts.js
0 → 100644
View file @
0e8ad5ae
import
Vue
from
'
vue
'
;
import
{
parseBoolean
}
from
'
~/lib/utils/common_utils
'
;
import
DismissibleAlert
from
'
~/vue_shared/components/dismissible_alert.vue
'
;
const
mountVueAlert
=
el
=>
{
const
props
=
{
html
:
el
.
innerHTML
,
};
const
attrs
=
{
...
el
.
dataset
,
dismissible
:
parseBoolean
(
el
.
dataset
.
dismissible
),
};
return
new
Vue
({
el
,
render
(
h
)
{
return
h
(
DismissibleAlert
,
{
props
,
attrs
});
},
});
};
export
default
()
=>
[...
document
.
querySelectorAll
(
'
.js-vue-alert
'
)].
map
(
mountVueAlert
);
app/assets/javascripts/vue_shared/components/dismissible_alert.vue
0 → 100644
View file @
0e8ad5ae
<
script
>
import
{
GlAlert
}
from
'
@gitlab/ui
'
;
export
default
{
components
:
{
GlAlert
,
},
props
:
{
html
:
{
type
:
String
,
required
:
false
,
default
:
''
,
},
},
data
()
{
return
{
isDismissed
:
false
,
};
},
methods
:
{
dismiss
()
{
this
.
isDismissed
=
true
;
},
},
};
</
script
>
<
template
>
<gl-alert
v-if=
"!isDismissed"
v-bind=
"$attrs"
@
dismiss=
"dismiss"
v-on=
"$listeners"
>
<div
v-html=
"html"
></div>
</gl-alert>
</
template
>
spec/frontend/vue_alerts_spec.js
0 → 100644
View file @
0e8ad5ae
import
Vue
from
'
vue
'
;
import
initVueAlerts
from
'
~/vue_alerts
'
;
import
{
setHTMLFixture
}
from
'
helpers/fixtures
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
describe
(
'
VueAlerts
'
,
()
=>
{
const
alerts
=
[
{
title
:
'
Lorem
'
,
html
:
'
Lorem <strong>Ipsum</strong>
'
,
dismissible
:
true
,
primaryButtonText
:
'
Okay!
'
,
primaryButtonLink
:
`
${
TEST_HOST
}
/okay`
,
variant
:
'
tip
'
,
},
{
title
:
'
Hello
'
,
html
:
'
Hello <strong>World</strong>
'
,
dismissible
:
false
,
primaryButtonText
:
'
No!
'
,
primaryButtonLink
:
`
${
TEST_HOST
}
/no`
,
variant
:
'
info
'
,
},
];
beforeEach
(()
=>
{
setHTMLFixture
(
alerts
.
map
(
x
=>
`
<div class="js-vue-alert"
data-dismissible="
${
x
.
dismissible
}
"
data-title="
${
x
.
title
}
"
data-primary-button-text="
${
x
.
primaryButtonText
}
"
data-primary-button-link="
${
x
.
primaryButtonLink
}
"
data-variant="
${
x
.
variant
}
">
${
x
.
html
}
</div>
`
,
)
.
join
(
'
\n
'
),
);
});
const
findJsHooks
=
()
=>
document
.
querySelectorAll
(
'
.js-vue-alert
'
);
const
findAlerts
=
()
=>
document
.
querySelectorAll
(
'
.gl-alert
'
);
const
findAlertDismiss
=
alert
=>
alert
.
querySelector
(
'
.gl-alert-dismiss
'
);
const
serializeAlert
=
alert
=>
({
title
:
alert
.
querySelector
(
'
.gl-alert-title
'
).
textContent
.
trim
(),
html
:
alert
.
querySelector
(
'
.gl-alert-body div
'
).
innerHTML
,
dismissible
:
Boolean
(
alert
.
querySelector
(
'
.gl-alert-dismiss
'
)),
primaryButtonText
:
alert
.
querySelector
(
'
.gl-alert-action
'
).
textContent
.
trim
(),
primaryButtonLink
:
alert
.
querySelector
(
'
.gl-alert-action
'
).
href
,
variant
:
[...
alert
.
classList
].
find
(
x
=>
x
.
match
(
'
gl-alert-
'
)).
replace
(
'
gl-alert-
'
,
''
),
});
it
(
'
starts with only JsHooks
'
,
()
=>
{
expect
(
findJsHooks
().
length
).
toEqual
(
alerts
.
length
);
expect
(
findAlerts
().
length
).
toEqual
(
0
);
});
describe
(
'
when mounted
'
,
()
=>
{
beforeEach
(()
=>
{
initVueAlerts
();
});
it
(
'
replaces JsHook with GlAlert
'
,
()
=>
{
expect
(
findJsHooks
().
length
).
toEqual
(
0
);
expect
(
findAlerts
().
length
).
toEqual
(
alerts
.
length
);
});
it
(
'
passes along props to gl-alert
'
,
()
=>
{
expect
([...
findAlerts
()].
map
(
serializeAlert
)).
toEqual
(
alerts
);
});
describe
(
'
when dismissed
'
,
()
=>
{
beforeEach
(()
=>
{
findAlertDismiss
(
findAlerts
()[
0
]).
click
();
return
Vue
.
nextTick
();
});
it
(
'
hides the alert
'
,
()
=>
{
expect
(
findAlerts
().
length
).
toEqual
(
alerts
.
length
-
1
);
});
});
});
});
spec/frontend/vue_shared/components/dismissible_alert_spec.js
0 → 100644
View file @
0e8ad5ae
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
GlAlert
}
from
'
@gitlab/ui
'
;
import
DismissibleAlert
from
'
~/vue_shared/components/dismissible_alert.vue
'
;
const
TEST_HTML
=
'
Hello World! <strong>Foo</strong>
'
;
describe
(
'
vue_shared/components/dismissible_alert
'
,
()
=>
{
const
testAlertProps
=
{
primaryButtonText
:
'
Lorem ipsum
'
,
primaryButtonLink
:
'
/lorem/ipsum
'
,
};
let
wrapper
;
const
createComponent
=
(
props
=
{})
=>
{
wrapper
=
shallowMount
(
DismissibleAlert
,
{
propsData
:
{
html
:
TEST_HTML
,
...
testAlertProps
,
...
props
,
},
});
};
afterEach
(()
=>
{
wrapper
.
destroy
();
});
const
findAlert
=
()
=>
wrapper
.
find
(
GlAlert
);
describe
(
'
with default
'
,
()
=>
{
beforeEach
(()
=>
{
createComponent
();
});
it
(
'
shows alert
'
,
()
=>
{
const
alert
=
findAlert
();
expect
(
alert
.
exists
()).
toBe
(
true
);
expect
(
alert
.
props
()).
toEqual
(
expect
.
objectContaining
(
testAlertProps
));
});
it
(
'
shows given HTML
'
,
()
=>
{
expect
(
findAlert
().
html
()).
toContain
(
TEST_HTML
);
});
describe
(
'
when dismissed
'
,
()
=>
{
beforeEach
(()
=>
{
findAlert
().
vm
.
$emit
(
'
dismiss
'
);
});
it
(
'
hides the alert
'
,
()
=>
{
expect
(
findAlert
().
exists
()).
toBe
(
false
);
});
});
});
});
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